userutil.go 998 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2022 The Gogs 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 userutil
  5. import (
  6. "encoding/hex"
  7. "fmt"
  8. "strings"
  9. "gogs.io/gogs/internal/conf"
  10. "gogs.io/gogs/internal/tool"
  11. )
  12. // DashboardURLPath returns the URL path to the user or organization dashboard.
  13. func DashboardURLPath(name string, isOrganization bool) string {
  14. if isOrganization {
  15. return conf.Server.Subpath + "/org/" + name + "/dashboard/"
  16. }
  17. return conf.Server.Subpath + "/"
  18. }
  19. // GenerateActivateCode generates an activate code based on user information and
  20. // the given email.
  21. func GenerateActivateCode(id int64, email, name, password, rands string) string {
  22. code := tool.CreateTimeLimitCode(
  23. fmt.Sprintf("%d%s%s%s%s", id, email, strings.ToLower(name), password, rands),
  24. conf.Auth.ActivateCodeLives,
  25. nil,
  26. )
  27. // Add tailing hex username
  28. code += hex.EncodeToString([]byte(strings.ToLower(name)))
  29. return code
  30. }