module Authpwn::UserModel::ClassMethods
Class methods on models that include Authpwn::UserModel
.
Public Instance Methods
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.
@param [Session] signin the information entered in the sign-in form @return [User, Symbol] the authenticated user, or a symbol indicating the
reason why the authentication failed
# File lib/authpwn_rails/user_model.rb, line 51 def authenticate_signin(signin) Credentials::Password.authenticate_email signin.email, signin.password end
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.
@param [Hash] omniauth_hash the hash provided by OmniAuth @return [User] a saved User
, or nil if the OmniAuth sign-in information
should not be used to create a user
# 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
Scope using the value returned by User#to_param
.
@param [String] param value returned by User#to_param
@return [ActiveRecord::Relation]
# File lib/authpwn_rails/user_model.rb, line 39 def with_param(param) where(exuid: param) end