2012-02-25 22:43:17 +00:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
before_filter :load_omniauth_auth, :only => :create
|
|
|
|
|
2012-03-04 10:33:11 +00:00
|
|
|
def new; end
|
|
|
|
|
2012-02-25 22:43:17 +00:00
|
|
|
def create
|
2012-03-05 23:25:21 +00:00
|
|
|
@user =
|
2012-06-09 22:11:27 +00:00
|
|
|
User.find_by_provider_and_uid(@auth["provider"], @auth["uid"].to_s) ||
|
2012-02-26 17:13:46 +00:00
|
|
|
User.create_with_omniauth(@auth)
|
2012-02-25 22:43:17 +00:00
|
|
|
|
2012-03-05 23:25:21 +00:00
|
|
|
unless @user.persisted?
|
2012-03-10 13:58:10 +00:00
|
|
|
store_sensitive_user_data_in_session
|
2012-03-05 23:25:21 +00:00
|
|
|
render 'users/new', :status => 422
|
|
|
|
else
|
|
|
|
self.current_user = @user
|
|
|
|
redirect_back_or_to root_url, :notice => "Signed in!"
|
|
|
|
end
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
self.current_user = nil
|
|
|
|
redirect_to root_url, :notice => "Signed out!"
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure
|
2012-02-26 17:39:46 +00:00
|
|
|
redirect_to root_url, :alert => params[:message]
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_omniauth_auth
|
|
|
|
@auth = request.env["omniauth.auth"]
|
|
|
|
end
|
|
|
|
|
2012-03-10 13:58:10 +00:00
|
|
|
def store_sensitive_user_data_in_session
|
2012-04-09 12:42:22 +00:00
|
|
|
session[:new_user] = {
|
|
|
|
:provider => @user.provider,
|
|
|
|
:uid => @user.uid,
|
|
|
|
:avatar_url => @user.avatar_url
|
|
|
|
}
|
2012-03-10 13:58:10 +00:00
|
|
|
end
|
|
|
|
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|