-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathflowAuthCodeSignup.go
More file actions
34 lines (29 loc) · 896 Bytes
/
flowAuthCodeSignup.go
File metadata and controls
34 lines (29 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"github.com/patrickmn/go-cache"
"log"
"net/http"
)
func init() {
Router.HandleFunc("/signup", handlerSignupPost).Methods("POST")
}
func handlerSignupPost(w http.ResponseWriter, r *http.Request) {
code := generateRandomNumbers(flowConfig.VerificationCodeLength)
owner := Owner{
Email: r.FormValue("email"),
Phone: r.FormValue("phone"),
Password: r.FormValue("password"),
Data: r.FormValue("data"),
VerificationCode: code,
VerificationRoute: authCodeConfig.OauthCodeUi + "/verify/" + code,
}
if id, err := owner.create(); err == nil {
VerifyStorage.Set(code, id, cache.DefaultExpiration)
log.Printf("Verification code for user '%s' is: %s", id, code)
w.WriteHeader(http.StatusCreated)
} else {
log.Printf(err.Error())
Rnd.JSON(w, http.StatusForbidden, ErrorResponse{err.Error()})
}
return
}