A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

29 righe
842 B

  1. /*
  2. * Copyright © 2018 Musing Studio LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package writefreely
  11. // AuthenticateUser ensures a user with the given accessToken is valid. Call
  12. // it before any operations that require authentication or optionally associate
  13. // data with a user account.
  14. // Returns an error if the given accessToken is invalid. Otherwise the
  15. // associated user ID is returned.
  16. func AuthenticateUser(db writestore, accessToken string) (int64, error) {
  17. if accessToken == "" {
  18. return 0, ErrNoAccessToken
  19. }
  20. userID := db.GetUserID(accessToken)
  21. if userID == -1 {
  22. return 0, ErrBadAccessToken
  23. }
  24. return userID, nil
  25. }