Esempio n. 1
0
        public ActionResult SetValidateEmail()
        {
            string emailcode = Request["emailcode"];
            bool   state     = true;
            string message   = string.Empty;

            try
            {
                state = UserService.CheckEamilValidate(emailcode, sessionModel.User.UserId,
                                                       sessionModel.EmailValidateCode);
                if (state)
                {
                    UserService.ChangeEmailValidateStatus(sessionModel.User.UserId, EmailValide.Valide);
                }
                sessionModel.EmailValidateCode = string.Empty;
                CacheResolver.SetCache(SessionId.GetSessionId(), sessionModel);
                message = state ? "邮箱验证成功" : "邮箱验证失败";
            }
            catch (EmailValideCodeException e)
            {
                state   = false;
                message = e.Message;
            }
            return(Content(JsonString.GetString(new { state = state, message = message })));
        }
Esempio n. 2
0
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string       key   = Request["sessionid"];
            SessionModel model = null;
            bool         state = false;

            try
            {
                model = CacheResolver.GetCache(key) as SessionModel;
                if (null != model)
                {
                    state = true;
                }
            }
            catch (ArgumentNullException)
            {
                //没有缓存键,第一次登陆这个网站
                key   = Guid.NewGuid().ToString("N");
                model = new SessionModel();
            }
            catch (NullReferenceException)
            {
                model = new SessionModel();
            }
            if (!state)
            {
                //开始重新写入
                CacheResolver.SetCache(key, model);
                //开始吧key写入到cookie中去
                HttpContext.Current.Response.Cookies.Add(new HttpCookie("sessionid", key));
            }
        }
Esempio n. 3
0
        public ActionResult GetValidateCode()
        {
            //有可能会用户刷新验证码,所以我们要消除原来的验证码
            CacheResolver.DeleteCache(ValidateCodeId.GetValidateCodeId());
            ValidateCode code      = new ValidateCode();
            string       codevalue = code.CreateValidateCode(6);//6位长度的值

            //开始存入缓存服务器
            CacheResolver.SetCache(ValidateCodeId.GetValidateCodeId(), codevalue);
            return(File(code.CreateValidateGraphic(codevalue), @"image/jpeg"));
        }
Esempio n. 4
0
 public void SetCurrentUser(string sessionid, SessionModel sessionModel)
 {
     if (string.IsNullOrEmpty(sessionid) || null == sessionModel)
     {
         throw new ArgumentNullException("用户SessionId或者用户对象为空", innerException: null);
     }
     try
     {
         CacheResolver.SetCache(sessionid, sessionModel);
     }
     catch (CacheException)
     {
         //写入用户状态失败了
         throw new UserException("用户信息写入失败");
     }
 }
Esempio n. 5
0
        public ActionResult ValidateEmail()
        {
            bool state = UserService.IsEmailValidated(sessionModel.User.UserId);

            if (state)
            {
                return(Content("邮箱已经被验证了"));
            }
            //开始邮箱验证工作,首先产生验证码,然后存入SessionModel中去
            ValidateCode codeobj   = new ValidateCode();
            string       emailcode = codeobj.CreateValidateCode(6);

            //更改缓存对象,同时我们数据库也要进行一次更改,用户完成了验证之后,记得要进行删除
            sessionModel.EmailValidateCode = emailcode;
            //缓存服务器保存
            CacheResolver.SetCache(SessionId.GetSessionId(), sessionModel);
            UserService.SetUserEmailValidateCode(sessionModel.User.UserId, emailcode);
            //设置完数据库之后,我们就要进行一次邮件的发送了
            UserService.SendValidateEmail(UserService.GetUserEmail(sessionModel.User.UserId), emailcode);
            return(Content("验证邮件已经发送,注意接收"));
        }