-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverification_code.go
60 lines (51 loc) · 1.42 KB
/
verification_code.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package controllers
import (
"fmt"
"github.com/opensourceways/app-cla-server/config"
"github.com/opensourceways/app-cla-server/email"
"github.com/opensourceways/app-cla-server/models"
)
type VerificationCodeController struct {
baseController
}
func (this *VerificationCodeController) Prepare() {
this.apiPrepare("")
}
// @Title Post
// @Description send verification code when signing
// @Param :org_cla_id path string true "org cla id"
// @Param :email path string true "email of corp"
// @Success 201 {int} map
// @Failure util.ErrSendingEmail
// @router /:link_id/:email [post]
func (this *VerificationCodeController) Post() {
action := "create verification code"
linkID := this.GetString(":link_id")
emailOfSigner := this.GetString(":email")
orgInfo, merr := models.GetOrgOfLink(linkID)
if merr != nil {
this.sendFailedResponse(0, "", merr, action)
return
}
code, err := models.CreateVerificationCode(
emailOfSigner, linkID, config.AppConfig.VerificationCodeExpiry,
)
if err != nil {
this.sendModelErrorAsResp(err, action)
return
}
this.sendSuccessResp("create verification code successfully")
sendEmailToIndividual(
linkID, emailOfSigner,
fmt.Sprintf(
"Verification code for signing CLA on project of \"%s\"",
orgInfo.OrgAlias,
),
email.VerificationCode{
Email: emailOfSigner,
Org: orgInfo.OrgAlias,
Code: code,
ProjectURL: orgInfo.ProjectURL(),
},
)
}