hotime/example/app/upan.go

85 lines
1.9 KiB
Go
Raw Normal View History

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")
//验证不成功则反馈
err := auth(that, phone, companyName)
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, "绑定成功")
},
}