You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user.go 825 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package sso
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. )
  9. // SignedInUser returns the user object of signed user.
  10. // It returns a bool value to indicate whether user uses basic auth or not.
  11. func SignedInUser(req *http.Request, w http.ResponseWriter, ds DataStore, sess SessionStore) (*models.User, bool) {
  12. if !models.HasEngine {
  13. return nil, false
  14. }
  15. // Try to sign in with each of the enabled plugins
  16. for _, ssoMethod := range Methods() {
  17. if !ssoMethod.IsEnabled() {
  18. continue
  19. }
  20. user := ssoMethod.VerifyAuthData(req, w, ds, sess)
  21. if user != nil {
  22. _, isBasic := ssoMethod.(*Basic)
  23. return user, isBasic
  24. }
  25. }
  26. return nil, false
  27. }