-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserviceUser.go
56 lines (50 loc) · 1.95 KB
/
serviceUser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2023 gpress Authors.
//
// This file is part of gpress.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"context"
"gitee.com/chunanyong/zorm"
)
// insertUser 插入用户
func insertUser(ctx context.Context, user User) error {
// 清空用户,只能有一个管理员
deleteAll(ctx, tableUserName)
// 初始化数据
user.Id = "gpress_admin"
user.SortNo = 1
user.Status = 1
_, err := zorm.Transaction(ctx, func(ctx context.Context) (interface{}, error) {
return zorm.Insert(ctx, &user)
})
return err
}
// findUserId 查询用户ID
func findUserId(ctx context.Context, account string, password string) (string, error) {
finder := zorm.NewSelectFinder(tableUserName, "id").Append(" WHERE account=? and password=?", account, password)
userId := ""
_, err := zorm.QueryRow(ctx, finder, &userId)
return userId, err
}
// findUserAddress 查询用户区块链Address
func findUserAddress(ctx context.Context) (string, string, string, error) {
finder := zorm.NewSelectFinder(tableUserName, "id,chainType,chainAddress")
userMap, err := zorm.QueryRowMap(ctx, finder)
if len(userMap) < 1 || userMap["id"] == nil || userMap["chainType"] == nil || userMap["chainAddress"] == nil { //没有数据
return "", "", "", err
}
return userMap["id"].(string), userMap["chainType"].(string), userMap["chainAddress"].(string), err
}