/// <summary> /// 验证码校验 /// 如果是邮件链接,步骤/接收人/邮箱无须传入 /// 如果是验证码,则接收人和邮箱二者必须传入一个 /// </summary> /// <param name="code"></param> /// <param name="receiveId"></param> /// <param name="email"></param> /// <returns></returns> private Result <Msg_EmailValidate> ValidateEmailCode(string code, MessageStep step, long receiveId = 0, string email = "") { Result <Msg_EmailValidate> result = new Result <Msg_EmailValidate>(); try { string strStep = step.ToString(); //链接里的验证码校验 if (receiveId == 0 && string.IsNullOrEmpty(email)) { //解密校验 string sourceData = DesTool.DesDecrypt(code); IList <string> decryptData = sourceData.SplitString("#"); strStep = decryptData[0]; email = decryptData[1]; code = decryptData[2]; } var model = DataOperateMsg <Msg_EmailValidate> .Get().Single(i => (i.ReceiveId == receiveId || i.ReceiveEmail == email) && i.Code == code && i.ValidateType == strStep); if (model == null) { throw new Exception("验证码错误"); } else { if (model.State == ValCodeState.Used.ToString()) { throw new Exception("验证码已经使用过"); } if (model.ExpiredTime < DateTime.Now) { throw new Exception("验证码已过期"); } //更新验证码 model.State = ValCodeState.Used.ToString(); DataOperateMsg <Msg_EmailValidate> .Get().Update(model); result.Data = model; result.Flag = EResultFlag.Success; } } catch (Exception ex) { result.Data = null; result.Flag = EResultFlag.Failure; result.Exception = new ExceptionEx(ex, "ValidateEmailCode"); } return(result); }
/// <summary> /// 登录 /// </summary> /// <param name="isOut"></param> /// <returns></returns> public ActionResult Login(string isOut = "") { //返回URL链接 ViewBag.autoLogin = false; Result <Base_Config> result = new Result <Base_Config>(); //加载网站配置 using (AdminClientProxy proxy = new AdminClientProxy(ProxyEx(Request))) { //result = proxy.LoadConfig(); //ViewBag.webConfig = result.Data; ViewBag.userName = ""; ViewBag.password = ""; //是否已登录 if (string.IsNullOrEmpty(isOut)) { var userInfo = HttpContext.Session[ConstStr_Session.CurrentUserEntity] as UserView; if (userInfo != null) { return(RedirectToAction("Index", "Home")); } } //是否是自动登录 HttpCookie username = Request.Cookies[ConstString.COOKIEADMINNAME]; HttpCookie password = Request.Cookies[ConstString.COOKIEADMINPWD]; if (username != null && password != null && !string.IsNullOrEmpty(username.Value) && !string.IsNullOrEmpty(password.Value)) { ViewBag.autoLogin = true; ViewBag.userName = username.Value; ViewBag.password = DesTool.DesDecrypt(password.Value); if (string.IsNullOrEmpty(isOut)) { Result <UserView> loginResult = new Result <UserView>(); loginResult = proxy.Login(username.Value, password.Value, RoleType.Admin); if (loginResult.Flag == 0) { Session[ConstStr_Session.CurrentUserEntity] = loginResult.Data; return(RedirectToAction("Index", "Home")); } } } } return(View()); }