Skip to content

Commit

Permalink
fix "disable user registration in yiwen.ltd"
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Sep 17, 2023
1 parent 1f26ec7 commit 0afdfbb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/api/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ func (a *AuthN) Callback(ctx *gear.Context) error {

// disable user registration in yiwen.ltd
if conf.Config.Env != "prod" {
a.blls.Session.DisabledUser(ctx, res.UID)
if _, err = a.blls.Session.DisabledUser(ctx, res.UID); err != nil {
logging.SetTo(ctx, "error", fmt.Sprintf("DisabledUser failed: %v", err))
}
}
} else {
a.blls.Logbase.Log(ctx, bll.LogActionUserLogin, 1, res.UID, res.UID, &bll.LogPayload{
Expand Down
26 changes: 20 additions & 6 deletions src/bll/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,37 @@ type userInfo struct {
Status int8 `json:"status" cbor:"status"`
}

func (b *Session) DisabledUser(ctx context.Context, uid util.ID) (*SuccessResponse[bool], error) {
func (b *Session) DisabledUser(ctx context.Context, uid util.ID) (*SuccessResponse[userInfo], error) {
res := SuccessResponse[userInfo]{}
api := "/v1/user?fields=cn,name,updated_at,status&id=" + uid.String()
if err := b.svc.Get(ctx, api, &res); err != nil {
return nil, err
}

if res.Result.Status == -2 {
return &SuccessResponse[bool]{Result: true}, nil
return &res, nil
}

output := SuccessResponse[bool]{}
if res.Result.Status >= 0 {
updatedAt := res.Result.UpdatedAt
res = SuccessResponse[userInfo]{}
if err := b.svc.Patch(ctx, "/v1/sys/user/update_status", &UpdateSpecialFieldInput{
ID: uid,
UpdatedAt: updatedAt,
Status: util.Ptr(int8(-1)),
}, &res); err != nil {
return nil, err
}
}

updatedAt := res.Result.UpdatedAt
res = SuccessResponse[userInfo]{}
if err := b.svc.Patch(ctx, "/v1/sys/user/update_status", &UpdateSpecialFieldInput{
ID: uid,
UpdatedAt: res.Result.UpdatedAt,
UpdatedAt: updatedAt,
Status: util.Ptr(int8(-2)),
}, &output); err != nil {
}, &res); err != nil {
return nil, err
}
return &output, nil
return &res, nil
}

0 comments on commit 0afdfbb

Please sign in to comment.