module DeviseMeteor::MeteorUserModel
Public Instance Methods
after_confirmation()
click to toggle source
called by devise after confirmation is set
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 54 def after_confirmation emails_temp = emails # we have to do this, by pop and re-adding because # MongoDb does not save when update within a nested array when is called by $set # So we pop our email out and overwrite the array completely # This approach does not work like expected which should update AND PERSIST, which does not work # User.where("emails.address" => email) # .set('emails.$.verified': true) hash = emails.pop { |m| m[:address] == email } hash[:verified] = true emails_temp << hash set(emails: emails_temp) end
meteor_get_hash_by_email(given_mail)
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 48 def meteor_get_hash_by_email(given_mail) used_mail = given_mail.nil? ? email : given_mail emails.detect { |mail| mail[:address] == used_mail } end
name()
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 32 def name profile.name end
name=(name)
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 36 def name=(name) profile.update_attribute(:name, name) end
username()
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 40 def username profile.username end
username=(username)
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 44 def username=(username) profile.update_attribute(:username, username) end
Private Instance Methods
build_meteor_mail_hash(email, verified_state)
click to toggle source
build a default email hash
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 103 def build_meteor_mail_hash(email, verified_state) {address: email, verified: verified_state} end
build_meteor_password_hash(encrypted_password)
click to toggle source
build a default password hash
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 71 def build_meteor_password_hash(encrypted_password) {bcrypt: encrypted_password} end
meteor_create_initial_email()
click to toggle source
called when user is created
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 119 def meteor_create_initial_email add_to_set(emails: build_meteor_mail_hash(email, confirmed?)) end
meteor_init()
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 114 def meteor_init meteor_create_initial_email end
meteor_map_attributes()
click to toggle source
remaps devise for devise_meteor
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 108 def meteor_map_attributes meteor_map_email meteor_map_name meteor_map_password end
meteor_map_email()
click to toggle source
maps current email to devise_meteor emails: :address
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 76 def meteor_map_email if attribute_changed?(:email) && email.present? existing_meteor_mail = meteor_get_hash_by_email(email) if existing_meteor_mail emails.delete(existing_meteor_mail) if existing_meteor_mail[:verified] == true new_mail = build_meteor_mail_hash(email, true) skip_confirmation! else new_mail = build_meteor_mail_hash(email, false) end else new_mail = build_meteor_mail_hash(email, false) end add_to_set(emails: new_mail) end end
meteor_map_name()
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 95 def meteor_map_name if attribute_changed?(:name) && name.present? name = first_name + " " + last_name profile.update_attribute(:name, name) end end
meteor_map_password()
click to toggle source
# File lib/devise_meteor/concerns/meteor_user_model.rb, line 123 def meteor_map_password if (attribute_changed?(:encrypted_password) && encrypted_password.present?) || (encrypted_password.nil? && !sessions.password[:bcrypt].nil?) password_hash = build_meteor_password_hash(encrypted_password) services.set(password: password_hash) elsif encrypted_password.nil? update_attribute!(:encrypted_password, services.password[:bcrypt]) end end