Module: Milia::InviteMember

Defined in:
lib/milia/invite_member.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

#############################################################################


7
8
9
# File 'lib/milia/invite_member.rb', line 7

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#attempt_set_password(params) ⇒ Object


new function to set the password without knowing the current password



22
23
24
25
26
27
# File 'lib/milia/invite_member.rb', line 22

def attempt_set_password(params)
  p = {}
  p[:password] = params[:password]
  p[:password_confirmation] = params[:password_confirmation]
  update_attributes(p)
end

#check_or_set_passwordObject


check_or_set_password – if password missing, generates a password ASSUMES: Milia.use_invite_member



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/milia/invite_member.rb', line 71

def check_or_set_password

  if self.password.blank?
    self.password =
      ::Milia::Password.generate(
        8, Password::ONE_DIGIT | Password::ONE_CASE
      )

      self.password_confirmation = self.password
  else
    # if a password is being supplied, then ok to skip
    # setting up a password upon confirm
    self.skip_confirm_change_password = true if ::Milia.use_invite_member
  end

end

#has_no_password?Boolean


Returns:

  • (Boolean)

32
33
34
# File 'lib/milia/invite_member.rb', line 32

def has_no_password?
  self.encrypted_password.blank?
end

#only_if_unconfirmedObject



39
40
41
# File 'lib/milia/invite_member.rb', line 39

def only_if_unconfirmed
  pending_any_confirmation {yield}
end

#save_and_invite_memberObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/milia/invite_member.rb', line 52

def save_and_invite_member
  status = nil

  if (self.email.blank?)
    self.errors.add(:email, :blank)
  elsif User.where([ "lower(email) = ?", self.email.downcase ]).present?
    self.errors.add(:email, :taken)
			else
check_or_set_password()
    status = self.save && self.errors.empty?
  end

  return status
end