1 class User < ActiveRecord::Base
5 # Include default devise modules. Others available are:
6 # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
7 devise :database_authenticatable, :registerable,
8 :recoverable, :rememberable, :trackable, :validatable,
9 :omniauthable, :omniauth_providers => [:twitter, :google_oauth2]
14 token = Devise.friendly_token
15 if token_suitable?(token)
16 self.authentication_token = token
23 def token_suitable?(token)
24 !self.class.exists?(authentication_token: token)
28 self.authentication_token = nil
35 self.author.scrolls.each do |scroll|
36 raise ActiveRecord::Rollback unless scroll.destroy_with_scroll_panel
38 self.author.panels.each do |panel|
39 raise ActiveRecord::Rollback unless panel.destroy_with_elements
42 self.artist.original_pictures.each do |original_picture|
43 raise ActiveRecord::Rollback unless original_picture.destroy_with_resource_picture
45 raise ActiveRecord::Rollback unless self.artist.destroy
47 raise ActiveRecord::Rollback unless self.author.destroy
48 raise ActiveRecord::Rollback unless super
54 def self.from_omniauth(auth)
55 where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
56 user.name = auth.info.nickname
57 user.email = auth.info.email
61 def self.new_with_session(params, session)
62 if session["devise.user_attributes"]
63 new(session["devise.user_attributes"], without_protection: true) do |user|
64 user.attributes = params
72 def password_required?
73 super && provider.blank?
78 params.require(:user).permit(:email, :password, :password_confirmation, :remember_me, :authentication_token)