feat: add captcha when signing up (closes #53)
This commit is contained in:
parent
bb3d56f548
commit
6f7eb5eeee
23 changed files with 316 additions and 61 deletions
|
@ -55,9 +55,10 @@ type tumblrCallbackResponse struct {
|
|||
Token string `json:"token,omitempty"`
|
||||
User *userResponse `json:"user,omitempty"`
|
||||
|
||||
Tumblr string `json:"tumblr,omitempty"` // username, for UI purposes
|
||||
Ticket string `json:"ticket,omitempty"`
|
||||
RequireInvite bool `json:"require_invite"` // require an invite for signing up
|
||||
Tumblr string `json:"tumblr,omitempty"` // username, for UI purposes
|
||||
Ticket string `json:"ticket,omitempty"`
|
||||
RequireInvite bool `json:"require_invite"` // require an invite for signing up
|
||||
RequireCaptcha bool `json:"require_captcha"`
|
||||
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||
|
@ -200,10 +201,11 @@ func (s *Server) tumblrCallback(w http.ResponseWriter, r *http.Request) error {
|
|||
}
|
||||
|
||||
render.JSON(w, r, tumblrCallbackResponse{
|
||||
HasAccount: false,
|
||||
Tumblr: tumblrName,
|
||||
Ticket: ticket,
|
||||
RequireInvite: s.RequireInvite,
|
||||
HasAccount: false,
|
||||
Tumblr: tumblrName,
|
||||
Ticket: ticket,
|
||||
RequireInvite: s.RequireInvite,
|
||||
RequireCaptcha: s.hcaptchaSecret != "",
|
||||
})
|
||||
|
||||
return nil
|
||||
|
@ -335,6 +337,19 @@ func (s *Server) tumblrSignup(w http.ResponseWriter, r *http.Request) error {
|
|||
return server.APIError{Code: server.ErrInvalidTicket}
|
||||
}
|
||||
|
||||
// check captcha
|
||||
if s.hcaptchaSecret != "" {
|
||||
ok, err := s.verifyCaptcha(ctx, req.CaptchaResponse)
|
||||
if err != nil {
|
||||
log.Errorf("verifying captcha: %v", err)
|
||||
return server.APIError{Code: server.ErrInternalServerError}
|
||||
}
|
||||
|
||||
if !ok {
|
||||
return server.APIError{Code: server.ErrInvalidCaptcha}
|
||||
}
|
||||
}
|
||||
|
||||
u, err := s.DB.CreateUser(ctx, tx, req.Username)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == db.ErrUsernameTaken {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue