Esempio n. 1
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <param name="e_mail"></param>
        /// <param name="tel"></param>
        /// <param name="sex"></param>
        /// <param name="post"></param>
        /// <param name="isAble"></param>
        /// <param name="isChangePwd"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public JsonMessage Insert(string userId, string userName, string e_mail, string tel, bool sex, string post, bool isAble, bool isChangePwd, string desc)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                DataTable dt = _userRep.GetById(userId);
                if (dt.Rows.Count > 0)
                {
                    throw new CustomException(0, "该用户已存在");//该用户已存在
                }

                string       newPwd = "123456";
                SysUserModel model  = new SysUserModel();
                model.USER_CODE   = userId;
                model.USER_NAME   = userName;
                model.USER_PWD    = MD5Cryption.MD5(newPwd);
                model.USER_EMAIL  = e_mail;
                model.USER_TEL    = tel;
                model.USER_SEX    = sex ? 1 : 0;
                model.USER_POST   = post;
                model.IS_ABLED    = isAble ? 1 : 0;
                model.IS_C_PWD    = isChangePwd ? 1 : 0;
                model.QR_CODE     = DESCryption.Encrypt(userId + newPwd);
                model.USER_DESC   = desc;
                model.CREATE_USER = UserID;
                model.LM_USER     = UserID;

                result  = _userRep.Insert(model);
                jsonMsg = ServiceResult.Message(result, "添加用户成功");
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
                WriteSystemException(ex, this.GetType(), OPT_MODEL, "添加用户失败");
            }

            //写入log
            WriteSystemLog(jsonMsg, CREATE, OPT_MODEL, "添加用户");

            return(jsonMsg);
        }
Esempio n. 2
0
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <param name="e_mail"></param>
        /// <param name="tel"></param>
        /// <param name="sex"></param>
        /// <param name="post"></param>
        /// <param name="resetPwd"></param>
        /// <param name="qrCode"></param>
        /// <param name="isAble"></param>
        /// <param name="isChangePwd"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public JsonMessage Edit(string userId, string userName, string e_mail, string tel, bool sex, string post, bool resetPwd, bool qrCode, bool isAble, bool isChangePwd, string desc)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                DataTable dt = _userRep.GetById(userId);
                if (ValidateHelper.IsDataTableNotData(dt))
                {
                    throw new CustomException(0, "该用户不存在");
                }

                string       newPwd = "123456";
                SysUserModel model  = new SysUserModel();
                model.USER_CODE  = userId;
                model.USER_NAME  = userName;
                model.USER_PWD   = resetPwd ? MD5Cryption.MD5(newPwd) : dt.Rows[0]["USER_PWD"].ToString();
                model.USER_EMAIL = e_mail;
                model.USER_TEL   = tel;
                model.USER_SEX   = sex ? 1 : 0;
                model.USER_POST  = post;
                model.IS_ABLED   = isAble ? 1 : 0;
                model.IS_C_PWD   = isChangePwd ? 1 : 0;
                model.QR_CODE    = qrCode ? DESCryption.Encrypt(userId + newPwd) : dt.Rows[0]["QR_CODE"].ToString();
                model.USER_DESC  = desc;
                model.LM_USER    = UserID;
                result           = _userRep.Edit(model);

                jsonMsg = ServiceResult.Message(result, "修改用户成功");
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
                WriteSystemException(ex, this.GetType(), OPT_MODEL, "修改用户失败");
            }

            //写入log
            WriteSystemLog(jsonMsg, CREATE, OPT_MODEL, "修改用户");

            return(jsonMsg);
        }
        public JsonResult EditPassword(string oldPwd, string newPwd, string newPwdOk, bool isQR)
        {
            JsonMessage jsonMsg = _userApp.EditPassword(UserId, MD5Cryption.MD5(oldPwd), MD5Cryption.MD5(newPwd), MD5Cryption.MD5(newPwdOk), isQR, MD5Cryption.MD5(UserId + newPwd));

            if (jsonMsg.type == 1)
            {
                FormsIdentity             id      = (FormsIdentity)User.Identity;
                FormsAuthenticationTicket tickets = id.Ticket;
                SysUserModel userFromDB           = _userApp.GetById(UserId);
                FormsAuthentication.SignOut();
                AccountModel model = new AccountModel();
                model.UserCode = userFromDB.USER_CODE;
                model.LoginNo  = userFromDB.USER_CODE;
                model.UserName = userFromDB.USER_NAME;
                model.QRCode   = userFromDB.QR_CODE;

                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket
                                                   (
                    2,
                    userFromDB.USER_CODE,
                    DateTime.Now,
                    tickets.Expiration,
                    false,
                    new JavaScriptSerializer().Serialize(model)             //序列化新的用户对象
                                                   );
                string     encTicket = FormsAuthentication.Encrypt(ticket); //加密
                HttpCookie cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                if (ticket.Expiration != new DateTime(9999, 12, 31))        //不是默认时间才设置过期时间,否则会话cookie
                {
                    cookie.Expires = tickets.Expiration;
                }
                Response.Cookies.Add(cookie);  //写入cookie
            }

            return(Json(jsonMsg, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="model">返回用户信息</param>
        /// <param name="user_id">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public JsonMessage Login(ref AccountModel model, string user_id, string pwd)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                if (ValidateHelper.IsNullOrEmpty(StringHelper.Trim(user_id)))
                {
                    throw new CustomException(0, "用户名不能为空");
                }
                if (ValidateHelper.IsNullOrEmpty(pwd))
                {
                    throw new CustomException(0, "密码不能为空");
                }

                //UserID = userId;
                DataTable            dt   = _userRep.Login(user_id, MD5Cryption.MD5(pwd));
                IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt);
                if (list.Count < 1)
                {
                    throw new CustomException(2, "用户名或密码错误");//用户名或密码错误
                }
                if (!ConverHelper.ToBool(list[0].IS_ABLED))
                {
                    throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用
                }
                model.UserCode = list[0].USER_CODE;
                model.UserName = list[0].USER_NAME;
                model.LoginNo  = list[0].USER_CODE;
                model.QRCode   = list[0].QR_CODE;
                model.DeptCode = list[0].DEPT_CODE;

                jsonMsg = ServiceResult.Message(1, "登录成功");

                SessionHelper.SetSession("Account", model);

                CookieHelper.SetCookie("Account", DESCryption.Encrypt(ConverHelper.ToJson(model)));
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
            }
            //写入log
            SysLogLoginModel log = new SysLogLoginModel();

            log.LOGIN_ID      = GuidHelper.GenerateComb().ToString();
            log.USER_CODE     = user_id;
            log.USER_PWD      = MD5Cryption.MD5(pwd);
            log.USER_PWD_LAWS = pwd;
            log.LOGIN_IP      = NetHelper.GetUserIp;
            log.LOGIN_RESULT  = jsonMsg.type == 1 ? "SUCCESS" : "FAIL";
            log.LOGIN_MSG     = jsonMsg.message;
            _loglRep.Insert(log);

            return(jsonMsg);
        }
