Class: QuoVadis::SessionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- QuoVadis::SessionsController
- Defined in:
- app/controllers/quo_vadis/sessions_controller.rb
Instance Method Summary collapse
-
#accept ⇒ Object
POST activation_path /sign-in/accept/:token.
-
#create ⇒ Object
POST sign_in_path.
-
#destroy ⇒ Object
GET sign_out_path.
-
#edit ⇒ Object
GET change_password_path /sign-in/change-password/:token.
-
#forgotten ⇒ Object
GET forgotten_sign_in_path POST forgotten_sign_in_path.
-
#invite ⇒ Object
GET invitation_path /sign-in/invite/:token.
-
#invite_to_activate(user, data = {}) ⇒ Object
Invites a user to set up their sign-in credentials.
-
#new ⇒ Object
GET sign_in_path.
-
#update ⇒ Object
PUT change_password_path /sign-in/change-password/:token.
Instance Method Details
#accept ⇒ Object
POST activation_path /sign-in/accept/:token
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 100 def accept if (@user = QuoVadis.model_class.valid_token(params[:token]).first) @user.username, @user.password = params[:username], params[:password] # When we create a user who must activate their account, we give them # a random username and password. However we want to treat them as if # they weren't set at all. @user.password_digest = nil if params[:password].blank? if @user.save @user.clear_token flash_if_present :notice, 'quo_vadis.flash.activation.accepted' sign_in @user else flash_if_present :alert, 'quo_vadis.flash.activation.invalid_credentials', :now render 'sessions/invite' end else invalid_token :activation end end |
#create ⇒ Object
POST sign_in_path
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 11 def create if blocked? flash_if_present :alert, 'quo_vadis.flash.sign_in.blocked', :now render 'sessions/new' elsif user = QuoVadis.model_class.authenticate(params[:username], params[:password]) flash_if_present :notice, 'quo_vadis.flash.sign_in.after' sign_in user else QuoVadis.failed_sign_in_hook self flash_if_present :alert, 'quo_vadis.flash.sign_in.failed', :now render 'sessions/new' end end |
#destroy ⇒ Object
GET sign_out_path
26 27 28 29 30 31 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 26 def destroy QuoVadis.signed_out_hook send(:"current_#{QuoVadis.model_instance_name}"), self self.send :"current_#{QuoVadis.model_instance_name}=", nil flash_if_present :notice, 'quo_vadis.flash.sign_out' redirect_to QuoVadis.signed_out_url(self) end |
#edit ⇒ Object
GET change_password_path /sign-in/change-password/:token
58 59 60 61 62 63 64 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 58 def edit if QuoVadis.model_class.valid_token(params[:token]).first render 'sessions/edit' else invalid_token :forgotten end end |
#forgotten ⇒ Object
GET forgotten_sign_in_path POST forgotten_sign_in_path
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 35 def forgotten if request.get? render 'sessions/forgotten' elsif request.post? if params[:username].present? && (user = QuoVadis.model_class.where(:username => params[:username]).first) if user.email.present? user.generate_token! QuoVadis::Notifier.change_password(user).deliver flash_if_present :notice, 'quo_vadis.flash.forgotten.sent_email' redirect_to :root else flash_if_present :alert, 'quo_vadis.flash.forgotten.no_email', :now render 'sessions/forgotten' end else flash_if_present :alert, 'quo_vadis.flash.forgotten.unknown', :now render 'sessions/forgotten' end end end |
#invite ⇒ Object
GET invitation_path /sign-in/invite/:token
87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 87 def invite if (@user = QuoVadis.model_class.valid_token(params[:token]).first) # When we create a user who must activate their account, we give them # a random username and password. However we want to treat them as if # they weren't set at all. @user.username = nil render 'sessions/invite' else invalid_token :activation end end |
#invite_to_activate(user, data = {}) ⇒ Object
Invites a user to set up their sign-in credentials.
121 122 123 124 125 126 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 121 def invite_to_activate(user, data = {}) return false if user.email.blank? user.generate_token! QuoVadis::Notifier.invite(user, data).deliver true end |
#new ⇒ Object
GET sign_in_path
6 7 8 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 6 def new render 'sessions/new' end |
#update ⇒ Object
PUT change_password_path /sign-in/change-password/:token
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/quo_vadis/sessions_controller.rb', line 67 def update if (user = QuoVadis.model_class.valid_token(params[:token]).first) if params[:password].present? user.password = params[:password] if user.save user.clear_token flash_if_present :notice, 'quo_vadis.flash.forgotten.password_changed' sign_in user else render 'sessions/edit' end else render 'sessions/edit' end else invalid_token :forgotten end end |