Files
nbi_alarm/handle/api/req_cmca_login_alarm.go
2023-08-24 09:46:39 +08:00

85 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package api
import (
"omc/core"
"omc/core/manage"
"omc/core/parse"
"omc/handle/service"
"github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/zlog"
"github.com/aceld/zinx/znet"
)
var ReqCMCALoginAlarmMsgID uint32 = 11
var ReqCMCALoginAlarmMsgType uint32 = 11
var ReqCMCALoginAlarmMsgName string = "reqCMCALoginAlarm"
// reqCMCALoginAlarm CMCA认证方式登录
type ReqCMCALoginAlarm struct {
znet.BaseRouter
}
func (*ReqCMCALoginAlarm) Handle(request ziface.IRequest) {
// 登录消息处理
body, err := parse.RequestBodyDecode(request, []string{"user", "key", "cert", "type"})
username := body.Data["user"]
key := body.Data["key"]
cert := body.Data["cert"]
tp := body.Data["type"]
if err != nil || username == "" || cert == "" || key == "" || tp == "" {
zlog.Ins().ErrorF("inlaid message body %s", err.Error())
request.GetConnection().SendMsg(ReqLoginAlarmMsgType, core.ResultError(ReqLoginAlarmMsgName, err.Error(), ""))
return
}
// 获取当前请求的通道
m := manage.GetManager(request.GetConnection().GetName())
if m == nil {
zlog.Ins().ErrorF("server internal error")
request.GetConnection().SendMsg(ReqLoginAlarmMsgType, core.ResultError(ReqLoginAlarmMsgName, "server internal error", ""))
return
}
uid, err := request.GetConnection().GetProperty("UID")
if err != nil {
zlog.Ins().ErrorF("GetProperty UID error %s", err)
request.GetConnection().Stop()
return
}
// 得到连接实例的随机码
seqNo := m.GetUserByPID(uid.(string)).SeqNo
content := username + ":" + seqNo
// 检查判断是否对应随机码
if err := service.CMCALogin(username, cert, content, key); err != nil {
zlog.Ins().ErrorF("LoginFail %s", err)
request.GetConnection().SendMsg(ReqLoginAlarmMsgType, core.Result(ReqLoginAlarmMsgName, map[string]string{
"result": "autherror",
"resDesc": err.Error()[:30],
}))
// 已登录的登录错误超过3次,断开连接
if uid != nil || uid != "" {
isClose, _ := m.LoginFail(uid.(string))
if isClose {
request.GetConnection().Stop()
return
}
}
return
}
// manager 用户登录更新
err = m.LoginSuccess(uid.(string), username, tp)
if err != nil {
zlog.Ins().ErrorF("manager:%s", err)
request.GetConnection().SendMsg(ReqLoginAlarmMsgType, core.Result(ReqLoginAlarmMsgName, map[string]string{
"result": "autherror",
"resDesc": err.Error()[:30],
}))
return
}
zlog.Ins().InfoF("user login loginSuccess,username:%s, type:%s, channel:%s", username, tp, request.GetConnection().GetName())
request.GetConnection().SendMsg(ReqLoginAlarmMsgType, core.ResultSuccess(ReqLoginAlarmMsgName, "ok", ""))
}