Class: Authentifyd::AuthenticationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Authentifyd::AuthenticationsController
- Includes:
- Localyzed::LocalyzedController
- Defined in:
- app/controllers/authentifyd/authentications_controller.rb
Instance Method Summary collapse
- #add ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #failure ⇒ Object
- #index ⇒ Object
- #link ⇒ Object
- #new ⇒ Object
Instance Method Details
#add ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 21 def add @user ||= Authentifyd::User.find(params[:user_id]) if @user.valid_password?(params[:user][:password]) omniauth = session[:omniauth] @user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid']) session[:omniauth] = nil sign_in_and_redirect(:user, @user) else flash[:notice] = "Incorrect Password" return redirect_to link_accounts_url(@user.id) end end |
#create ⇒ Object
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 63 64 65 66 67 68 69 70 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 38 def create omniauth = request.env['omniauth.auth'] authentication = Authentifyd::Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) if authentication flash[:notice] = "Signed in successfully" sign_in_and_redirect(:user, authentication.user) else user = user_signed_in? ? current_user : Authentifyd::User.new user.apply_omniauth(omniauth) if user_signed_in? user.save redirect_to accounts_url else omniauth_email = (omniauth["info"] && omniauth["info"]["email"]).try(:to_s) user.email = omniauth_email unless user_signed_in? if user.save flash[:notice] = "Successfully registered" sign_in_and_redirect(:user, user) else session[:omniauth] = omniauth.except('extra') session[:omniauth_email] = omniauth_email # Check if email already taken. If so, ask user to link_accounts if user.errors[:email][0] =~ /has already been taken/ # omniauth? TBD # fetch the user with this email id! user = Authentifyd::User.find_by_email(user.email) return redirect_to link_accounts_url(user.id) end redirect_to new_user_registration_url end end end end |
#destroy ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 77 def destroy @authentication = Authentifyd::Authentication.find(params[:id]) @authentication.destroy respond_to do |format| format.html { redirect_to(accounts_url) } format.xml { head :ok } end end |
#failure ⇒ Object
72 73 74 75 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 72 def failure flash[:notice] = params[:message] redirect_to root_path end |
#index ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 8 def index @authentications = current_user.authentications.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @authentications } end end |
#link ⇒ Object
34 35 36 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 34 def link @user ||= Authentifyd::User.find(params[:user_id]) end |
#new ⇒ Object
17 18 19 |
# File 'app/controllers/authentifyd/authentications_controller.rb', line 17 def new @authentication = Authentifyd::Authentication.new end |