Class: SelfAuthRails::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/self_auth_rails/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

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

#dlObject

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

#logoutObject

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

#newObject



3
# File 'app/controllers/self_auth_rails/sessions_controller.rb', line 3

def new; end

#qrObject

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