public ActionResult AdministartorsRegisterDetials(CreateAdminitratorDetialData cre)
        {
            var or = Session["admin"] is SchoolAdministrator;
            SchoolAdministrator schoolAdministrator = null;

            if (or == false)
            {
                ModelState.AddModelError("RegisterError", "出现了意外的错误");
                return(View("AdministartorsRegister"));
            }
            schoolAdministrator = Session["admin"] as SchoolAdministrator;
            bool resiterIS = true;

            try
            {
                re.RegisterBll(schoolAdministrator, cre, dal);
                //用户注册后发送一个带QueryString的URL给校长
                var rightUrl = Url.Action("SeendValidateCode");
                var LeftUrl  = Request.Url.GetLeftPart(UriPartial.Authority) + rightUrl;
                try
                {
                    var entity = dal.GetEntity(schoolAdministrator.AdministratorAccount);
                    LeftUrl = LeftUrl + "?account=" + entity.AdministratorAccount + "&email=" + entity.CreateAdminitratorDetialDatas.Email;
                    ICreateEmail createEmail = new CreateEnail();
                    bool         Ok          = createEmail.SeendEmail(LeftUrl, entity.CreateAdminitratorDetialDatas.Email, entity.CreateAdminitratorDetialDatas.Message, entity.AdministratorAccount, entity.CreateAdminitratorDetialDatas.AdministratorAuthority);
                    if (!Ok)
                    {
                        throw new ArgumentException("邮件发送失败");
                    }
                }
                catch (Exception e)
                {
                    ErrorDatabase error = new ErrorDatabase()
                    {
                        DateTime     = DateTime.Now,
                        ErrorMessage = e.StackTrace.ToString()
                    };
                    errorDal.AddEntity(error);
                    resiterIS = false;
                    ModelState.AddModelError("RegisterError", "验证功能暂时失败请您后续登陆网站发送验证");
                }
            }
            catch (Exception e)
            {
                ErrorDatabase error = new ErrorDatabase()
                {
                    DateTime     = DateTime.Now,
                    ErrorMessage = e.StackTrace.ToString()
                };
                errorDal.AddEntity(error);
                resiterIS = false;
                ModelState.AddModelError("RegisterError", "您输入的邮箱已被占用");
            }
            if (resiterIS)
            {
                return(Content("完成"));
            }
            return(View("AdministartorsRegister"));
        }
示例#2
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));
        }