コード例 #1
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }

            if (model.VerifyCode != (string)TempData["verifyCode"])
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "验证码错误"
                }));
            }

            bool result = AdminUserService.CheckLogin(model.PhoneNum, model.Password);

            if (result)
            {
                //将userId存放到session中
                Session["LoginUserId"] = AdminUserService.GetByPhoneNum(model.PhoneNum).Id;
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名或者密码错误"
                }));
            }
        }
コード例 #2
0
        public ActionResult Add(AdminUserAddNewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }

            var user = AdminUserService.GetByPhoneNum(model.PhoneNum);

            if (user != null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "该手机号已被注册"
                }));
            }
            //发现在service里面也判断了一次手机是否注册,感觉越早判断越好,service那个就没必要了
            //TODO:这里应该用事务
            long adminUserId = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.PassWord, model.Email, model.CityId);

            RoleService.AddRoleIds(adminUserId, model.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
コード例 #3
0
        public ActionResult Login(UserLoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }

            var user = UserService.GetbyPhoneNum(model.PhoneNum);

            //1.判断用户是否存在
            if (user == null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "用户不存在或密码错误"
                }));
            }
            //2.判断用户是否被锁定
            if (UserService.IsLocked(user.Id))
            {
                TimeSpan?leftTimeSpan = TimeSpan.FromMinutes(30) - (DateTime.Now - user.LastLoginErrorDateTime);
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "用户已被锁定,请" + (int)leftTimeSpan.Value.TotalMinutes + "分钟后重试"
                }));
            }
            //3,判断密码
            if (UserService.CheckLogin(model.PhoneNum, model.Password))
            {
                //一旦登录成功,就重置所有登录错误信息,避免影响下一次登录
                UserService.ResetLoginError(user.Id);
                //把当前登录用户信息存入Session
                Session["UserId"] = user.Id;
                Session["CityId"] = user.CityId;
                return(Json(new AjaxResult()
                {
                    Status = "ok"
                }));
            }
            else
            {
                UserService.IncrLoginError(user.Id);
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "用户不存在或密码错误"
                }));
            }
        }
コード例 #4
0
        public ActionResult MakeAppointment(HouseAppointmentModel model)
        {
            if (!ModelState.IsValid)
            {
                string msg = MVCHelper.GetValidMesg(ModelState);
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = msg
                }));
            }
            long?userId = FrontHelper.GetUserId(HttpContext);

            HouseAppointmentService.AddNew(userId, model.Name, model.PhoneNum, model.HouseId, model.VisitDate);
            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }
コード例 #5
0
        public ActionResult Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }
            //检查一下注册的时候手机号是不是被改掉了,防止漏洞
            string serverPhone = TempData["RegPhoneNum"].ToString();

            if (serverPhone != model.PhoneNum)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "手机号不一致,请重试"
                }));
            }
            if (!TempData["SMSCode"].ToString().Contains(model.SmsCode))
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "短信验证码错误"
                }));
            }
            var user = UserService.GetbyPhoneNum(model.PhoneNum);

            if (user != null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "手机号已被注册"
                }));
            }

            UserService.AddNew(model.PhoneNum, model.Password);
            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
コード例 #6
0
        public ActionResult Add(RoleAddNewModel model)
        {
            //这两个操作应该放到事务中,以免造成只成功了一个
            //检查model验证是否通过
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }
            long roleId = RoleService.AddNew(model.Name);

            PermissionService.AddPermIds(roleId, model.PermissionIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }