# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
-
- # Setup accessible (or protected) attributes for your model
- attr_accessible :id, :name, :password, :password_confirmation, :remember_me , :email
+ :recoverable, :rememberable, :trackable, :validatable,
+ :omniauthable#, :confirmable
def create_token
- self.ensure_authentication_token
+ loop do
+ token = Devise.friendly_token
+ if token_suitable?(token)
+ self.authentication_token = token
+ break
+ end
+ end
self.save
end
+
+ def token_suitable?(token)
+ !self.class.exists?(authentication_token: token)
+ end
def delete_token
self.authentication_token = nil
res
end
+ private
+ def user_params
+ params.require(:user).permit(:email, :password, :password_confirmation, :remember_me, :authentication_token)
+ end
+
end