@@ -20,12 +20,15 @@ package controller
2020import (
2121 "fmt"
2222 "net/http"
23+ "strings"
2324 "text/template"
25+ "time"
2426
2527 "github.com/b3log/pipe/model"
2628 "github.com/b3log/pipe/service"
2729 "github.com/b3log/pipe/util"
2830 "github.com/gin-gonic/gin"
31+ "github.com/parnurzeal/gorequest"
2932)
3033
3134func showInitPageAction (c * gin.Context ) {
@@ -52,9 +55,51 @@ func initAction(c *gin.Context) {
5255 return
5356 }
5457
58+ arg := map [string ]interface {}{}
59+ if err := c .BindJSON (& arg ); nil != err {
60+ result .Code = - 1
61+ result .Msg = "parses init request failed"
62+
63+ return
64+ }
65+ b3key := strings .TrimSpace (arg ["b3key" ].(string ))
66+ if "" == b3key {
67+ result .Code = - 1
68+ result .Msg = "B3 key cant' be empty"
69+
70+ return
71+ }
72+ if 20 < len (b3key ) {
73+ result .Code = - 1
74+ result .Msg = "B3 key should less then 20 characters"
75+
76+ return
77+ }
78+
79+ checkResult := util .NewResult ()
80+ request := gorequest .New ()
81+ _ , _ , errs := request .Post (util .HacPaiURL + "/apis/check-b3key" ).Send (map [string ]interface {}{
82+ "userName" : session .UName ,
83+ "userB3Key" : b3key ,
84+ }).Set ("user-agent" , util .UserAgent ).Timeout (30 * time .Second ).EndStruct (checkResult )
85+ if nil != errs {
86+ logger .Errorf ("check b3 key failed: %s" , errs )
87+ result .Code = - 1
88+ result .Msg = "check b3 key failed"
89+
90+ return
91+ }
92+
93+ if 0 != checkResult .Code {
94+ result .Code = - 1
95+ result .Msg = "B3 key is not match"
96+
97+ return
98+ }
99+
55100 platformAdmin := & model.User {
56101 Name : session .UName ,
57- B3Key : session . UB3Key ,
102+ B3Key : b3key ,
58103 AvatarURL : session .UAvatar ,
59104 }
60105
0 commit comments