class Admin < ActiveRecord::Base
# Include default devise modules. Others available are:
- # , :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
+ # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable
devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
+ :recoverable, :rememberable, :trackable, :validatable
+
+ def active_for_authentication?
+ super && (self.approve == 1)
+ end
- # Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me
- before_save :ensure_authentication_token\r
+ 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)
- Admin.create! :email => email, :password => passwd, :password_confirmation => passwd, :activate => 1
+ a = Admin.find_or_initialize_by(email: email)
+ a.password = passwd
+ a.password_confirmation = passwd
+ a.approve = 1
+ a.save!
+ end
+
+ private
+ def admin_params
+ params.require(:admin).permit(:email, :password, :password_confirmation, :remember_me, :authentication_token)
end
end