Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor user authentication to a more generic strategy #2

Open
tramuntanal opened this issue May 21, 2019 · 0 comments
Open

Refactor user authentication to a more generic strategy #2

tramuntanal opened this issue May 21, 2019 · 0 comments
Assignees

Comments

@tramuntanal
Copy link
Contributor

tramuntanal commented May 21, 2019

authenticated = user.try(:authenticate, password) || user.try(:valid_password?, password)

In an initializer in the app:

Ctws.user_authentication_callback= ->(login, pwd) {
   session= UserSession.new(login, pwd)
   if session.save!
     session.model
   end
}

then, in AuthenticateUser, check if the callback is setted and

if Ctws.user_authentication_callback.
  Ctws.user_authentication_callback.call(email, password)
else
  user = Ctws.user_class.find_by(email: email)
  authenticated = true
  user
end
@tramuntanal tramuntanal changed the title Refactor user aguthentication to a more generic strategy Refactor user augthentication to a more generic strategy May 21, 2019
@tramuntanal tramuntanal changed the title Refactor user augthentication to a more generic strategy Refactor user authentication to a more generic strategy May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants