Class: Muck::PasswordResetsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/password_resets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

Forgot password action



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/muck/password_resets_controller.rb', line 17

def create
  @title = t('muck.users.recover_password')
  if @user = User.find_by_email(params[:reset_password][:email])
    @user.deliver_password_reset_instructions!
    flash[:notice] = t('muck.users.password_reset_link_sent')
    respond_to do |format|
      format.html { redirect_to  }
    end
  else
    flash[:notice] = t('muck.users.could_not_find_user_with_email')
    respond_to do |format|
      format.html { render :template => 'password_resets/new' }
    end
  end  
end

#editObject

Action triggered by clicking on the /reset_password/:id link recieved via email Makes sure the id code is included Checks that the id code matches a user in the database Then if everything checks out, shows the password reset fields



37
38
39
40
41
42
# File 'app/controllers/muck/password_resets_controller.rb', line 37

def edit
  @title = t('muck.users.reset_password')
  respond_to do |format|
    format.html { render :template => 'password_resets/edit' }
  end
end

#newObject

Enter email address to recover password



9
10
11
12
13
14
# File 'app/controllers/muck/password_resets_controller.rb', line 9

def new
  @title = t('muck.users.recover_password')
  respond_to do |format|
    format.html { render :template => 'password_resets/new' }
  end
end

#updateObject

Reset password action /reset_password/:id Checks once again that an id is included and makes sure that the password field isn’t blank



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/muck/password_resets_controller.rb', line 46

def update
  if @user.reset_password!(params[:user])
    flash[:success] = t('muck.users.password_updated')
    respond_to do |format|
      format.html { redirect_to  }
    end
  else
    respond_to do |format|
      format.html { render :template => 'password_resets/edit' }
    end
  end
end