Skip to content

Instantly share code, notes, and snippets.

@al3rez
Created February 16, 2020 11:30
Show Gist options
  • Save al3rez/ab56e9de56ace2b64153d62c651ba14b to your computer and use it in GitHub Desktop.
Save al3rez/ab56e9de56ace2b64153d62c651ba14b to your computer and use it in GitHub Desktop.
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