parent
a70c656690
commit
4d3971113f
13 changed files with 196 additions and 0 deletions
22
app/models/session.rb
Normal file
22
app/models/session.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Session
|
||||
include ActiveModel::Model
|
||||
|
||||
include ActiveModel::Attributes
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :user_id
|
||||
|
||||
attribute :email, :string
|
||||
attribute :password, :string
|
||||
|
||||
validates :email, presence: true
|
||||
validates :password, presence: true
|
||||
|
||||
def save
|
||||
user = User.authenticate_by(email: email, password: password)
|
||||
|
||||
@user_id = user && user.id
|
||||
|
||||
user.present? && self || nil
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue