(c *context.Context, cpt *captcha.Captcha, f form.Register)
| 310 | } |
| 311 | |
| 312 | func SignUpPost(c *context.Context, cpt *captcha.Captcha, f form.Register) { |
| 313 | c.Title("sign_up") |
| 314 | |
| 315 | c.Data["EnableCaptcha"] = conf.Auth.EnableRegistrationCaptcha |
| 316 | |
| 317 | if conf.Auth.DisableRegistration { |
| 318 | c.Status(http.StatusForbidden) |
| 319 | return |
| 320 | } |
| 321 | |
| 322 | if c.HasError() { |
| 323 | c.HTML(http.StatusBadRequest, tmplUserAuthSignup) |
| 324 | return |
| 325 | } |
| 326 | |
| 327 | if conf.Auth.EnableRegistrationCaptcha && !cpt.VerifyReq(c.Req) { |
| 328 | c.FormErr("Captcha") |
| 329 | c.RenderWithErr(c.Tr("form.captcha_incorrect"), http.StatusUnauthorized, tmplUserAuthSignup, &f) |
| 330 | return |
| 331 | } |
| 332 | |
| 333 | if f.Password != f.Retype { |
| 334 | c.FormErr("Password") |
| 335 | c.RenderWithErr(c.Tr("form.password_not_match"), http.StatusBadRequest, tmplUserAuthSignup, &f) |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | user, err := database.Handle.Users().Create( |
| 340 | c.Req.Context(), |
| 341 | f.UserName, |
| 342 | f.Email, |
| 343 | database.CreateUserOptions{ |
| 344 | Password: f.Password, |
| 345 | Activated: !conf.Auth.RequireEmailConfirmation, |
| 346 | }, |
| 347 | ) |
| 348 | if err != nil { |
| 349 | switch { |
| 350 | case database.IsErrUserAlreadyExist(err): |
| 351 | c.FormErr("UserName") |
| 352 | c.RenderWithErr(c.Tr("form.username_been_taken"), http.StatusUnprocessableEntity, tmplUserAuthSignup, &f) |
| 353 | case database.IsErrEmailAlreadyUsed(err): |
| 354 | c.FormErr("Email") |
| 355 | c.RenderWithErr(c.Tr("form.email_been_used"), http.StatusUnprocessableEntity, tmplUserAuthSignup, &f) |
| 356 | case database.IsErrNameNotAllowed(err): |
| 357 | c.FormErr("UserName") |
| 358 | c.RenderWithErr(c.Tr("user.form.name_not_allowed", err.(database.ErrNameNotAllowed).Value()), http.StatusBadRequest, tmplUserAuthSignup, &f) |
| 359 | default: |
| 360 | c.Error(err, "create user") |
| 361 | } |
| 362 | return |
| 363 | } |
| 364 | log.Trace("Account created: %s", user.Name) |
| 365 | |
| 366 | // FIXME: Count has pretty bad performance implication in large instances, we |
| 367 | // should have a dedicate method to check whether the "user" table is empty. |
| 368 | // |
| 369 | // Auto-set admin for the only user. |
nothing calls this directly
no test coverage detected