Sha256: 298a81b74ed6bbf609ed80a6e884124f3b7ff8c1a9f6ad6f2b99d3aad9041bb9
Contents?: true
Size: 1.72 KB
Versions: 2
Compression:
Stored size: 1.72 KB
Contents
class User include Mongoid::Document before_create {generate_token(:auth_token)} field :provider, :type => String field :uid, :type => String field :code, :type => String field :email, :type => String field :role, :type => String field :user, :type => String field :auth_token, :type => String field :password_reset_token, :type => String field :password_reset_sent_at,:type => DateTime field :image, :type => String belongs_to :identity, :polymorphic => true, :optional => true has_many :xmains, :class_name => "Jinda::Xmain" ## Add to create forgot password def generate_token(column) begin self[column] = SecureRandom.urlsafe_base64 end #end while User.exists?(column => self[column]) end def has_role(role1) return role.upcase.split(',').include?(role1.upcase) end def self.from_omniauth(auth) # Rails now no longer support slice # where(auth.slice(:uid, :provider, :email)).first_or_create do |user| where(uid: auth.uid, provider: auth.provider, email: auth.info.email).first_or_create do |user| case auth.provider when 'identity' identity = Identity.find auth.uid user.code = identity.code user.email = identity.email else user.email = auth.info.email user.uid = auth.uid user.provider = auth.provider user.code = auth.info.name user.role = "M" user.image = auth.info.image end end end def ma_secured? role.upcase.split(',').include?(ma_secured_ROLE) end def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = Time.zone.now save! UserMailer.password_reset(self).deliver end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jinda-0.2.0 | lib/generators/jinda/templates/app/models/user.rb |
jinda-0.1.9 | lib/generators/jinda/templates/app/models/user.rb |