Ejemplo n.º 1
0
 public EdgeServerResponse(HttpStatusCode code, LogonResult logon)
 {
     status = code; result = logon;
 }
Ejemplo n.º 2
0
        public static EdgeServerResponse ProcessLogonData(object payload)
        {
            LogonData data = new LogonData();

            try
            {
                data = JsonConvert.DeserializeObject<LogonData>(payload.ToString());
                //LogHelper.WriteInfoLog(typeof(LogonData), "收到登录数据,用户名为" + data.username);
            }
            catch (Exception)
            {
                return new EdgeServerResponse(HttpStatusCode.BadRequest);
            }

            //检查用户名密码是否正确
            LogonResult result = new LogonResult();
            try
            {

                var user = UserBLL.GetUserByUsername(data.username);
                if (user == null)
                {
                    result.result = 1;
                    LogHelper.WriteInfoLog(typeof(LogonData), "当前登录用户不存在,用户名为" + data.username);
                }
                else
                {

                    if (user.Password == data.password)
                    {
                        result.result = 0; //登录成功
                        //检查要登录的该设备是否已经在系统中存在,若存在,则返回其TerminalID,否则生成新的TerminalID
                        var t = TerminalBLL.GetTerminal(data);
                        string Name = "默认策略组";

                        #region 登录成功 TerminalID 操作
                        if (t == null)
                        {
                            Terminal newt = new Terminal();
                            newt.UserId = user.ID;
                            newt.UserGroup = UserBLL.GetUserGroupById(user.ID);
                            newt.User = data.username;
                            newt.IMEI = data.imei;
                            newt.PhoneNumber = data.phoneNumber;
                            newt.AppID = data.appID;
                            newt.DeviceSN = data.deviceSN;
                            newt.Status = 1;
                            StrategyGroup groupModel = StrategyGroupBLL.GetStrategyGroupByName(Name);
                            if (groupModel != null)
                            {
                                newt.policyID = groupModel.ID;
                            }
                            string id = TerminalBLL.Instance.AddAndReturnID(newt);
                            if (id != string.Empty)
                            {
                                result.terminalID = id;
                                if (user.Terminals == null)
                                    user.Terminals = new MongoDB.Bson.BsonArray();
                                user.Terminals.Add(id);
                                UserBLL.Instance.Update(user.ID, user);
                            }
                        }
                        else if (t.User == data.username)
                        {
                            result.terminalID = t.ID;
                        }
                        else
                        {
                            result.result = 4;
                        }
                        #endregion

                        #region 发送策略信息

                        //StrategyItemBLL.SendStrategyItemMsg(result.terminalID);
                        #endregion

                    }
                    else
                    {
                        result.result = 2;
                        LogHelper.WriteInfoLog(typeof(LogonData), "当前登录用户密码错误,用户名为" + data.username);
                    }
                }

            }
            catch (Exception)
            {
                result.result = 3;
            }
            return new EdgeServerResponse(HttpStatusCode.OK, result);
        }