class Hello::Business::Authentication::SignIn
Attributes
login[RW]
password[RW]
Public Instance Methods
authenticate(login, password)
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 7 def authenticate(login, password) @ignited = true @login = login @password = password validates_presence_of :login, :password return false if any_errors? find_user_by_login check_login_found return false if any_errors? check_password_matches return false if any_errors? true end
bad_login?()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 25 def bad_login? !!@bad_login end
bad_password?()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 29 def bad_password? !!@bad_password end
user()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 33 def user @user ||= ::User.new end
Private Instance Methods
add_errors_for_login_not_found()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 70 def add_errors_for_login_not_found @bad_login = true errors.add(:login, 'was not found') end
add_errors_for_password_incorrect()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 75 def add_errors_for_password_incorrect @bad_password = true errors.add(:password, 'is incorrect') end
any_errors?()
click to toggle source
authenticate helpers
# File lib/hello/business/authentication/sign_in.rb, line 41 def any_errors? errors.full_messages.any? end
check_login_found()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 62 def check_login_found add_errors_for_login_not_found if @user.nil? end
check_password_matches()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 66 def check_password_matches add_errors_for_password_incorrect unless user.password_is?(password) end
find_user_by_login()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 45 def find_user_by_login @user = if login_is_email? find_user_by_login_email else find_user_by_login_username end end
find_user_by_login_email()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 53 def find_user_by_login_email e = ::EmailCredential.find_by_email(login) e && e.user end
find_user_by_login_username()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 58 def find_user_by_login_username ::User.where(username: login).first end
ignited()
click to toggle source
# File lib/hello/business/authentication/sign_in.rb, line 86 def ignited @ignited || false end
login_is_email?()
click to toggle source
helpers
# File lib/hello/business/authentication/sign_in.rb, line 82 def login_is_email? login.to_s.include? '@' end