2012-02-25 22:43:17 +00:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
|
2012-03-04 10:33:11 +00:00
|
|
|
def new; end
|
|
|
|
|
2012-02-25 22:43:17 +00:00
|
|
|
def create
|
2013-10-19 18:59:39 +00:00
|
|
|
user = find_user
|
2012-02-25 22:43:17 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
if user
|
|
|
|
self.current_user = user
|
2013-10-22 15:26:36 +00:00
|
|
|
redirect_back_or_to root_url, :notice => "Welcome back!"
|
2013-08-19 15:08:13 +00:00
|
|
|
else
|
2013-10-19 18:59:39 +00:00
|
|
|
store[:new_user_email] = omniauth_credentials.email
|
2013-10-19 16:25:30 +00:00
|
|
|
redirect_to new_user_path
|
2012-03-05 23:25:21 +00:00
|
|
|
end
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
self.current_user = nil
|
2013-10-22 15:26:36 +00:00
|
|
|
redirect_to root_path, :notice => "See you later!"
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def failure
|
2013-10-19 18:59:39 +00:00
|
|
|
redirect_to root_path, :alert => "Authentication failed. Maybe try again?"
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
def store
|
|
|
|
session
|
2012-03-10 13:58:10 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
def find_user
|
|
|
|
User.for_email(omniauth_credentials.email)
|
2013-10-19 16:25:30 +00:00
|
|
|
end
|
|
|
|
|
2012-02-25 22:43:17 +00:00
|
|
|
end
|