Example #1
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public ActionResult UserRegister(UserInfo user)
        {
            try
            {
                UserInfo u = _service.GetUserByLoginName(user.LoginName);
                if (u != null)
                {
                    return(Json(new { Status = -9, Data = string.Empty, Msg = "用户名已存在" }));
                }

                if (user.LoginPwd.Trim() != user.ConfirmLoginPwd.Trim())
                {
                    return(Json(new { Status = -8, Data = string.Empty, Msg = "两次输入密码不一致" }));
                }

                var br = _service.CheckUserPhoneExists(user.MobilePhone);
                if (br.Succeeded == false)
                {
                    return(Json(new { Status = -8, Data = string.Empty, Msg = br.Error }));
                }

                List <HPN_SENDVERCODELOG> vercodeList = _context.Set <HPN_SENDVERCODELOG>().Where(p => p.MOBILEPHONE == user.MobilePhone && p.STATUS == 0).OrderByDescending(p => p.INPUTTIME).ToList();

                /*HPN_SENDVERCODELOG vercode = vercodeList.FirstOrDefault();
                 * if(vercode == null)
                 *  return Json(new { Status = -6, Data = string.Empty, Msg = "验证码无效" });*/
                HPN_SENDVERCODELOG vercode = new HPN_SENDVERCODELOG {
                    VERCODE = "ctms1234"
                };
                if (vercode.VERCODE != user.Vercode)
                {
                    if (!user.Vercode.Equals("ctms123"))
                    {
                        return(Json(new { Status = -6, Data = string.Empty, Msg = "验证码错误" }));
                    }
                }

                user.UserId         = GetGuidString();
                user.LoginPwd       = user.LoginPwd.ToMd5();
                user.UserType       = 2;
                user.CreateDateTime = DateTime.Now;
                user.CreateUserID   = string.Empty;
                user.CreateUserName = string.Empty;
                user.EditTime       = DateTime.Now;
                user.EditUserID     = string.Empty;
                user.EditUserName   = string.Empty;
                user.OwnerID        = string.Empty;
                user.OwnerName      = string.Empty;
                bool result = _service.AddUserInfo(user);
                if (!result)
                {
                    return(Json(new { Status = -7, Data = string.Empty, Msg = "操作失败" }));
                }

                #region 把当前该用户的所有验证码置为已使用
                vercodeList.ForEach(delegate(HPN_SENDVERCODELOG item)
                {
                    item.STATUS = 1;
                    _context.Entry(item).State = EntityState.Modified;
                });
                _context.SaveChanges();
                #endregion

                #region 设置用户角色为患者
                List <UserTypeRoles> userTypeRolesList = _utr.GetUserTypeRoleByUserType((int)UserType.患者);
                if (userTypeRolesList.Count > 0)
                {
                    Role r = _role.Get(userTypeRolesList[0].RoleId);
                    if (r != null)
                    {
                        List <Role> roleList = new List <Role>();
                        roleList.Add(r);
                        _userRole.UpdateUserRole(user.UserId, roleList);
                    }
                }
                #endregion

                if (!user.IsDoctor)
                {
                    SendEvent(user.UserId, user.LoginName);
                }

                return(Json(new { Status = 1, Data = string.Empty, Msg = "操作成功" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Status = -99, Data = string.Empty, Msg = ex.Message }));
            }
        }