- Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathadmin_user.go
68 lines (60 loc) · 2.28 KB
/
admin_user.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
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2015 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 gogs
import (
"bytes"
"encoding/json"
"fmt"
)
typeCreateUserOptionstruct {
SourceIDint64`json:"source_id"`
LoginNamestring`json:"login_name"`
Usernamestring`json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"`
FullNamestring`json:"full_name" binding:"MaxSize(100)"`
Emailstring`json:"email" binding:"Required;Email;MaxSize(254)"`
Passwordstring`json:"password" binding:"MaxSize(255)"`
SendNotifybool`json:"send_notify"`
}
func (c*Client) AdminCreateUser(optCreateUserOption) (*User, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
user:=new(User)
returnuser, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
}
typeEditUserOptionstruct {
SourceIDint64`json:"source_id"`
LoginNamestring`json:"login_name"`
FullNamestring`json:"full_name" binding:"MaxSize(100)"`
Emailstring`json:"email" binding:"Required;Email;MaxSize(254)"`
Passwordstring`json:"password" binding:"MaxSize(255)"`
Websitestring`json:"website" binding:"MaxSize(50)"`
Locationstring`json:"location" binding:"MaxSize(50)"`
Active*bool`json:"active"`
Admin*bool`json:"admin"`
AllowGitHook*bool`json:"allow_git_hook"`
AllowImportLocal*bool`json:"allow_import_local"`
MaxRepoCreation*int`json:"max_repo_creation"`
}
func (c*Client) AdminEditUser(userstring, optEditUserOption) error {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnerr
}
_, err=c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body))
returnerr
}
func (c*Client) AdminDeleteUser(userstring) error {
_, err:=c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
returnerr
}
func (c*Client) AdminCreateUserPublicKey(userstring, optCreateKeyOption) (*PublicKey, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
key:=new(PublicKey)
returnkey, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
}