MCPcopy Create free account
hub / github.com/QuantumNous/new-api / EmailBind

Function EmailBind

controller/user.go:1210–1246  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

1208}
1209
1210func EmailBind(c *gin.Context) {
1211 var req emailBindRequest
1212 if err := common.DecodeJson(c.Request.Body, &req); err != nil {
1213 common.ApiError(c, errors.New("invalid request body"))
1214 return
1215 }
1216 email := req.Email
1217 email = model.NormalizeEmail(email)
1218 code := req.Code
1219 if !common.VerifyCodeWithKey(email, code, common.EmailVerificationPurpose) {
1220 common.ApiErrorI18n(c, i18n.MsgUserVerificationCodeError)
1221 return
1222 }
1223 session := sessions.Default(c)
1224 id := session.Get("id")
1225 user := model.User{
1226 Id: id.(int),
1227 }
1228 err := user.FillUserById()
1229 if err != nil {
1230 common.ApiError(c, err)
1231 return
1232 }
1233 if err := model.BindEmailToUser(&user, email); err != nil {
1234 if errors.Is(err, model.ErrEmailAlreadyTaken) {
1235 common.ApiErrorI18n(c, i18n.MsgUserEmailAlreadyTaken)
1236 return
1237 }
1238 common.ApiError(c, err)
1239 return
1240 }
1241 c.JSON(http.StatusOK, gin.H{
1242 "success": true,
1243 "message": "",
1244 })
1245 return
1246}
1247
1248type topUpRequest struct {
1249 Key string `json:"key"`

Callers

nothing calls this directly

Calls 8

FillUserByIdMethod · 0.95
DecodeJsonFunction · 0.92
ApiErrorFunction · 0.92
NormalizeEmailFunction · 0.92
VerifyCodeWithKeyFunction · 0.92
ApiErrorI18nFunction · 0.92
BindEmailToUserFunction · 0.92
GetMethod · 0.45

Tested by

no test coverage detected