Esempio n. 5
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="model">返回用户信息</param>
        /// <param name="user_id">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public JsonMessage Login(string user_id, string pwd, string qr_code)
        {
            JsonMessage jsonMsg = new JsonMessage(); //返回Json
            int         result  = -1;                //类型(成功 、失败)

            try
            {
                if (ValidateHelper.IsNullOrEmpty(user_id) && ValidateHelper.IsNullOrEmpty(qr_code))
                {
                    throw new CustomException(0, "用户名和二维码不能同时为空");
                }
                if (ValidateHelper.IsNullOrEmpty(pwd) && ValidateHelper.IsNullOrEmpty(qr_code))
                {
                    throw new CustomException(0, "密码和二维码不能同时为空");
                }
                DataTable dt;
                if (ValidateHelper.IsNullOrEmpty(qr_code))
                {
                    dt = _userRep.Login(user_id, pwd);
                }
                else
                {
                    dt = _userRep.Login(qr_code);
                }
                IList <SysUserModel> list = ConverHelper.ToList <SysUserModel>(dt);
                if (list.Count < 1)
                {
                    if (ValidateHelper.IsNullOrEmpty(qr_code))
                    {
                        throw new CustomException(2, "用户名或密码错误");//用户名或密码错误
                    }
                    else
                    {
                        throw new CustomException(2, "二维码不正确");//二维码不正确
                    }
                }
                if (!ConverHelper.ToBool(list[0].IS_ABLED))
                {
                    throw new CustomException(3, "账号已被禁用,请联系系统管理员");//账号是否被禁用
                }

                jsonMsg = ServiceResult.Message(1, "登录成功", list[0]);
            }
            catch (CustomException ex)
            {
                jsonMsg = ServiceResult.Message(ex.ResultFlag, ex.Message);
            }
            catch (Exception ex)
            {
                jsonMsg = ServiceResult.Message(-1, ex.Message);
            }

            //写入log
            SysLogLoginModel log = new SysLogLoginModel();

            log.LOGIN_ID      = GuidHelper.GenerateComb().ToString();
            log.USER_CODE     = user_id;
            log.USER_PWD      = MD5Cryption.MD5(pwd);
            log.USER_PWD_LAWS = ValidateHelper.IsNullOrEmpty(user_id) ? qr_code : pwd;
            log.LOGIN_IP      = NetHelper.GetUserIp;
            log.LOGIN_RESULT  = jsonMsg.type == 1 ? "SUCCESS" : "FAIL";
            log.LOGIN_MSG     = jsonMsg.message;
            _loglRep.Insert(log);

            return(jsonMsg);
        }