Merge pull request #1089 from budnik/minor_refactorings

Some refactorings
This commit is contained in:
Sam 2013-06-25 17:29:51 -07:00
commit 4b56aa8183
2 changed files with 12 additions and 27 deletions

View File

@ -61,7 +61,7 @@ class Users::OmniauthCallbacksController < ApplicationController
} }
if user_info if user_info
if user_info.user.active if user_info.user.active?
if Guardian.new(user_info.user).can_access_forum? if Guardian.new(user_info.user).can_access_forum?
log_on_user(user_info.user) log_on_user(user_info.user)
@data[:authenticated] = true @data[:authenticated] = true
@ -92,7 +92,7 @@ class Users::OmniauthCallbacksController < ApplicationController
session[:authentication] = { session[:authentication] = {
facebook: { facebook: {
facebook_user_id: fb_uid , facebook_user_id: fb_uid,
link: raw_info["link"], link: raw_info["link"],
username: raw_info["username"], username: raw_info["username"],
first_name: raw_info["first_name"], first_name: raw_info["first_name"],
@ -116,12 +116,8 @@ class Users::OmniauthCallbacksController < ApplicationController
} }
if user_info if user_info
user = user_info.user if user = user_info.user
if user user.toggle(:active).save unless user.active?
unless user.active
user.active = true
user.save
end
# If we have to approve users # If we have to approve users
if Guardian.new(user).can_access_forum? if Guardian.new(user).can_access_forum?
@ -132,13 +128,9 @@ class Users::OmniauthCallbacksController < ApplicationController
end end
end end
else else
user = User.where(email: email).first if user = User.where(email: email).first
if user user.create_facebook_user_info! session[:authentication][:facebook]
FacebookUserInfo.create!(session[:authentication][:facebook].merge(user_id: user.id)) user.toggle(:active).save unless user.active?
unless user.active
user.active = true
user.save
end
log_on_user(user) log_on_user(user)
@data[:authenticated] = true @data[:authenticated] = true
end end
@ -173,12 +165,8 @@ class Users::OmniauthCallbacksController < ApplicationController
} }
if user_info if user_info
user = user_info.user if user = user_info.user
if user user.toggle(:active).save unless user.active?
unless user.active
user.active = true
user.save
end
log_on_user(user) log_on_user(user)
@data[:authenticated] = true @data[:authenticated] = true
end end
@ -186,10 +174,7 @@ class Users::OmniauthCallbacksController < ApplicationController
user = User.where(email: email).first user = User.where(email: email).first
if user if user
CasUserInfo.create!(session[:authentication][:cas].merge(user_id: user.id)) CasUserInfo.create!(session[:authentication][:cas].merge(user_id: user.id))
unless user.active user.toggle(:active).save unless user.active?
user.active = true
user.save
end
log_on_user(user) log_on_user(user)
@data[:authenticated] = true @data[:authenticated] = true
end end
@ -268,7 +253,7 @@ class Users::OmniauthCallbacksController < ApplicationController
} }
if user_info if user_info
if user_info.user.active if user_info.user.active?
if Guardian.new(user_info.user).can_access_forum? if Guardian.new(user_info.user).can_access_forum?
log_on_user(user_info.user) log_on_user(user_info.user)

View File

@ -306,7 +306,7 @@ class UsersController < ApplicationController
@user = fetch_user_from_params @user = fetch_user_from_params
@email_token = @user.email_tokens.unconfirmed.active.first @email_token = @user.email_tokens.unconfirmed.active.first
if @user if @user
@email_token = @user.email_tokens.create(email: @user.email) if @email_token.nil? @email_token ||= @user.email_tokens.create(email: @user.email)
Jobs.enqueue(:user_email, type: :signup, user_id: @user.id, email_token: @email_token.token) Jobs.enqueue(:user_email, type: :signup, user_id: @user.id, email_token: @email_token.token)
end end
render nothing: true render nothing: true