Class: UserInvitation

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveUUID::UUID
Defined in:
app/models/user_invitation.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveUUID::UUID

#fix_uuid_strings, included

Class Method Details

.find_by_invitation_token(invitation_token) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/user_invitation.rb', line 15

def self.find_by_invitation_token(invitation_token)
  begin
    user_invitation = UserInvitation.find(id = invitation_token.gsub(/.{27}$/, ''))
    if user_invitation.token == invitation_token.gsub(/^#{id}/, '')
      return user_invitation
    else
      return nil
    end
  rescue
    return nil
  end
end

Instance Method Details

#accept(user) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/user_invitation.rb', line 28

def accept(user)
  if ..where(:user_id => user.id).empty?
     = ..create(:user => user)
    .set_roles(roles.split(',')) if roles
    self.used = true
    save
    true
  else
    false
  end
end