Ejemplo n.º 1
0
        public new ActionResult Redirect(String code)
        {
            try
            {
                base.Logger.Info("Redirect Open");
                string data = HttpConnector.GetInstance().GetRequest("https://accounts.google.com/o/oauth2/token",
                                                                     HttpConnector.HttpMethod.POST,
                                                                     new Dictionary <String, Object>()
                {
                    { "code", code },
                    { "client_id", HtmlUtil.GetClientID() },
                    { "client_secret", HtmlUtil.GetClientSecret() },
                    { "redirect_uri", HtmlUtil.GetRedirectUrl() },
                    { "grant_type", "authorization_code" }
                });
                base.Logger.Info("Google account auth : " + code);
                LoginToken token = JsonConvert.DeserializeObject <LoginToken>(data);
                data = HttpConnector.GetInstance().GetRequest("https://www.googleapis.com/oauth2/v1/userinfo",
                                                              HttpConnector.HttpMethod.GET,
                                                              new Dictionary <String, Object>()
                {
                    { "access_token", token.Access_token }
                });
                base.Logger.Info("Google access_token : " + token.Access_token);
                LoginBean login = JsonConvert.DeserializeObject <LoginBean>(data);
                login.Token = token;

                String usercheck = HttpConnector.GetInstance().GetDataRequest("CheckUser.php",
                                                                              new Dictionary <String, Object>()
                {
                    { "GID", login.Id }
                });
                Session["USER_BUFFER"] = login;
                if (usercheck == null)
                {
                    base.Logger.Info("usercheck == null");
                    return(base.Redirect("/Home/ApplyConfirm"));
                }
                base.Logger.Info("Redirect -> Apply");
                return(Apply());
            }
            catch (Exception e)
            {
                base.Logger.Error(e);
                return(base.Redirect("/"));
            }
        }