Class: SelfAuthRails::SessionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- SelfAuthRails::SessionsController
- Defined in:
- app/controllers/self_auth_rails/sessions_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Authenticates a user with the given token.
-
#dl ⇒ Object
Generates a dynamic link to authenticate users.
-
#logout ⇒ Object
Logs out the current user.
- #new ⇒ Object
-
#qr ⇒ Object
Generates a QR code for authenticating users.
Instance Method Details
#create ⇒ Object
Authenticates a user with the given token
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/self_auth_rails/sessions_controller.rb', line 6 def create if session_params[:token].empty? # AJAX request SelfAuthRails.self_client.facts.request(session_params[:selfid], [:display_name], auth: true, cid: session_params[:connection_id], async: true) request.format = :json respond_to do |format| format.json { head :no_content } end else # Form submission reset_user_token(session_params[:token]) respond_to do |format| format.html { redirect_to SelfAuthRails.authenticated_path, notice: 'Welcome.' } end end end |
#dl ⇒ Object
Generates a dynamic link to authenticate users.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/self_auth_rails/sessions_controller.rb', line 56 def dl link = '#' unless Rails.env.test? uuid = "dl::#{params[:uuid]}" link = SelfAuthRails.self_client.facts.generate_deep_link(SelfAuthRails.auth_facts, SelfAuthRails.authenticated_path, cid: uuid, auth: true) end render json: { url: link } end |
#logout ⇒ Object
Logs out the current user.
27 28 29 30 31 32 33 34 |
# File 'app/controllers/self_auth_rails/sessions_controller.rb', line 27 def logout session[:user_id] = nil respond_to do |format| format.html { redirect_to new_url } format.json { head :no_content } end end |
#new ⇒ Object
3 |
# File 'app/controllers/self_auth_rails/sessions_controller.rb', line 3 def new; end |
#qr ⇒ Object
Generates a QR code for authenticating users.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/self_auth_rails/sessions_controller.rb', line 37 def qr if Rails.env.test? send_data("test") else uuid = "qr::#{params[:uuid]}" img = ::SelfClient.authentication.generate_qr( facts: SelfAuthRails.auth_facts, cid: uuid, exp_timeout: 86_400 ) send_data(img.as_png(border: 0, size: 400), type: 'image/png', disposition: 'inline') end end |