lib/authenticate/model/email.rb in authenticate-0.3.1 vs lib/authenticate/model/email.rb in authenticate-0.3.2
- old
+ new
@@ -1,10 +1,10 @@
require 'email_validator'
module Authenticate
module Model
-
+ #
# Use :email as the identifier for the user. Email must be unique.
#
# = Columns
# * email - the email address of the user
#
@@ -16,11 +16,11 @@
# = Methods
# * normalize_email - normalize the email, removing spaces etc, before saving
#
# = Class Methods
# * credentials(params) - return the credentials required for authorization by email
- # * authenticate(credentials) - find user with given email, validate their password, return the user if authenticated
+ # * authenticate(credentials) - find user with given email, validate their password, return user if authenticated
# * normalize_email(email) - clean up the given email and return it.
# * find_by_credentials(credentials) - find and return the user with the email address in the credentials
#
module Email
extend ActiveSupport::Concern
@@ -35,13 +35,15 @@
email: { strict_mode: true },
presence: true,
uniqueness: { allow_blank: true }
end
-
+ # Class methods for authenticating using email as the user identifier.
module ClassMethods
-
+ # Retrieve credentials from params.
+ #
+ # @return [id, pw]
def credentials(params)
return [] if params.nil? || params[:session].nil?
[params[:session][:email], params[:session][:password]]
end
@@ -52,20 +54,16 @@
def find_by_credentials(credentials)
email = credentials[0]
find_by_normalized_email(email)
end
-
end
- # Sets the email on this instance to the value returned by
- # {.normalize_email}
+ # Sets the email on this instance to the value returned by class method #normalize_email
#
# @return [String]
def normalize_email
self.email = self.class.normalize_email(email)
end
end
-
end
end
-