Class: AuthsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- AuthsController
- Defined in:
- lib/generators/authkit/templates/app/controllers/auths_controller.rb
Overview
The AuthsController is used for connecting accounts only. The user must be logged in for the connection to work. This controller is not used for creating a new session.
Instance Method Summary collapse
- #callback ⇒ Object
-
#connect ⇒ Object
Adjust scope here for particular sets of user using the session.
- #disconnect ⇒ Object
- #failure ⇒ Object
Instance Method Details
#callback ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/authkit/templates/app/controllers/auths_controller.rb', line 18 def callback # If we are not connecting we want to logout any existing user logout unless connecting? if connecting? if auth && auth.user == current_user # This is an auth that is already connected to this user (success, noop) redirect_to settings_path elsif auth && auth.user_id != current_user.id # This is an auth that is connected to another user (error) deny_user("Sorry, this account is already connected to another account", settings_path) else # Success, add the auth and redirect to settings @auth ||= current_user.auths.build(auth_params) if current_user.save redirect_to account_path else flash[:error] = "Sorry, there was an error connecting this account" redirect_to accounts_path end end else # Could have a check here for login/sign up action to be explicit # # If login and auth does not exist, confirm that they want to signup (not attach) # If signup and auth exists, confirm that they have selected the right account (already exists) if auth login(auth.user) redirect_to account_path elsif auth_email.present? && User.where(email: auth_email.downcase).count > 0 deny_user("Sorry, the email address associated with this account is already connected to an existing user", signup_path) else @signup = Signup.new_with_oauth(auth_params, {kind: @kind}) if signup.save login(signup.user) redirect_to account_path else flash[:error] = "Sorry, there was an error connecting this account (#{@signup.errors..to_sentence})" redirect_to signup_path end end end end |
#connect ⇒ Object
Adjust scope here for particular sets of user using the session
session[:google_oauth_scope] = 'userinfo.email, userinfo.profile, adsense, adsense.readonly'
You can also reset it to the default using nil
15 16 |
# File 'lib/generators/authkit/templates/app/controllers/auths_controller.rb', line 15 def connect end |
#disconnect ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/authkit/templates/app/controllers/auths_controller.rb', line 64 def disconnect # TODO: you may want to change this lookup to use uid and provider @auth = current_user.auths.where(params[:id]) @auth.destroy respond_to do |format| format.json { head :no_content } format.html { redirect_to accounts_path } end end |
#failure ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/generators/authkit/templates/app/controllers/auths_controller.rb', line 76 def failure flash[:error] = "Sorry, there was an error connecting this account: #{params[:message]}" if connecting? redirect_to settings_path elsif signing_up? redirect_to signup_path else redirect_to login_path end end |