1 # frozen_string_literal: true
3 class PasswordsController < ApplicationController
8 before_action :authorize_web
9 before_action :set_locale
10 before_action :check_database_readable
12 authorize_resource :class => false
14 before_action :check_database_writable
24 self.current_user = User.find_by_token_for(:password_reset, params[:token])
27 flash[:error] = t ".flash token bad"
28 redirect_to :action => "new"
36 user = User.visible.find_by(:email => params[:email])
39 users = User.visible.where("LOWER(email) = LOWER(?)", params[:email])
41 user = users.first if users.one?
45 token = user.generate_token_for(:password_reset)
46 UserMailer.lost_password(user, token).deliver_later
49 flash[:notice] = t ".send_paranoid_instructions"
50 redirect_to login_path
55 self.current_user = User.find_by_token_for(:password_reset, params[:token])
59 current_user.pass_crypt = params[:user][:pass_crypt]
60 current_user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
61 current_user.activate if current_user.may_activate?
62 current_user.email_valid = true
65 session[:fingerprint] = current_user.fingerprint
66 flash[:notice] = t ".flash changed"
67 successful_login(current_user)
73 flash[:error] = t ".flash token bad"
74 redirect_to :action => "new"