OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / models / admin.rb
1 class Admin < ActiveRecord::Base
2   # Include default devise modules. Others available are:
3   # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable
4   devise :database_authenticatable, :registerable,
5          :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
6
7   # Setup accessible (or protected) attributes for your model
8   attr_accessible :email, :password, :password_confirmation, :remember_me
9   
10   def active_for_authentication?\r
11     super && (self.approve == 1)
12   end
13
14   def create_token
15     self.ensure_authentication_token
16     self.save
17   end
18   
19   def delete_token
20     self.authentication_token = nil
21     self.save
22   end
23   
24   def apv
25     self.approve = 1
26     self.save
27   end
28   
29   def self.start(email, passwd)
30     a = Admin.find(:first, :conditions => ['email = ?', email])
31     if a
32       a.password = passwd
33       a.password_confirmation = passwd
34     else
35       a = Admin.create! :email => email, :password => passwd, :password_confirmation => passwd
36     end
37     a.approve = 1
38     a.save!
39   end
40   
41 end