sqlite3, test coverage improvements, auto auth

This commit is contained in:
2015-10-23 19:34:59 -05:00
parent 41ceccc5b5
commit 7ddf93578e
15 changed files with 143 additions and 83 deletions

View File

@ -10,21 +10,44 @@ class OauthsController < ApplicationController
@user = login_from(provider)
if @user
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
redirect_to root_path, notice: login_msg(@user, provider)
else
msg = "Your account must be pre-approved. Please contact the administrator."
redirect_to root_path, notice: msg
@user = auth_and_login(provider)
redirect_to root_path, notice: login_msg(@user, provider)
end
end
private
# def create_and_login provider
# @user = create_from(provider)
# reset_session # protect from session fixation attack
# auto_login(@user)
# redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
# end
def login_msg user, provider = 'oAuth'
if user.active?
"Logged in from #{provider.titleize}!"
else
"Your account must be activated by an administrator."
end
end
def auth_and_login provider
user = create_auth_from(provider, auth_info)
reset_session # protect from session fixation attack
auto_login(user) if user.active?
user
end
def create_auth_from provider, auth
user = Person.find_by_email auth[:user_info]["email"]
user.authentications.create(provider: provider, uid: auth[:uid])
user
end
def auth_info
@auth_info ||= google_hash
end
def google_hash
ga = Sorcery::Providers::Google.new
ga.get_user_hash access_token
end
def auth_params
params.permit(:code, :provider)