OSDN Git Service

test speech balloon extended
[pettanr/pettanr.git] / app / models / admin.rb
index 07f6523..abff349 100644 (file)
@@ -1,14 +1,41 @@
 class Admin < ActiveRecord::Base
   # Include default devise modules. Others available are:
-  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
+  # , :encryptable, :lockable, :timeoutable and :omniauthable, :confirmable
   devise :database_authenticatable, :registerable,
-         :recoverable, :rememberable, :trackable, :validatable
+         :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
 
   # Setup accessible (or protected) attributes for your model
   attr_accessible :email, :password, :password_confirmation, :remember_me
   
+  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)
-    Admin.create! :email => email, :password => passwd, :password_confirmation => passwd, :activate => true
+    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