2022-05-05 08:07:01 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
|
|
|
"code.hoteas.com/golang/hotime/common"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var UpanCtr = Ctr{
|
|
|
|
"login": func(that *Context) {
|
|
|
|
timestamp := that.Req.FormValue("timestamp")
|
|
|
|
sn := that.Req.FormValue("sn")
|
|
|
|
|
|
|
|
//str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))//
|
|
|
|
re, e := DePwdCode(sn)
|
|
|
|
|
|
|
|
if e != nil {
|
|
|
|
that.Display(3, "数据异常")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
reStr := string(re)
|
|
|
|
realSn := strings.Replace(reStr, ":"+timestamp, "", -1)
|
|
|
|
if len(realSn)+len(timestamp)+1 != len(reStr) {
|
|
|
|
that.Display(4, "数据验证失败")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println("U盘校验", realSn)
|
|
|
|
user := that.Db.Get("user", "*", common.Map{"upankey": realSn})
|
|
|
|
if user == nil {
|
|
|
|
that.Display(5, "还没有绑定用户")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
that.Session("user_id", user.GetCeilInt("id"))
|
|
|
|
that.Display(0, "登录成功")
|
|
|
|
},
|
|
|
|
|
|
|
|
"create": func(that *Context) {
|
|
|
|
timestamp := that.Req.FormValue("timestamp")
|
|
|
|
sn := that.Req.FormValue("sn")
|
|
|
|
|
|
|
|
//str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))//
|
|
|
|
re, e := DePwdCode(sn)
|
|
|
|
|
|
|
|
if e != nil {
|
|
|
|
that.Display(3, "数据异常")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
reStr := string(re)
|
|
|
|
realSn := strings.Replace(reStr, ":"+timestamp, "", -1)
|
|
|
|
if len(realSn)+len(timestamp)+1 != len(reStr) {
|
|
|
|
that.Display(4, "数据验证失败")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("U盘校验", realSn)
|
|
|
|
|
|
|
|
uuser := that.Db.Get("user", "id", common.Map{"upankey": realSn})
|
|
|
|
|
|
|
|
if uuser != nil {
|
|
|
|
that.Display(4, "已经绑定了其他企业")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
phone := that.Req.FormValue("phone")
|
|
|
|
companyName := that.Req.FormValue("company_name")
|
2022-05-06 03:35:40 +00:00
|
|
|
userName := that.Req.FormValue("user_name")
|
|
|
|
|
|
|
|
if len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 {
|
|
|
|
that.Display(3, "请求参数异常")
|
|
|
|
return
|
|
|
|
}
|
2022-05-05 08:07:01 +00:00
|
|
|
//验证不成功则反馈
|
2022-05-06 03:35:40 +00:00
|
|
|
err := auth(that, phone, companyName, userName)
|
2022-05-05 08:07:01 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
that.Display(3, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
num := that.Db.Update("user", common.Map{"upankey": realSn}, common.Map{"id": that.Session("user_id").Data})
|
|
|
|
if num == 0 {
|
|
|
|
that.Display(4, "更新失败")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
that.Display(0, "绑定成功")
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|