OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
[pettanr/pettanr.git] / app / models / user.rb
1 class User < ActiveRecord::Base
2   has_one :author
3   
4   # Include default devise modules. Others available are:
5   # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
6   devise :database_authenticatable, :registerable,
7          :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
8
9   # Setup accessible (or protected) attributes for your model
10   attr_accessible :id, :name, :password, :password_confirmation, :remember_me , :email
11
12   def create_token
13     self.ensure_authentication_token
14     self.save
15   end
16   
17   def delete_token
18     self.authentication_token = nil
19     self.save
20   end
21   
22   def destroy
23     res = false
24     User.transaction do
25       self.author.comics.each do |comic|
26         raise ActiveRecord::Rollback unless comic.destroy_with_story
27       end
28       self.author.panels.each do |panel|
29         raise ActiveRecord::Rollback unless panel.destroy_with_elements
30       end
31       if self.author.artist
32         self.author.artist.original_pictures.each do |original_picture|
33           raise ActiveRecord::Rollback unless original_picture.destroy_with_resource_picture
34         end
35         raise ActiveRecord::Rollback unless self.author.artist.destroy
36       end
37       raise ActiveRecord::Rollback unless self.author.destroy
38       raise ActiveRecord::Rollback unless super
39       res = true
40     end
41     res
42   end
43   
44 end