Example #1
0
        public ActionResult GetEmailValidateCode(LogInModel model, string ValidateCode, string Option = "administartor")
        {
            bool isValidateForSend = false;
            bool sendIsOk          = false;

            //发送验证码
            ICreateEmail sendEmail = new CreateEnail();
            IGetEntity   getEntity = new GetEntity();
            //创建四位随机码
            String validateCode = CreateValidateCode.CreateValidateCodes();

            try
            {
                if (model.Account == null || model.Password == null)
                {
                    return(JavaScript(""));
                }
                Session["Administartor"] = validateCode;
                ILoinValidate log = new LoginValidate();
                if (sendIsOk == false && log.ValidateAccount(model, option: Option))
                {
                    var entity = getEntity.GetEntityForKey(model.Account,
                                                           accountSchoolDal);
                    sendIsOk = sendEmail.SeendEmail(entity.AdministratorAccount, entity.CreateAdminitratorDetialDatas.Email,
                                                    validateCode, "登陆验证");
                }
            }
            catch (Exception e)
            {
                isValidateForSend = false;
            }
            if (sendIsOk)
            {
                var createCookie = new CreateCooks();
                //创建Cookie
                var cookie = createCookie.CreateCooki(5);
                HttpContext.Response.Cookies.Add(cookie);
                isValidateForSend = true;
            }
            if (isValidateForSend)
            {
                var str = CreateJavaScript.CreateJS(5);
                return(JavaScript(str));
            }
            return(new HttpStatusCodeResult(400));
        }
Example #2
0
        public ActionResult Login(LogInModel model, string ValidateCode, string Option = "administartor")
        {
            var sessionValidateCode = "";
            var XzPassword          = "";

            try
            {
                //登录逻辑代码
                #region 管理员登录代码

                sessionValidateCode = Session["Administartor"] == null ? "" : Session["Administartor"].ToString();
                if (!ComentBll.ExaminationEquals(ValidateCode, sessionValidateCode))
                {
                    ModelState.AddModelError("LogInError", "验证码不正确");
                    return(View());
                }
                ILoinValidate genlog = new LoginValidate();
                #region 管理员登录代码
                if (genlog.ValidateAccount(model, Option))
                {
                    var cookie = HttpContext.Request.Cookies["GetValidateTime"];
                    ComentBll.SettingExpiredCookie(HttpContext, cookie);
                    LoginModifySessionData(HttpContext);
                    Session["AdminUserLogin"] = model.Account;
                    //登录的账户与密码验证成功
                    return(Redirect("~/AdministartorsViews/Home"));
                }
                #endregion
                #endregion
            }
            catch (Exception e)
            {
                ModelState.AddModelError("LogInError", e.Message);
            }
            ModelState.AddModelError("LogInError", "账户名或密码不正确或检查您的登陆选项");
            return(View());
        }