Class: Mori::PasswordsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/mori/passwords_controller.rb

Overview

Mori::PasswordsController is responsible for changing and resetting passwords

Instance Method Summary collapse

Methods inherited from BaseController

#mori_config, #set_token

Instance Method Details

#changeObject



13
14
15
16
# File 'app/controllers/mori/passwords_controller.rb', line 13

def change
  # View for change password
  render :template => 'passwords/change'
end

#forgotObject



4
5
6
7
8
9
10
11
# File 'app/controllers/mori/passwords_controller.rb', line 4

def forgot
  # View for sending password reset
  if current_user
    redirect_to @config.dashboard_path
  else
    render :template => 'passwords/forgot'
  end
end

#password_change_conditionsObject



61
62
63
# File 'app/controllers/mori/passwords_controller.rb', line 61

def password_change_conditions
  current_user.authenticate(params[:password]) && params[:new_password] == params[:new_password_confirmation]
end

#resetObject



18
19
20
21
22
23
24
25
# File 'app/controllers/mori/passwords_controller.rb', line 18

def reset
  @user = @config.user_model.find_by_password_reset_token(@token) unless @token.blank?
  if @user
    render :template => 'passwords/reset'
  else
    redirect_to root_path
  end
end

#reset_passwordObject



49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/mori/passwords_controller.rb', line 49

def reset_password
  user = @config.user_model.find_by_password_reset_token @token
  if @token != user.password_reset_token or user.password_reset_sent < Mori::Token.expiration_date
    flash[:notice] = t('flashes.invalid_password_reset_token')
    redirect_to "/passwords/reset?token=#{@token}"
  else
    user.reset_password(params[:new_password])
    warden.authenticate!
    redirect_to @config.dashboard_path
  end
end

#send_resetObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/mori/passwords_controller.rb', line 27

def send_reset
  # Send Password Reset to User
  if user = @config.user_model.find_by_normalized_email(params[:email])
    user.forgot_password
    render :template => 'passwords/send_reset'
  else
    render :template => 'passwords/forgot'
  end
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/mori/passwords_controller.rb', line 37

def update
  # Update their password
  if password_change_conditions
    current_user.change_password(params[:new_password])
    flash[:notice] = t('flashes.password_changed_successfully')
    redirect_to @config.dashboard_path
  else
    flash[:notice] = I18n.t('flashes.password_change_failed')
    render :template => 'passwords/change'
  end
end