Sha256: 0b420e0088e84f2bd32ce9a997592015077bf5004a18de0a32da41c2ccdb4961
Contents?: true
Size: 883 Bytes
Versions: 6
Compression:
Stored size: 883 Bytes
Contents
class Session module Formats EMAIL = /\A([^\s]+)@([^\s]+)\Z/i end extend ActiveModel::Naming include ActiveModel::Conversion include ActiveModel::Validations attr_accessor :email attr_accessor :password validates_presence_of :email validates_presence_of :password validates_format_of :email, :with => Formats::EMAIL, :message => "should look like an email", :unless => "email.blank?" validate do return unless errors.empty? errors[:email] << "is not valid" and return unless self.user errors[:password] << "is not valid" and return unless self.user.authenticate(self.password) end def initialize(attributes = {}) @email = attributes[:email] @password = attributes[:password] end def user @user ||= User.find_by_email(self.email) end def persisted? user and user.authenticate(self.password) end end
Version data entries
6 entries across 6 versions & 1 rubygems