Class: AuthenticationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- AuthenticationsController
- Defined in:
- lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb', line 6 def create omniauth = request.env["omniauth.auth"] authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) if authentication flash[:info] = "Signed in successfully." sign_in_and_redirect(:user, authentication.user) elsif current_user current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid']) flash[:info] = "Authentication successful." redirect_to edit_user_registration_path else user = User.new user.apply_omniauth(omniauth) if user.save flash[:info] = "Signed in successfully." sign_in_and_redirect(:user, user) else session[:omniauth] = omniauth.except('extra') redirect_to new_user_registration_url end end end |
#destroy ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb', line 34 def destroy if ( current_user.authentications.count == 1 && current_user.encrypted_password.empty? ) flash[:error] = "You must first set a password on the <a href=\"#{edit_user_registration_path}\">preferences page</a>".html_safe else @authentication = current_user.authentications.find(params[:id]) @authentication.destroy flash[:success] = "Successfully destroyed authentication." end redirect_to edit_user_registration_path end |
#failure ⇒ Object
29 30 31 32 |
# File 'lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb', line 29 def failure flash[:error] = "There was a problem authenticating with the selected service." redirect_to new_user_registration_url end |
#index ⇒ Object
2 3 4 |
# File 'lib/generators/frame/omniauth/templates/app/controllers/authentications_controller.rb', line 2 def index @authentications = current_user.authentications if current_user end |