/// <summary> /// Manager帐号登录 /// </summary> /// <param name="loginModel"></param> /// <returns></returns> public JsonModel<string> ManagerLogin(ManagerLoginModel loginModel) { JsonModel<string> jsonModel = new JsonModel<string>() { Success = false, ErrMsg = "登录失败", SuccessMsg = "登录成功" }; //实体验证 var validate = DotNet.Utils.DataValidate.ValidateHelper<ManagerLoginModel>.ValidateModel(loginModel); if (!validate.Pass) { jsonModel.ErrMsg = validate.ResultList.FirstOrDefault().ErrorMessage; return jsonModel; } IManagerDal managerDal = new ManagerDal(); //查询数据库中是否存在该实体 var manager = managerDal.GetEntity(new ManagerSingleParam() { LoginName = loginModel.LoginName }); if (manager == null) { jsonModel.ErrMsg = "帐号不存在"; return jsonModel; } //登录帐号加密后 string encryptPwd = DotNet.Utils.Encrypt.EncryptHelper.AESEncryString(loginModel.LoginPwd, manager.EncryptKey); if (!manager.LoginPwd.Trim().Equals(encryptPwd.Trim())) { jsonModel.ErrMsg = "密码不正确"; return jsonModel; } //验证 验证码 string imageCodeKey = BllUtility.ManagerHandler.GetImageCodeCookie(); if (!BllUtility.VerifyCodeHandler.VerifyCode(imageCodeKey, loginModel.ImageCode)) { jsonModel.ErrMsg = "验证码不正确"; return jsonModel; } //获取token,在获取的时候已经进行缓存 string token = BllUtility.ManagerHandler.AddLoginCache(manager); //写入到cookie中 BllUtility.ManagerHandler.WriteLoginCookie(token); jsonModel.Success = true; jsonModel.Data = token; return jsonModel; }
public ActionResult Logon() { ManagerLoginModel loginModel = new ManagerLoginModel() { LoginName = HttpUtility.HtmlEncode(Request["loginName"]), LoginPwd = HttpUtility.HtmlEncode(Request["loginPwd"]), ImageCode = HttpUtility.HtmlEncode(Request["imgCode"]) }; IManagerService managerService = new ManagerService(); JsonModel<string> jsonModel = managerService.ManagerLogin(loginModel); if (jsonModel.Success) { return Json(new { success=true }, JsonRequestBehavior.AllowGet); } else { return Json(new { success = false, msg = jsonModel.ErrMsg }, JsonRequestBehavior.AllowGet); } }