Sha256: c1ec649463c99b9e53ed5b31dc2709ed25f0e0b845d7744547b0fd4d9d445e34
Contents?: true
Size: 1.66 KB
Versions: 15
Compression:
Stored size: 1.66 KB
Contents
class User < ActiveRecord::Base attr_accessible :first_name , :last_name , :email , :password , :password_confirmation , :bio , :image_id self.table_name = "gb_users" belongs_to :images , :foreign_key => "image_id" , :class_name => "Gluttonberg::Asset" validates_presence_of :first_name , :email , :role validates_format_of :password, :with => /^(?=.*\d)(?=.*[a-zA-Z])(?!.*[^\w\S\s]).{6,}$/ , :if => :require_password?, :message => "must be a minimum of 6 characters in length, contain at least 1 letter and at least 1 number" clean_html [:bio] acts_as_authentic do |c| c.login_field = "email" end def full_name self.first_name = "" if self.first_name.blank? self.last_name = "" if self.last_name.blank? self.first_name + " " + self.last_name end def deliver_password_reset_instructions! reset_perishable_token! Notifier.password_reset_instructions(self.id).deliver end def super_admin? self.role == "super_admin" end def admin? self.role == "admin" end def self.user_roles @roles ||= (["super_admin" , "admin" , "contributor"] << (Rails.configuration.user_roles) ).flatten end def user_valid_roles(user) if user.id == self.id [] else roles = (["super_admin" , "admin" , "contributor"] << (Rails.configuration.user_roles) ).flatten roles.delete("super_admin") unless self.super_admin? roles.delete("contributor") if !self.super_admin? && !self.admin? roles end end def have_backend_access? ["super_admin" , "admin" , "contributor"].include?(self.role) end def self.all_super_admin_and_admins self.where(:role => ["super_admin" , "admin"]).all end end
Version data entries
15 entries across 15 versions & 1 rubygems