Module: Authenticate::User
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/authenticate/user.rb
Overview
Required to be included in your configured user class, which is ‘User` by default, but can be changed with Configuration#user_model=.
class User
include Authenticate::User
# ...
end
To change the user class from the default User, assign it :
Authenticate.configure do |config|
config.user_model = 'MyPackage::Gundan'
end
The fields and methods included by Authenticate::User will depend on what modules you have included in your configuration. When your user class is loaded, User will load any modules at that time. If you have another initializer that loads User before Authenticate’s initializer has run, this may cause interfere with the configuration of your user.
Every user will have two methods to manage session tokens:
-
generate_session_token - generates and sets the Authenticate session token
-
reset_session_token! - calls generate_session_token and save! immediately
Every user will have these two class methods to normalize email addresses:
-
normalize_email(email) - normalize the given email address by downcasing, removing spaces.
-
find_by_normalized_email(email) - find a user by his/her normalized email address
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#generate_session_token ⇒ Object
Generate a new session token for the user, overwriting the existing session token, if any.
-
#reset_session_token! ⇒ Object
Generate a new session token and persist the change, ignoring validations.
Instance Method Details
#generate_session_token ⇒ Object
Generate a new session token for the user, overwriting the existing session token, if any. This is not automatically persisted; call #reset_session_token! to automatically generate and persist the session token update.
43 44 45 |
# File 'lib/authenticate/user.rb', line 43 def generate_session_token self.session_token = Authenticate::Token.new end |
#reset_session_token! ⇒ Object
Generate a new session token and persist the change, ignoring validations. This effectively signs out all existing sessions. Called as part of logout.
49 50 51 52 |
# File 'lib/authenticate/user.rb', line 49 def reset_session_token! generate_session_token save validate: false end |