From 6063a7dd717b02617bbbf0cb8fd0c2cb57ba1297 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Thu, 7 Apr 2022 07:28:04 +0300 Subject: [PATCH] Automatically approve users who link their discord account --- src/website/discord.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/website/discord.go b/src/website/discord.go index d8e58ad..8554da9 100644 --- a/src/website/discord.go +++ b/src/website/discord.go @@ -78,6 +78,22 @@ func DiscordOAuthCallback(c *RequestContext) ResponseData { return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to save new Discord user info")) } + if c.CurrentUser.Status == models.UserStatusConfirmed { + _, err = c.Conn.Exec(c.Context(), + ` + UPDATE auth_user + SET status = $1 + WHERE id = $2 + `, + models.UserStatusApproved, + c.CurrentUser.ID, + ) + if err != nil { + c.Logger.Error().Err(err).Msg("failed to set user status to approved after linking discord account") + // NOTE(asaf): It's not worth failing the request over this, so we're not returning an error to the user. + } + } + return c.Redirect(hmnurl.BuildUserSettings("discord"), http.StatusSeeOther) }