-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
151 lines (132 loc) · 3.86 KB
/
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package cocka2notesapi
import (
"encoding/json"
"strconv"
)
/*
Six910 is a shopping cart and E-commerce system.
Copyright (C) 2020 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2020 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//AddUser AddUser
func (a *NotesAPI) AddUser(u *User) *Response {
var rtn Response
var aurl = a.restURL + "/rs/user/add"
a.log.Debug("url: ", aurl)
aJSON, err := json.Marshal(u)
if err == nil {
reqacu := a.buildRequest(post, aurl, a.headers, aJSON)
sucaacu, stat := a.proxy.Do(reqacu, &rtn)
a.log.Debug("suc: ", sucaacu)
a.log.Debug("stat: ", stat)
if !sucaacu {
rtn.Code = int64(stat)
}
}
a.log.Debug("rtn: ", rtn)
return &rtn
}
//UpdateUser UpdateUser
func (a *NotesAPI) UpdateUser(u *User) *Response {
var rtn Response
var url = a.restURL + "/rs/user/update"
a.log.Debug("url: ", url)
aJSON, err := json.Marshal(u)
if err == nil {
reqacuu := a.buildRequest(put, url, a.headers, aJSON)
acuusuc, stat := a.proxy.Do(reqacuu, &rtn)
a.log.Debug("suc: ", acuusuc)
a.log.Debug("stat: ", stat)
if !acuusuc {
rtn.Code = int64(stat)
}
}
a.log.Debug("rtn: ", rtn)
return &rtn
}
//AddUserToNote AddUserToNote
func (a *NotesAPI) AddUserToNote(n *NoteUsers) *Response {
var rtn Response
var aurl = a.restURL + "/rs/note/user/add"
a.log.Debug("url: ", aurl)
aJSON, err := json.Marshal(n)
if err == nil {
reqacu := a.buildRequest(post, aurl, a.headers, aJSON)
sucaacu, stat := a.proxy.Do(reqacu, &rtn)
a.log.Debug("suc: ", sucaacu)
a.log.Debug("stat: ", stat)
if !sucaacu {
rtn.Code = int64(stat)
}
}
a.log.Debug("rtn: ", rtn)
return &rtn
}
//GetNoteUserList GetNoteUserList
func (a *NotesAPI) GetNoteUserList(noteID int64, ownerEmail string) *[]string {
var rtn []string
idStr := strconv.FormatInt(noteID, 10)
var url = a.restURL + "/rs/note/users/" + idStr + "/" + ownerEmail
a.log.Debug("url: ", url)
req := a.buildRequest(get, url, a.headers, nil)
suc, stat := a.proxy.Do(req, &rtn)
a.log.Debug("suc: ", suc)
a.log.Debug("stat: ", stat)
return &rtn
}
//GetUser GetUser
func (a *NotesAPI) GetUser(email string) *User {
var rtn User
var url = a.restURL + "/rs/user/get/" + email
a.log.Debug("url: ", url)
req := a.buildRequest(get, url, a.headers, nil)
suc, stat := a.proxy.Do(req, &rtn)
a.log.Debug("suc: ", suc)
a.log.Debug("stat: ", stat)
return &rtn
}
//Login Login
func (a *NotesAPI) Login(u *User) *LoginResponse {
var rtn LoginResponse
var aurl = a.restURL + "/rs/user/login"
a.log.Debug("url: ", aurl)
aJSON, err := json.Marshal(u)
if err == nil {
reqacu := a.buildRequest(post, aurl, a.headers, aJSON)
sucaacu, stat := a.proxy.Do(reqacu, &rtn)
a.log.Debug("suc: ", sucaacu)
a.log.Debug("stat: ", stat)
}
a.log.Debug("rtn: ", rtn)
return &rtn
}
//ResetPassword ResetPassword
func (a *NotesAPI) ResetPassword(u *User) *Response {
var rtn Response
var url = a.restURL + "/rs/user/password/reset"
a.log.Debug("url: ", url)
aJSON, err := json.Marshal(u)
if err == nil {
reqacuu := a.buildRequest(put, url, a.headers, aJSON)
acuusuc, stat := a.proxy.Do(reqacuu, &rtn)
a.log.Debug("suc: ", acuusuc)
a.log.Debug("stat: ", stat)
if !acuusuc {
rtn.Code = int64(stat)
}
}
a.log.Debug("rtn: ", rtn)
return &rtn
}