Created
February 16, 2020 11:30
-
-
Save al3rez/ab56e9de56ace2b64153d62c651ba14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Login | |
include ActiveModel::Model | |
attr_accessor :email, :password, :user | |
validates :email, presence: true | |
validates :password, presence: true | |
validates :user, presence: {message: "email or password is wrong"} | |
def initialize(params) | |
super(params.require(:user).permit(:email, :password)) | |
@user = User.find_by(email: email)&.authenticate(password) | |
end | |
def save | |
return if invalid? | |
Tokenizer.generate_and_refresh(@user) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment