Class: Usman::SessionsController
- Inherits:
-
Kuppayam::BaseController
- Object
- Kuppayam::BaseController
- Usman::SessionsController
- Includes:
- AuthenticationHelper
- Defined in:
- app/controllers/usman/sessions_controller.rb
Instance Method Summary collapse
- #create_session ⇒ Object
- #forgot_password ⇒ Object
- #forgot_password_form ⇒ Object
- #reset_password_form ⇒ Object
- #reset_password_update ⇒ Object
- #sign_in ⇒ Object
- #sign_out ⇒ Object
Instance Method Details
#create_session ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/usman/sessions_controller.rb', line 19 def create_session set_title("Sign In") registration_params = { login_handle: params[:login_handle], password: params[:password], remote_ip: request.remote_ip} @registration_details = Usman::AuthenticationService.new(registration_params) if @registration_details.error text = "#{I18n.t("#{@registration_details.error}.heading")}: #{I18n.t("#{@registration_details.error}.message")}" (text, :error, false) if defined?(flash) && flash redirect_or_popup_to_default_sign_in_page return else @user = @registration_details.user session[:id] = @user.id @current_user = @user text = "#{I18n.t("authentication.logged_in.heading")}: #{I18n.t("authentication.logged_in.message")}" (text, :success, false) if defined?(flash) && flash redirect_to_appropriate_page_after_sign_in return end end |
#forgot_password ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/usman/sessions_controller.rb', line 57 def forgot_password @user = User.find_by_email(params[:email]) if @user.present? @user.generate_reset_password_token @user.save UsersMailer.forgot_password(@user).deliver else end flash[:notice] = "A password reset link will be send to your email if the records matches." redirect_to root_path end |
#forgot_password_form ⇒ Object
54 55 |
# File 'app/controllers/usman/sessions_controller.rb', line 54 def forgot_password_form end |
#reset_password_form ⇒ Object
69 70 71 |
# File 'app/controllers/usman/sessions_controller.rb', line 69 def reset_password_form @user = User.find(params[:id]) end |
#reset_password_update ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/usman/sessions_controller.rb', line 73 def reset_password_update @user = User.find(params[:id]) if @user.reset_password_token == user_params[:reset_password_token] && @user.update(user_params) @user.reset_password_token = nil @user.save flash[:success] = "Password updated successfully" redirect_to root_path else flash[:error] = "Unable to update password please try again later" render "reset_password_form" end end |
#sign_in ⇒ Object
14 15 16 17 |
# File 'app/controllers/usman/sessions_controller.rb', line 14 def sign_in set_title("Sign In") redirect_to_appropriate_page_after_sign_in if @current_user end |
#sign_out ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/usman/sessions_controller.rb', line 44 def sign_out text = "#{I18n.t("authentication.logged_out.heading")}: #{I18n.t("authentication.logged_out.message")}" (text, :success, false) if defined?(flash) && flash @current_user.end_session session.delete(:id) restore_last_user redirect_after_unsuccessful_authentication end |