two_factor.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package errors
  7. import "fmt"
  8. // TwoFactorNotFound represents a "TwoFactorNotFound" kind of error
  9. type TwoFactorNotFound struct {
  10. UserID int64
  11. }
  12. // IsTwoFactorNotFound checks if an error is a TwoFactorNotFound
  13. func IsTwoFactorNotFound(err error) bool {
  14. _, ok := err.(TwoFactorNotFound)
  15. return ok
  16. }
  17. func (err TwoFactorNotFound) Error() string {
  18. return fmt.Sprintf("two-factor authentication does not found [user_id: %d]", err.UserID)
  19. }
  20. // TwoFactorRecoveryCodeNotFound represents a "TwoFactorRecoveryCodeNotFound" kind of error
  21. type TwoFactorRecoveryCodeNotFound struct {
  22. Code string
  23. }
  24. // IsTwoFactorRecoveryCodeNotFound checks if an error is a TwoFactorRecoveryCodeNotFound
  25. func IsTwoFactorRecoveryCodeNotFound(err error) bool {
  26. _, ok := err.(TwoFactorRecoveryCodeNotFound)
  27. return ok
  28. }
  29. func (err TwoFactorRecoveryCodeNotFound) Error() string {
  30. return fmt.Sprintf("two-factor recovery code does not found [code: %s]", err.Code)
  31. }