Class: Lato::AuthenticationController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Lato::AuthenticationController
- Defined in:
- app/controllers/lato/authentication_controller.rb
Instance Method Summary collapse
-
#accept_invitation ⇒ Object
Accept invitation.
- #accept_invitation_action ⇒ Object
-
#authenticator ⇒ Object
Authenticator.
- #authenticator_action ⇒ Object
-
#recover_password ⇒ Object
Recover password.
- #recover_password_action ⇒ Object
-
#signin ⇒ Object
Signin.
- #signin_action ⇒ Object
-
#signout ⇒ Object
Signout.
- #signout_action ⇒ Object
-
#signup ⇒ Object
Signup.
- #signup_action ⇒ Object
-
#update_password ⇒ Object
Update password.
- #update_password_action ⇒ Object
-
#verify_email ⇒ Object
Verify email.
- #verify_email_action ⇒ Object
- #web3_signin ⇒ Object
- #web3_signin_action ⇒ Object
Methods inherited from ApplicationController
#error, #index, #not_found, #offline, #switch_locale
Methods included from Componentable
Methods included from Layoutable
#active_navbar, #active_sidebar, #hide_sidebar, #page_class, #page_classes, #page_title, #show_sidebar
Methods included from Sessionable
#authenticate_session, #limit_requests, #not_authenticate_session, #session_create, #session_destroy
Instance Method Details
#accept_invitation ⇒ Object
Accept invitation
173 174 175 |
# File 'app/controllers/lato/authentication_controller.rb', line 173 def accept_invitation @user = Lato::User.new(email: @invitation.email) end |
#accept_invitation_action ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/controllers/lato/authentication_controller.rb', line 177 def accept_invitation_action @user = Lato::User.new(registration_params) respond_to do |format| if @user.accept_invitation(params.permit(:id, :accepted_code)) session_create(@user.id) format.html { redirect_to lato.root_path } format.json { render json: @user } else format.html { render :accept_invitation, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#authenticator ⇒ Object
Authenticator
196 197 198 199 |
# File 'app/controllers/lato/authentication_controller.rb', line 196 def authenticator @user = Lato::User.find_by_id(session[:authenticator_user_id]) return respond_to_with_not_found unless @user end |
#authenticator_action ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'app/controllers/lato/authentication_controller.rb', line 201 def authenticator_action @user = Lato::User.find_by_id(session[:authenticator_user_id]) respond_to do |format| if @user.authenticator(params.require(:user).permit(:authenticator_code)) session[:authenticator_user_id] = nil session_create(@user.id) format.html { redirect_to lato.root_path } format.json { render json: @user } else format.html { render :authenticator, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#recover_password ⇒ Object
Recover password
135 136 137 |
# File 'app/controllers/lato/authentication_controller.rb', line 135 def recover_password @user = Lato::User.new end |
#recover_password_action ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/controllers/lato/authentication_controller.rb', line 139 def recover_password_action @user = Lato::User.new respond_to do |format| if @user.request_recover_password(params.require(:user).permit(:email)) format.html { redirect_to lato.authentication_update_password_path(id: @user.id) } format.json { render json: @user } else format.html { render :recover_password, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#signin ⇒ Object
Signin
20 21 22 |
# File 'app/controllers/lato/authentication_controller.rb', line 20 def signin @user = Lato::User.new end |
#signin_action ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/lato/authentication_controller.rb', line 24 def signin_action @user = Lato::User.new respond_to do |format| if @user.signin(params.require(:user).permit(:email, :password).merge( ip_address: request.remote_ip, user_agent: request.user_agent )) if create_session_or_start_authenticator(@user) format.html { redirect_to lato.root_path } format.json { render json: @user } else format.html { redirect_to lato.authentication_authenticator_path } format.json { render json: @user } end else format.html { render :signin, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#signout ⇒ Object
Signout
102 |
# File 'app/controllers/lato/authentication_controller.rb', line 102 def signout; end |
#signout_action ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'app/controllers/lato/authentication_controller.rb', line 104 def signout_action session_destroy respond_to do |format| format.html { redirect_to lato.root_path } format.json { render json: {} } end end |
#signup ⇒ Object
Signup
79 80 81 |
# File 'app/controllers/lato/authentication_controller.rb', line 79 def signup @user = Lato::User.new end |
#signup_action ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/lato/authentication_controller.rb', line 83 def signup_action @user = Lato::User.new(registration_params) respond_to do |format| if @user.signup(ip_address: request.remote_ip, user_agent: request.user_agent) session_create(@user.id) format.html { redirect_to lato.root_path } format.json { render json: @user } else format.html { render :signup, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#update_password ⇒ Object
Update password
156 |
# File 'app/controllers/lato/authentication_controller.rb', line 156 def update_password; end |
#update_password_action ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/lato/authentication_controller.rb', line 158 def update_password_action respond_to do |format| if @user.update_password(params.require(:user).permit(:code, :password, :password_confirmation)) format.html { redirect_to lato.authentication_signin_path, notice: I18n.t('lato.authentication_controller.update_password_action_notice') } format.json { render json: @user } else format.html { render :update_password, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#verify_email ⇒ Object
Verify email
116 117 118 |
# File 'app/controllers/lato/authentication_controller.rb', line 116 def verify_email @code = params[:code] end |
#verify_email_action ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/lato/authentication_controller.rb', line 120 def verify_email_action respond_to do |format| if @user.verify_email(params.require(:user).permit(:code)) format.html { redirect_to lato.root_path, notice: I18n.t('lato.authentication_controller.verify_email_action_notice') } format.json { render json: @user } else format.html { render :verify_email, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#web3_signin ⇒ Object
46 47 48 49 |
# File 'app/controllers/lato/authentication_controller.rb', line 46 def web3_signin @user = Lato::User.new session[:web3_nonce] = SecureRandom.hex(32) end |
#web3_signin_action ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/lato/authentication_controller.rb', line 51 def web3_signin_action @user = Lato::User.new respond_to do |format| if @user.web3_signin(params.require(:user).permit(:web3_address, :web3_signed_nonce).merge( ip_address: request.remote_ip, user_agent: request.user_agent, web3_nonce: session[:web3_nonce] )) session[:web3_nonce] = nil if create_session_or_start_authenticator(@user) format.html { redirect_to lato.root_path } format.json { render json: @user } else format.html { redirect_to lato.authentication_authenticator_path } format.json { render json: @user } end else session[:web3_nonce] = nil format.html { render :web3_signin, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |