Exemple #1
0
        //注销
        public ActionResult Logout()
        {
            string     result = "no";
            HttpCookie ck     = Request.Cookies["LData"];

            ck.Expires = DateTime.Now.AddDays(-1);
            if (MemcacheHelper.Delete(ck.Value))
            {
                result = "ok";
            }
            return(Content(result));
        }
        public ActionResult LoginOut()
        {
            var cookie    = Request.Cookies[Keys.SessionId];
            var sessionid = cookie?.Value;

            if (sessionid != null)
            {
                MemcacheHelper.Delete(sessionid);
                cookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(cookie);
            }
            return(Redirect("/"));
        }
        public JsonResult ValidEmail(string confirmatio)
        {
            var data = new { code = 1, msg = "验证失败,请重试!", error = "" };

            if (!string.IsNullOrEmpty(confirmatio))
            {
                var obj = MemcacheHelper.Get(confirmatio);
                if (obj != null)
                {
                    var user = SerializerHelper.DeserializeToObject <User>(obj.ToString());
                    if (user != null)
                    {
                        // 邮箱验证成功
                        user.IsValid = true;
                        userService.EditEntity(user);
                        if (userService.SaveChanges())
                        {
                            MemcacheHelper.Delete(confirmatio);
                            var sessionid = Guid.NewGuid().ToString();
                            MemcacheHelper.Set(sessionid, SerializerHelper.SerializeToString(user.ToAccount()), DateTime.Now.AddHours(1));
                            Response.Cookies[Keys.SessionId].Value   = sessionid;
                            Response.Cookies[Keys.SessionId].Expires = DateTime.Now.AddHours(1);
                            data = new { code = 0, msg = "成功绑定邮箱。", error = "" };
                        }
                    }
                    else
                    {
                        data = new { code = 1, msg = "验证失败,请重试!", error = "用户不存在。" };
                    }
                }
                else
                {
                    data = new { code = 1, msg = "验证失败,请重试!", error = "验证信息过期。" };
                }
            }
            return(Json(data));
        }