class Devise::G5::AuthUserCreator
Create a new user account on the G5
Auth server
Attributes
model[R]
Public Class Methods
new(authenticatable_model)
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 11 def initialize(authenticatable_model) @model = authenticatable_model end
Public Instance Methods
create()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 15 def create create_auth_user unless auth_user_exists? end
Private Instance Methods
auth_client()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 44 def auth_client G5AuthenticationClient::Client.new( access_token: updated_by.g5_access_token ) end
auth_user()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 25 def auth_user auth_client.create_user(auth_user_args) rescue StandardError => error raise error unless error.message =~ /Email has already been taken/ existing_auth_user end
auth_user_args()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 54 def auth_user_args { email: model.email, password: model.password, password_confirmation: model.password_confirmation } end
auth_user_exists?()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 40 def auth_user_exists? !model.uid.blank? end
create_auth_user()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 21 def create_auth_user update_auth_attributes(auth_user) end
existing_auth_user()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 32 def existing_auth_user user = auth_client.find_user_by_email(model.email) user.password = model.password user.password_confirmation = model.password auth_client.update_user(user.to_hash) user end
update_auth_attributes(auth_user)
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 60 def update_auth_attributes(auth_user) model.provider = 'g5' model.uid = auth_user.id model.clean_up_passwords model end
updated_by()
click to toggle source
# File lib/devise_g5_authenticatable/g5/auth_user_creator.rb, line 50 def updated_by model.updated_by || model end