Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1.  
  2. when getting api_user from auth_token:
  3. if an AuthToken with auth_token=params[:auth_token] is found:
  4. if that auth_token is linked to an existing ApiUser:
  5. # note: we had an existing auth_token with an existing api_user
  6. return auth_token.api_user
  7.  
  8. else
  9. search for an ApiUser with api_key=auth_token.apikey, user=@current_user, device=nil, device_version=nil, app_version=nil:
  10.  
  11. if found:
  12. # note: we have a legacy AuthToken that has yet to be associated with its corresponding legacy ApiUser
  13. associate auth_token with this api_user
  14. return auth_token.api_user
  15.  
  16. else
  17. # note: we have a legacy AuthToken that never had an associated legacy ApiUser
  18. create a new ApiUser with api_key=auth_token.apikey, user=@current_user, device=nil, device_version=nil, app_version=nil:
  19. associate auth_token with this api_user
  20. return auth_token.api_user
  21.  
  22. else:
  23. # note: login failed or whatever
  24. return nil
  25.  
  26.  
  27. when getting auth_token from api_user:
  28. if api_user.auth_token is nil:
  29. if api_user.device==nil, api_user.device_version==nil, and api_user.app_version==nil:
  30. search for an AuthToken with apikey=apikey and user=user and api_user=nil
  31.  
  32. if found:
  33. # note: we have a legacy ApiUser that had yet to be associated with its legacy AuthToken
  34. associate auth_token with api_user
  35. return api_user.auth_token
  36.  
  37. else:
  38. # note: we have a legacy ApiUser that never had an associated legacy AuthToken
  39. create a new AuthToken with apikey=auth_token.api_key, user=api_user.user
  40. associate auth_token with api_user
  41. return api_user.auth_token
  42.  
  43. else:
  44. # note: we have a non-legacy api_user that has yet to have an AuthToken generated for it
  45. create a new AuthToken with apikey=auth_token.api_key, user=api_user.user
  46. associate auth_token with api_user
  47. return api_user.auth_token
  48.  
  49. else
  50. # note: we have an existing ApiUser that had an existing AuthToken
  51. return api_user.auth_token
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement