Ejemplo n.º 1
0
        public async Task <IActionResult> Begin(int prNumber, CancellationToken cancellationToken)
        {
            if (await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false) != null)
            {
                return(RedirectToAction("ReviewPullRequest", "PullRequest", new { number = prNumber }));
            }
            var redirectURI = new Uri(generalConfiguration.RootURL, Url.Action(nameof(Complete), prNumber));

            return(Redirect(String.Concat(gitHubManager.GetAuthorizationURL(redirectURI).ToString())));
        }
        public async Task <IActionResult> Begin(int prNumber, CancellationToken cancellationToken)
        {
            if (await gitHubManager.CheckAuthorization(Request.Cookies, cancellationToken).ConfigureAwait(false) != null)
            {
                return(RedirectToAction("ReviewPullRequest", "PullRequest", new { number = prNumber }));
            }

            var redirectURI = Url.Action(nameof(Complete), new { prNumber });

            return(Redirect(gitHubManager.GetAuthorizationURL(new Uri(String.Format(CultureInfo.InvariantCulture, "https://{0}{1}", Request.Host, redirectURI))).ToString()));
        }
        public async Task <IActionResult> Index(long repositoryId, CancellationToken cancellationToken)
        {
            try
            {
                var loadRepoTask = gitHubManager.LoadInstallation(repositoryId, cancellationToken);
                var authedTask   = gitHubManager.CheckAuthorization(repositoryId, Request.Cookies, cancellationToken);
                await loadRepoTask.ConfigureAwait(false);

                ViewBag.ConfiguredDme = await databaseContext.InstallationRepositories.Where(x => x.Id == repositoryId).Select(x => x.TargetDme).ToAsyncEnumerable().First(cancellationToken).ConfigureAwait(false);

                var authLevel = await authedTask.ConfigureAwait(false);

                ViewBag.SignIn = stringLocalizer[authLevel == AuthenticationLevel.LoggedOut ? "Sign-In with GitHub" : "Log Out"];
                if (authLevel == AuthenticationLevel.LoggedOut)
                {
                    ViewBag.SignInHref = gitHubManager.GetAuthorizationURL(new Uri(String.Concat(generalConfiguration.ApplicationPrefix, '/', Route, '/', nameof(Authorize))), repositoryId.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    ViewBag.SignInHref = Url.Action(nameof(SignOut), new { repositoryId });
                }

                ViewBag.AuthLevel  = authLevel;
                ViewBag.Title      = stringLocalizer["DME Configuration"];
                ViewBag.HideLogin  = false;
                ViewBag.EditHeader = stringLocalizer["Set the path to the .dme MapDiffBot should use for rendering"];
                ViewBag.AutoDme    = stringLocalizer["Auto-Detect"];
                ViewBag.Submit     = stringLocalizer["Submit"];
                ViewBag.OnlyMemes  = stringLocalizer["Only maintainers can perform this action!"];

                return(View());
            }
            catch
            {
                return(NotFound());
            }
        }