예제 #1
0
        // GET: Authorize
        public async Task <ActionResult> Index(string code, string state)
        {
            var entity = _service.GetAuthorizeEntity(code);

            Log4NetHelper.WriteDebug("Authorize result=" + entity.ToJson());
            //var entity = new AuthorizeAccessTokenResult();
            //entity.openid = "opKrYwas6Lx4_qRK9s9-NHLV-izo";

            var user = await _userService.GetUser(entity.openid);

            if (user != null)
            {
                var userData = user.ToJson();
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Name, DateTime.Now,
                                                                                 DateTime.Now.AddMinutes(30), false, userData);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                //加密身份信息,保存至Cookie
                Response.Cookies.Add(cookie);
            }
            return(Redirect(state.UrlDecode()));
        }