feat(server): Replace single-user service with muti-users service (#62)

* feat(svc/multiusers): add multi-users service

* test(multiusers): add unit tests for user store

* feat(multiusers): add multiusers service and refactor userstore

* feat(multiusers): add adduser api and tests

* feat(client): add adduser api
This commit is contained in:
Hexxa 2021-07-10 03:59:59 -05:00 committed by GitHub
parent 1680c5cb2f
commit 4b6f6d9e1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 866 additions and 90 deletions

View file

@ -1,10 +1,11 @@
package client
import (
"encoding/json"
"fmt"
"net/http"
su "github.com/ihexxa/quickshare/src/handlers/singleuserhdr"
"github.com/ihexxa/quickshare/src/handlers/multiusers"
"github.com/parnurzeal/gorequest"
)
@ -27,7 +28,7 @@ func (cl *SingleUserClient) url(urlpath string) string {
func (cl *SingleUserClient) Login(user, pwd string) (*http.Response, string, []error) {
return cl.r.Post(cl.url("/v1/users/login")).
Send(su.LoginReq{
Send(multiusers.LoginReq{
User: user,
Pwd: pwd,
}).
@ -42,10 +43,29 @@ func (cl *SingleUserClient) Logout(token *http.Cookie) (*http.Response, string,
func (cl *SingleUserClient) SetPwd(oldPwd, newPwd string, token *http.Cookie) (*http.Response, string, []error) {
return cl.r.Patch(cl.url("/v1/users/pwd")).
Send(su.SetPwdReq{
Send(multiusers.SetPwdReq{
OldPwd: oldPwd,
NewPwd: newPwd,
}).
AddCookie(token).
End()
}
func (cl *SingleUserClient) AddUser(name, pwd, role string, token *http.Cookie) (*http.Response, *multiusers.AddUserResp, []error) {
resp, body, errs := cl.r.Post(cl.url("/v1/users/")).
AddCookie(token).
Send(multiusers.AddUserReq{
Name: name,
Pwd: pwd,
Role: role,
}).
End()
auResp := &multiusers.AddUserResp{}
err := json.Unmarshal([]byte(body), auResp)
if err != nil {
errs = append(errs, err)
return nil, nil, errs
}
return resp, auResp, nil
}