Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Bottos-project/bottos
Browse files Browse the repository at this point in the history
  • Loading branch information
luomeiqin committed Apr 27, 2018
2 parents 5530fa8 + 62b8d82 commit 32e9a01
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 101 deletions.
18 changes: 18 additions & 0 deletions error/ErrorCode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[{
"code": 1001,
"lv": "ERROR",
"msg": {
"en": "username over length",
"cn": "用户名过长"
},
"details": "over length"
},{
"code": 1002,
"lv": "ERROR",
"msg": {
"en": "input tooshor",
"cn": "密码太短"
},
"details": "input tooshort"
}
]
68 changes: 68 additions & 0 deletions error/errcode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2017~2022 The Bottos Authors
// This file is part of the Bottos Chain library.
// Created by Rocket Core Team of Bottos.

//This program is free software: you can distribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
// along with bottos. If not, see <http://www.gnu.org/licenses/>.

/*
* file description: provide a interface error definition for all modules
* @Author: zl
* @Date: 2018-4-25
* @Last Modified by:
* @Last Modified time:
*/
package error

import (
"io/ioutil"
"encoding/json"
)

type ErrorCode struct {
Code int64 `json:"code"`
Lv string `json:"lv"`
Msg struct {
Cn string `json:"cn"`
En string `json:"en"`
} `json:"msg"`
Details string `json:"details"`
}


func GetErrorInfo(code int64) ErrorCode {
d := GetAllErrorInfos()

for _, v := range d {
if code == v.Code {
return v
}
}
return ErrorCode{}
}

func GetAllErrorInfos() []ErrorCode {
fr, err := ioutil.ReadFile("./ErrorCode.json")
if err != nil {
panic(err)
}

var d []ErrorCode
err = json.Unmarshal(fr, &d)
if err != nil {
panic(err)
}
return d
}


11 changes: 11 additions & 0 deletions error/errcode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package error

import "testing"

func Test_getErrorInfo(t *testing.T) {
t.Log(GetErrorInfo(1001))
}

func Test_GetAllErrorInfos(t *testing.T) {
t.Log(GetAllErrorInfos())
}
55 changes: 55 additions & 0 deletions service/identity/ideApi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,72 @@ import (
"strconv"
"regexp"
"github.com/code/bottos/config"
"github.com/mojocn/base64Captcha"
)

var configCode = base64Captcha.ConfigDigit{
Height: 80,
Width: 240,
MaxSkew: 0.7,
DotCount: 80,
CaptchaLen: 5,
}

//var configCode = base64Captcha.ConfigCharacter{
// Height: 60,
// Width: 240,
//// //const CaptchaModeNumber:数字,CaptchaModeAlphabet:字母,CaptchaModeArithmetic:算术,CaptchaModeNumberAlphabet:数字字母混合.
// Mode: base64Captcha.CaptchaModeNumber,
// ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
// ComplexOfNoiseDot: base64Captcha.CaptchaComplexLower,
// IsShowHollowLine: false,
// IsShowNoiseDot: false,
// IsShowNoiseText: false,
// IsShowSlimeLine: false,
// IsShowSineLine: false,
// CaptchaLen: 6,
//}

type User struct {
Client user.UserClient
}

func (u *User) GetVerificationCode(ctx context.Context, req *api.Request, rsp *api.Response) error {

idKeyD, capD := base64Captcha.GenerateCaptcha("", configCode)
//以base64编码
base64stringD := base64Captcha.CaptchaWriteToBase64Encoding(capD)

rsp.StatusCode = 200
b, _ := json.Marshal(map[string]interface{}{
"code": 1,
"data": map[string]interface{}{
"id_key": idKeyD,
"img_data": base64stringD,
},
"msg": "OK",
})

rsp.Body = string(b)
return nil
}


func (u *User) Register(ctx context.Context, req *api.Request, rsp *api.Response) error {
body := req.Body
//transfer to struct
var registerRequest user.RegisterRequest
json.Unmarshal([]byte(body), &registerRequest)

if !base64Captcha.VerifyCaptcha(registerRequest.IdKey, registerRequest.VerifyValue) {
b, _ := json.Marshal(map[string]interface{}{
"code": -8,
"msg": "Verification code error",
})
rsp.StatusCode = 200
rsp.Body = string(b)
return nil
}
//Checkout data format
ok, err := govalidator.ValidateStruct(registerRequest);
if !ok {
Expand Down
Loading

0 comments on commit 32e9a01

Please sign in to comment.