Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // страница всегда знает куда нужно отправить в случае если авторизация не требуется
            string redirectIfNoNeed = "Page1.aspx?a=1&b=2&action=return";

            var userId = Session["GapiUserId"] as string;

            // проверка userId
            if (string.IsNullOrEmpty(userId))
            {
                throw new Exception("Не указан userId");
            }

            // пробую авторизовать
            var result = new GooCalV3Integrator().Authorize(Request, userId);

            if (result is AuthorizationCodeWebApp.AuthResult)
            {
                // нужно авторизоваться, проверяю
                Response.Redirect((result as AuthorizationCodeWebApp.AuthResult).RedirectUri, true);
            }
            else
            {
                // авторизация прошла или произошла ошибка, отправляю назад
                Response.Redirect(redirectIfNoNeed, true);
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var newUserId = (IsPostBack && !string.IsNullOrEmpty(AccountNameInput.Text)) ? AccountNameInput.Text : null;
            var code      = Request["code"];
            var error     = Request["error"];
            var action    = Request["action"];

            if (newUserId != null)
            {
                Session["GapiUserId"] = newUserId;
            }

            if (newUserId != null || code != null || error != null || action != null)
            {
                GooCalIntegrator integra = new GooCalV3Integrator();
                var result = integra.Authorize(Request, Session["GapiUserId"] as string);

                // проверяю обработку
                if (result is AuthorizationCodeWebApp.AuthResult)
                {
                    var authResult = result as AuthorizationCodeWebApp.AuthResult;
                    // нужно выполнить переход на этот url
                    Response.Redirect(authResult.RedirectUri);
                }
                else if (result is string && (result as string) == "OK")
                {
                    // все ок, пользователь авторизовался
                    // запоминаю объект интегратора
                    Session["GooCalIntegrator"] = integra;
                    // перехожу на следующую страницу
                    Response.Redirect("Page2.aspx");
                }
                else if (result is Task <string> )
                {
                    //var task = result as Task<string>;
                    // авторизация прошла, нужно сейчас просто обновить страницу и снова авторизоваться
                    Response.Redirect(Request.Url.AbsolutePath + "?action=check");
                }
                else if (result is UserRejectException)
                {
                    // пользователь отвергнул приглашение
                    RenderException(new Exception("Пользователь отвергнул приглашение", result as UserRejectException));
                }
                else if (result is Exception)
                {
                    // произошла другая ошибка при обращении к сервису Google Api
                    RenderException(result as Exception);
                }
                else
                {
                    // случилось непредвиденное
                    RenderException(new Exception("Случилось непредвиденное", new Exception("GooCalIntegrator.Authorize вернул другой тип результата")));
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var newUserId = (IsPostBack && !string.IsNullOrEmpty(txtAccountName.Text)) ? txtAccountName.Text : null;
            var code = Request["code"];
            var error = Request["error"];
            var action = Request["action"];

            if (newUserId != null)
            {
                Session["GapiUserId"] = newUserId;
            }

            if (newUserId != null || code != null || error != null || action != null)
            {
                GooCalIntegrator integra = new GooCalV3Integrator();
                var result = integra.Authorize(Request, Session["GapiUserId"] as string);

                // Check processing
                if (result is AuthorizationCodeWebApp.AuthResult)
                {
                    var authResult = result as AuthorizationCodeWebApp.AuthResult;
                    // You need to go to this url
                    Response.Redirect(authResult.RedirectUri);
                }
                else if (result is string && (result as string) == "OK")
                {
                    // All ok, user authorized
                    // I remember the integrator object
                    Session["GooCalIntegrator"] = integra;
                    // I turn to the next page
                    Response.Redirect("Page2.aspx");
                }
                else if (result is Task<string>)
                {
                    //var task = result as Task<string>;
                    // Authorization has passed, you just need to update the page and log in again
                    Response.Redirect(Request.Url.AbsolutePath + "?action=check");
                }
                else if (result is UserRejectException)
                {
                    // пользователь отвергнул приглашение
                    RenderException(new Exception("Пользователь отвергнул приглашение", result as UserRejectException));
                }
                else if (result is Exception)
                {
                    // произошла другая ошибка при обращении к сервису Google Api
                    RenderException(result as Exception);
                }
                else
                {
                    // случилось непредвиденное
                    RenderException(new Exception("Случилось непредвиденное", new Exception("GooCalIntegrator.Authorize вернул другой тип результата")));
                }
            }
        }
Beispiel #4
0
 static void Main(string[] args)
 {
     var i = new GooCalV3Integrator();
 }