class Admin < ActiveRecord::Base
# Include default devise modules. Others available are:
- # , :encryptable, :lockable, :timeoutable and :omniauthable
+ # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable
devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :confirmable
+ :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
- before_save :ensure_authentication_token\r
+
+ def active_for_authentication?\r
+ super && (self.approve == 1)
+ end
+
+ def create_token
+ self.ensure_authentication_token
+ self.save
+ end
+
+ def delete_token
+ self.authentication_token = nil
+ self.save
+ end
+
+ def apv
+ self.approve = 1
+ self.save
+ end
def self.start(email, passwd)
- a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd
- a.confirm!
+ a = Admin.find(:first, :conditions => ['email = ?', email])
+ if a
+ a.password = passwd
+ a.password_confirmation = passwd
+ else
+ a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd
+ end
+ a.approve = 1
+ a.save!
end
end