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
|
2013-08-19 15:08:13 +00:00
|
|
|
@user = request.env['asciiio.user']
|
2012-02-25 22:43:17 +00:00
|
|
|
|
2013-08-19 15:08:13 +00:00
|
|
|
if @user.persisted? || @user.save
|
2012-03-05 23:25:21 +00:00
|
|
|
self.current_user = @user
|
2012-07-25 18:24:20 +00:00
|
|
|
redirect_back_or_to root_url, :notice => "Logged in!"
|
2013-08-19 15:08:13 +00:00
|
|
|
else
|
|
|
|
store_sensitive_user_data_in_session
|
|
|
|
render 'users/new', :status => 422
|
2012-03-05 23:25:21 +00:00
|
|
|
end
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
self.current_user = nil
|
2012-07-25 18:24:20 +00:00
|
|
|
redirect_to root_url, :notice => "Logged out!"
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def failure
|
2013-05-27 21:44:12 +00:00
|
|
|
redirect_to root_url, :alert => "Authentication failed. Maybe try again?"
|
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
|