aboutsummaryrefslogtreecommitdiff
path: root/internal/userutil/userutil.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-10-22 14:41:40 +0800
committerGitHub <noreply@github.com>2022-10-22 14:41:40 +0800
commitc502dc6ed888a4cf2c8b36176585f4166536ab6d (patch)
tree71e3f758069dc2435eecb88ae786b2efaaa972f9 /internal/userutil/userutil.go
parent260e990be75885e1a560df449dacdeecafeffdcf (diff)
refactor(db): move some methods from `user.go` to `users.go` (#7195)
Diffstat (limited to 'internal/userutil/userutil.go')
-rw-r--r--internal/userutil/userutil.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/userutil/userutil.go b/internal/userutil/userutil.go
new file mode 100644
index 00000000..87b8f15b
--- /dev/null
+++ b/internal/userutil/userutil.go
@@ -0,0 +1,36 @@
+// Copyright 2022 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package userutil
+
+import (
+ "encoding/hex"
+ "fmt"
+ "strings"
+
+ "gogs.io/gogs/internal/conf"
+ "gogs.io/gogs/internal/tool"
+)
+
+// DashboardURLPath returns the URL path to the user or organization dashboard.
+func DashboardURLPath(name string, isOrganization bool) string {
+ if isOrganization {
+ return conf.Server.Subpath + "/org/" + name + "/dashboard/"
+ }
+ return conf.Server.Subpath + "/"
+}
+
+// GenerateActivateCode generates an activate code based on user information and
+// the given email.
+func GenerateActivateCode(id int64, email, name, password, rands string) string {
+ code := tool.CreateTimeLimitCode(
+ fmt.Sprintf("%d%s%s%s%s", id, email, strings.ToLower(name), password, rands),
+ conf.Auth.ActivateCodeLives,
+ nil,
+ )
+
+ // Add tailing hex username
+ code += hex.EncodeToString([]byte(strings.ToLower(name)))
+ return code
+}