Guest User

Untitled

a guest
Mar 10th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1.  
  2. class Membership < ActiveRecord::Base
  3.  
  4. belongs_to :group
  5. belongs_to :user
  6.  
  7. validate_on_create :external_membership?
  8.  
  9. attr_accessor :username,
  10. :password
  11.  
  12. private
  13.  
  14. def external_membership?
  15. if private?
  16. request = PrivateGroupApi::Request.new group.api
  17. request.username = username
  18. request.password = password
  19. request.on_failure do
  20. errors.add_to_base "You do not have an account with this group's web site"
  21. end
  22. request.on_error do
  23. errors.add_to_base 'There was a problem when trying to authenticate your account'
  24. end
  25. request.authenticate
  26. end
  27. end
  28.  
  29. end
Add Comment
Please, Sign In to add comment