Module: Authpwn::UserModel::ClassMethods
- Defined in:
- lib/authpwn_rails/user_model.rb
Overview
Class methods on models that include Authpwn::UserModel.
Instance Method Summary collapse
-
#authenticate_signin(signin) ⇒ User, Symbol
Authenticates a user given the information on a signup form.
-
#create_from_omniauth(omniauth_hash) ⇒ User
Change this to customize on-demand user creation on OmniAuth signup.
-
#related_to_omniauth(omniauth_hash) ⇒ User
Looks up the User tat may be related to an OmniAuth sign-in.
-
#with_param(param) ⇒ ActiveRecord::Relation
Scope using the value returned by User#to_param.
Instance Method Details
#authenticate_signin(signin) ⇒ User, Symbol
Authenticates a user given the information on a signup form.
The easiest method of accepting other login information is to override this method, locate the user’s email, and supply it in a call to super.
51 52 53 |
# File 'lib/authpwn_rails/user_model.rb', line 51 def authenticate_signin(signin) Credentials::Password.authenticate_email signin.email, signin.password end |
#create_from_omniauth(omniauth_hash) ⇒ User
Change this to customize on-demand user creation on OmniAuth signup.
This method is called when there is no existing user matching the OmniAuth information, and is responsible for creating a user. It is an opportunity to collect the OmniAuth information to populate the user’s account.
The default implementation creates a user with the e-mail matching the ‘email’ key in the OmniAuth hash. If no e-mail key is present, no User is created.
88 89 90 91 92 93 94 95 |
# File 'lib/authpwn_rails/user_model.rb', line 88 def create_from_omniauth(omniauth_hash) info_hash = omniauth_hash['info'] return nil unless email = info_hash && info_hash['email'] user = User.new user.credentials << Credentials::Email.new(email: email, verified: true) user.save! user end |
#related_to_omniauth(omniauth_hash) ⇒ User
Looks up the User tat may be related to an OmniAuth sign-in.
This method is called when there is no Credential matching the OmniAuth information, but before User#create_from_omniauth. It is an opportunity to identify an existing user who uses a new sign-in method.
The default implementation finds an user whose e-mail matches the ‘email’ value in the OmniAuth hash.
67 68 69 70 71 72 |
# File 'lib/authpwn_rails/user_model.rb', line 67 def (omniauth_hash) info_hash = omniauth_hash['info'] return nil unless email = info_hash && info_hash['email'] credential = Credentials::Email.with email credential and credential.user end |
#with_param(param) ⇒ ActiveRecord::Relation
Scope using the value returned by User#to_param.
39 40 41 |
# File 'lib/authpwn_rails/user_model.rb', line 39 def with_param(param) where(exuid: param) end |