Class: LoginController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- LoginController
- Defined in:
- app/controllers/login_controller.rb
Instance Method Summary collapse
-
#accept_invitation ⇒ Object
For invited users.
-
#forgot_password ⇒ Object
Display the form to enter an email address requesting a token to set a new password.
-
#new_password ⇒ Object
Set a new password with a token from the password reminder email.
-
#reset_password ⇒ Object
Sends an email to a user with the token that allows setting a new password through action “password”.
-
#update_password ⇒ Object
Sets a new password.
- #validate_token ⇒ Object protected
Methods inherited from ApplicationController
Methods included from PathHelper
#finance_group_transactions_path
Instance Method Details
#accept_invitation ⇒ Object
For invited users.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/login_controller.rb', line 39 def accept_invitation @invite = Invite.find_by_token(params[:token]) if @invite.nil? || @invite.expires_at < Time.now redirect_to login_url, alert: I18n.t('login.controller.error_invite_invalid') elsif @invite.group.nil? redirect_to login_url, alert: I18n.t('login.controller.error_group_invalid') elsif request.post? User.transaction do @user = User.new(params[:user]) @user.email = @invite.email if @user.save Membership.new(user: @user, group: @invite.group).save! @invite.destroy session[:locale] = @user.locale redirect_to login_url, notice: I18n.t('login.controller.accept_invitation.notice') end end else @user = User.new(email: @invite.email) end end |
#forgot_password ⇒ Object
Display the form to enter an email address requesting a token to set a new password.
6 7 8 |
# File 'app/controllers/login_controller.rb', line 6 def forgot_password @user = User.new end |
#new_password ⇒ Object
Set a new password with a token from the password reminder email. Called with params :id => User.id and :token => User.reset_password_token to specify a new password.
22 |
# File 'app/controllers/login_controller.rb', line 22 def new_password; end |
#reset_password ⇒ Object
Sends an email to a user with the token that allows setting a new password through action “password”.
11 12 13 14 15 16 17 18 |
# File 'app/controllers/login_controller.rb', line 11 def reset_password redirect_to forgot_password_url, alert: I18n.t('errors.general_again') and return if request.get? || params[:user].nil? # Catch for get request and give better error message. if (user = User.undeleted.find_by_email(params[:user][:email])) user.request_password_reset! end redirect_to login_url, notice: I18n.t('login.controller.reset_password.notice') end |
#update_password ⇒ Object
Sets a new password. Called with params :id => User.id and :token => User.reset_password_token to specify a new password.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/login_controller.rb', line 26 def update_password @user.attributes = params[:user] if @user.valid? @user.reset_password_token = nil @user.reset_password_expires = nil @user.save redirect_to login_url, notice: I18n.t('login.controller.update_password.notice') else render :new_password end end |
#validate_token ⇒ Object (protected)
63 64 65 66 67 68 |
# File 'app/controllers/login_controller.rb', line 63 def validate_token @user = User.find_by_id_and_reset_password_token(params[:id], params[:token]) return unless @user.nil? || @user.reset_password_expires < Time.now redirect_to forgot_password_url, alert: I18n.t('login.controller.error_token_invalid') end |