gitea源码

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package db
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/auth"
  7. user_model "code.gitea.io/gitea/models/user"
  8. )
  9. // Source is a password authentication service
  10. type Source struct {
  11. auth.ConfigBase `json:"-"`
  12. }
  13. // FromDB fills up an OAuth2Config from serialized format.
  14. func (source *Source) FromDB(bs []byte) error {
  15. return nil
  16. }
  17. // ToDB exports the config to a byte slice to be saved into database (this method is just dummy and does nothing for DB source)
  18. func (source *Source) ToDB() ([]byte, error) {
  19. return nil, nil
  20. }
  21. // Authenticate queries if login/password is valid against the PAM,
  22. // and create a local user if success when enabled.
  23. func (source *Source) Authenticate(ctx context.Context, user *user_model.User, login, password string) (*user_model.User, error) {
  24. return Authenticate(ctx, user, login, password)
  25. }
  26. func init() {
  27. auth.RegisterTypeConfig(auth.NoType, &Source{})
  28. auth.RegisterTypeConfig(auth.Plain, &Source{})
  29. }