Ejemplo n.º 1
0
        /// <summary>
        /// 绑定设备之前先验证设备是符合绑定的条件
        /// </summary>
        /// <param name="user"></param>
        /// <param name="imei"></param>
        /// <returns></returns>
        public static Device preBindDevice(User user, string ip = "1.1.1.1")
        {
            Device _d = DeviceLogic.GetDeviceByUserId(user.Id);

            //验证设备是否存在
            if (!string.IsNullOrWhiteSpace(user.IMEI) && _d == null)
            {
                //需先调用设备接口验证
                DeviceCheckModel dcm = DeviceData.CheckDevice(user.IMEI, user.APIUserId ?? 0);
                if (dcm.State != 0 && dcm.State != 1105)
                {
                    //  res.State = State.Falid;
                    string msg = dcm.Message;
                    //res.Message = msg;
                    //   SaveUserLog(, LogLevel.Error, user.LoginName, "preBindDevice", "绑定该设备");

                    LogQueueInfo queue = new LogQueueInfo();
                    queue.IsSaveDB = true;
                    queue.DbLog    = new WebLog
                    {
                        Content  = user.LoginName + "绑定设备失败:" + msg,
                        Created  = DateTime.Now,
                        UserId   = user.Id,
                        UserName = user.LoginName,
                        LogName  = msg,
                        LogLevel = (int)LogLevel.Sensitive,
                        ClientIp = ip,
                        Method   = "preBindDevice"
                    };
                    HWebQueue.LogQueue.Enqueue(queue);

                    // return Json(res);
                    return(null);
                }
                else
                {
                    //添加设备表
                    Device d = new Device
                    {
                        UserId         = 0,
                        IconId         = 3,
                        Created        = DateTime.Now,
                        Imei           = user.IMEI,
                        Status         = (int)Status.Normal,
                        APIDeviceId    = dcm.DeviceId,
                        APIDeviceModel = dcm.Model
                    };
                    DeviceLogic.SaveDevice(d);
                    // SaveUserLog(AuthUser.LoginName + "为" + user.LoginName + "绑定设备:" + user.IMEI, LogLevel.Error, AuthUser.LoginName, "AjaxEditUser", "绑定设备");
                    return(d);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加设备
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        public JsonResult AjaxAddDevice(string imei)
        {
            BaseResult res = new BaseResult();

            Device _d = DeviceLogic.GetDeviceByImei(imei);

            //验证设备是否存在
            if (_d == null)
            {
                //需先调用设备接口验证
                DeviceCheckModel dcm = DeviceData.CheckDevice(imei, 1);
                if (dcm.State != 0 && dcm.State != 1105)
                {
                    //  res.State = State.Falid;
                    string msg = dcm.Message;
                    res.Message = msg;
                    res.State   = State.Falid;
                    //res.Message = msg;
                    SaveUserLog(AuthUser.LoginName + "添加设备失败:" + msg, LogLevel.Error, AuthUser.LoginName, "AjaxAddDevice", "添加设备");
                    // return Json(res);;
                }
                else
                {
                    //添加设备表
                    Device d = new Device
                    {
                        UserId         = 0,
                        IconId         = 3,
                        Created        = DateTime.Now,
                        Imei           = imei,
                        Status         = (int)Status.Normal,
                        APIDeviceId    = dcm.DeviceId,
                        APIDeviceModel = dcm.Model
                    };
                    DeviceLogic.SaveDevice(d);
                    SaveUserLog(AuthUser.LoginName + "添加了设备:" + imei, LogLevel.Info, AuthUser.LoginName, "AjaxAddDevice", "添加设备");
                    res.State   = State.Success;
                    res.Message = "添加成功";
                    //return Json(res);
                }
            }
            else
            {
                res.State   = State.DeviceIn;
                res.Message = "设备已存在";
            }

            return(Json(res));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 绑定设备之前先验证设备是符合绑定的条件
        /// </summary>
        /// <param name="user"></param>
        /// <param name="imei"></param>
        /// <returns></returns>
        Device preBindDevice(User user)
        {
            Device _d = DeviceLogic.GetDeviceByUserId(user.Id);

            //验证设备是否存在
            if (!string.IsNullOrWhiteSpace(user.IMEI) && _d == null)
            {
                //需先调用设备接口验证
                DeviceCheckModel dcm = DeviceData.CheckDevice(user.IMEI, user.APIUserId ?? 0);
                if (dcm.State != 0 && dcm.State != 1105)
                {
                    //  res.State = State.Falid;
                    string msg = dcm.Message;
                    //res.Message = msg;
                    SaveUserLog(AuthUser.LoginName + "绑定设备失败:" + msg, LogLevel.Error, AuthUser.LoginName, "preBindDevice", "绑定该设备");
                    // return Json(res);
                    return(null);
                }
                else
                {
                    //添加设备表
                    Device d = new Device
                    {
                        UserId         = 0,
                        IconId         = 3,
                        Created        = DateTime.Now,
                        Imei           = user.IMEI,
                        Status         = (int)Status.Normal,
                        APIDeviceId    = dcm.DeviceId,
                        APIDeviceModel = dcm.Model
                    };
                    DeviceLogic.SaveDevice(d);
                    // SaveUserLog(AuthUser.LoginName + "为" + user.LoginName + "绑定设备:" + user.IMEI, LogLevel.Error, AuthUser.LoginName, "AjaxEditUser", "绑定设备");
                    return(d);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 注册提交
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public JsonResult AjaxRegister(RegisterParam param)
        {
            BaseResult res        = new BaseResult();
            bool       isRegister = true;//是否注册成功

            //检查用户是否存在
            if (UserLogic.ExistsLoginName(param.LoginName))
            {
                res.State   = State.ExistsLoginName;
                res.Message = "用户名已存在!";
                isRegister  = false;
            }
            else if (UserLogic.ExistsPhoneNum(param.Phone))
            {
                res.State   = State.NumIsRegister;
                res.Message = "手机号码已被注册!";
                isRegister  = false;
            }

            if (isRegister)
            {
                //先去设备平台注册
                RegisterModel rm = UserData.Register(param.LoginName, param.Pwd, param.Phone, param.IMEI);
                if (rm.User == null)
                {//注册失败直接返回
                    res.State   = State.Falid;
                    res.Message = rm.Message;
                    isRegister  = false;
                    return(Json(res));
                }

                User _u = new User();
                _u.UserName     = param.LoginName;
                _u.LoginName    = param.LoginName;
                _u.Pwd          = Encryption.AESEncrypt(param.Pwd);
                _u.RegisterTime = DateTime.Now;
                _u.PhoneNum     = param.Phone;
                _u.Status       = (int)Status.Normal;
                _u.HeadImgId    = ConstVal.DefaultHeadImgId;
                _u.UserTypeId   = 4;//居民
                _u.APIUserId    = rm.User.UserId;
                _u.UserInfo     = "";
                _u.Sex          = 1;
                int i = UserLogic.SaveUser(_u);

                if (i > 0)
                {
                    res.State   = State.Success;
                    res.Message = "注册成功!";
                    if (!string.IsNullOrWhiteSpace(param.IMEI))
                    {
                        //检查设备
                        DeviceCheckModel dcm = DeviceData.CheckDevice(param.IMEI, _u.APIUserId ?? 0);

                        //添加设备表
                        Device d = new Device
                        {
                            UserId         = _u.Id,
                            IconId         = 3,
                            Created        = DateTime.Now,
                            Imei           = param.IMEI,
                            Status         = (int)Status.Normal,
                            APIDeviceId    = dcm.DeviceId,
                            APIDeviceModel = dcm.Model
                        };
                        DeviceLogic.SaveDevice(d);
                    }
                }
                else
                {
                    res.State   = State.Falid;
                    res.Message = "注册失败!";
                    isRegister  = false;
                }
            }
            //记录操作日志
            SaveUserLog("注册账号" + (isRegister ? "成功" : "失败") + ":" + res.Message, LogLevel.Info, param.LoginName, "AjaxRegister", "注册账号");
            return(Json(res));
        }