From 293283ed256dfa03397a50f0c26447f7afb90c4d Mon Sep 17 00:00:00 2001 From: Mikey Date: Sun, 31 Jul 2022 01:02:28 +0800 Subject: [PATCH] feat: add get user by phone (#934) * fix: check reset phone & email modify rules * Update verification.go * Update organization.go * feat: add get user by phone Co-authored-by: Yang Luo --- controllers/user.go | 15 +++++++++++---- object/user.go | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/controllers/user.go b/controllers/user.go index 81e46353..a9e45fc9 100644 --- a/controllers/user.go +++ b/controllers/user.go @@ -80,12 +80,16 @@ func (c *ApiController) GetUsers() { // @Title GetUser // @Tag User API // @Description get user -// @Param id query string true "The id of the user" +// @Param id query string true "The id of the user" +// @Param owner query string false "The owner of the user" +// @Param email query string false "The email of the user" +// @Param phone query string false "The phone of the user" // @Success 200 {object} object.User The Response object // @router /get-user [get] func (c *ApiController) GetUser() { id := c.Input().Get("id") email := c.Input().Get("email") + phone := c.Input().Get("phone") userId := c.Input().Get("userId") owner := c.Input().Get("owner") @@ -104,11 +108,14 @@ func (c *ApiController) GetUser() { } var user *object.User - if email != "" { + switch { + case email != "": user = object.GetUserByEmail(owner, email) - } else if userId != "" { + case phone != "": + user = object.GetUserByPhone(owner, phone) + case userId != "": user = object.GetUserByUserId(owner, userId) - } else { + default: user = object.GetUser(id) } diff --git a/object/user.go b/object/user.go index 9292a23d..00ce03ca 100644 --- a/object/user.go +++ b/object/user.go @@ -273,6 +273,24 @@ func GetUserByEmail(owner string, email string) *User { } } +func GetUserByPhone(owner string, phone string) *User { + if owner == "" || phone == "" { + return nil + } + + user := User{Owner: owner, Phone: phone} + existed, err := adapter.Engine.Get(&user) + if err != nil { + panic(err) + } + + if existed { + return &user + } else { + return nil + } +} + func GetUserByUserId(owner string, userId string) *User { if owner == "" || userId == "" { return nil