Sha256: ff7b9a5ac921cd3c76cde49ea3be682cbd6efe690d825fb328a66ef6f92b608e
Contents?: true
Size: 933 Bytes
Versions: 1
Compression:
Stored size: 933 Bytes
Contents
class UserInvitation < ActiveRecord::Base validates :email, :email => true, :presence => true before_save :set_token before_create :set_sent_at after_create :send_email belongs_to :account 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 def accept(user) Account.find(account_id).account_users << account_user = AccountUser.create(:user_id => user.id) account_user.set_roles(roles.split(',')) if roles end private def set_token self.token = SecureRandom.urlsafe_base64(20) unless token end def set_sent_at self.sent_at = Time.now end def send_email IuguMailer.invitation(self).deliver end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
iugusdk-1.0.0.alpha.1 | app/models/user_invitation.rb |