Class: Devise::Rownd::AuthController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Devise::Rownd::AuthController
- Defined in:
- app/controllers/devise/rownd/auth_controller.rb
Instance Method Summary collapse
Instance Method Details
#authenticate ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/devise/rownd/auth_controller.rb', line 13 def authenticate Devise::Rownd::Log.debug('handle /authenticate') access_token = params[:access_token] session_token = session['warden.user.user.key'] new_access_token = session_token != access_token Devise::Rownd::Log.debug("/authenticate: new_access_token = #{new_access_token}") if !session_token.nil? && new_access_token # We have to log the user out otherwise warden will just serialize the user from session, # which currently holds the old access token warden.logout(:user) end warden.authenticate!(scope: :user) should_refresh_page = new_access_token Devise::Rownd::Log.debug("/authenticate: success, refresh = #{should_refresh_page}") render json: { message: 'Successfully authenticated user', should_refresh_page: should_refresh_page }, status: :ok end |
#healthz ⇒ Object
74 75 76 77 78 |
# File 'app/controllers/devise/rownd/auth_controller.rb', line 74 def healthz render json: { message: 'Healthy' }, status: :ok end |
#sign_out ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/devise/rownd/auth_controller.rb', line 38 def sign_out Devise::Rownd::Log.debug('handling /sign_out') warden.logout(:user) Devise::Rownd::Log.debug('/sign_out: success') render json: { message: 'Successfully signed out user', return_to: return_to_after_sign_out }, status: :ok end |
#update_data ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/devise/rownd/auth_controller.rb', line 48 def update_data Devise::Rownd::Log.debug('handling /update_data') request_body = JSON.parse request.body.read profile = { 'data' => request_body['user_data'] } new_user = Devise::Rownd::User.new(profile, session['warden.user.user.key']) Devise::Rownd::Log.debug("/update_data: instantiated user: #{new_user}") warden.set_user(new_user) Devise::Rownd::Log.debug('/update_data: set user in warden') # Remove the cached user profile data so that the next next time its accessed, it will be # fetched from the API Server cache_key = "rownd_user_#{new_user.data['user_id']}" Rails.cache.delete(cache_key) Devise::Rownd::Log.debug("/update_data: removed cache key: #{cache_key}") render json: { # should_refresh_page: true }, status: :ok end |