Skip to content

Commit

Permalink
Thread review Url through login button (#343)
Browse files Browse the repository at this point in the history
* Thread review Url through login button

* Add ReturnUrl property
  • Loading branch information
JoshLove-msft authored Jan 21, 2020
1 parent 1b0e8ce commit 2aaf7d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class AccountController : Controller
public async Task<IActionResult> Login(string returnUrl = "/")
{
await HttpContext.SignOutAsync();
if (!Url.IsLocalUrl(returnUrl))
{
returnUrl = "/";
}
return Challenge(new AuthenticationProperties() { RedirectUri = returnUrl }, "GitHub");
}

Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/APIView/APIViewWeb/Pages/Unauthorized.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
find yourself under the "People" tab of the organization page and set your visibility to public.
</p>

<a class="login-button btn btn-outline-dark" asp-action="Login" asp-controller="Account">
<a class="login-button btn btn-outline-dark" asp-action="Login" asp-controller="Account" asp-route-returnUrl="@Model.ReturnUrl">
<img height="30" width="30" src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" />
Login with GitHub
</a>
6 changes: 6 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Pages/Unauthorized.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class UnauthorizedModel : PageModel
{
public OrganizationOptions Options { get; }

[BindProperty(SupportsGet = true)]
public string ReturnUrl { get; private set; }

public UnauthorizedModel(IOptions<OrganizationOptions> options)
{
Options = options.Value;
Expand All @@ -17,7 +20,10 @@ public UnauthorizedModel(IOptions<OrganizationOptions> options)
public IActionResult OnGet()
{
if (User.Identity.IsAuthenticated)
{
return RedirectToPage("./Assemblies/Index");
}
ReturnUrl = Request.Query["returnurl"];
return Page();
}
}
Expand Down

0 comments on commit 2aaf7d1

Please sign in to comment.