docs(website): 添加简记memo产品原型和UI设计规范文档
- 新增「简记memo」一体化小程序产品原型设计文档 - 新增简记memo完整版UI视觉设计规范和界面细节 - 添加IDEA项目配置文件.gitignore - 创建404页面HTML文件,包含响应式布局和错误提示 - 添加关于页面HTML文件,展示品牌介绍和团队信息 - 实现AES加解密工具函数,支持请求体加密 - 添加用户协议页面基础框架
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"simple-memo/global"
|
||||
"simple-memo/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
const userCodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func GenerateUserCode() string {
|
||||
for {
|
||||
code := generateRandomCode(8)
|
||||
if isUserCodeUnique(code) {
|
||||
return code
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func generateRandomCode(length int) string {
|
||||
result := make([]byte, length)
|
||||
for i := range result {
|
||||
result[i] = userCodeChars[rand.Intn(len(userCodeChars))]
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func isUserCodeUnique(code string) bool {
|
||||
var count int64
|
||||
global.DB.Model(&models.User{}).Where("user_code = ?", code).Count(&count)
|
||||
return count == 0
|
||||
}
|
||||
Reference in New Issue
Block a user