-
}
\ No newline at end of file
diff --git a/Yavsc/src/Controllers/AccountController.cs b/Yavsc/src/Controllers/AccountController.cs
index 0b798c8b..a0b55fd2 100644
--- a/Yavsc/src/Controllers/AccountController.cs
+++ b/Yavsc/src/Controllers/AccountController.cs
@@ -10,6 +10,7 @@ using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.OptionsModel;
+using Yavsc.Extensions;
using Yavsc.Models;
using Yavsc.Services;
using Yavsc.ViewModels.Account;
@@ -50,16 +51,21 @@ namespace Yavsc.Controllers
_twilioSettings = twilioSettings.Value;
_logger = loggerFactory.CreateLogger();
}
-
- public IActionResult Forbidden()
+ [HttpGet("~/login")]
+ public IActionResult Login(string returnUrl)
{
- return View();
+ return View("SignIn", new LoginViewModel {
+ AfterLoginRedirectUrl = returnUrl,
+ ReturnUrl = "/Account/ExternalLoginCallback",
+ ExternalProviders = HttpContext.GetExternalProviders()
+ });
}
-
+
[HttpPost("~/login")]
public async Task LocalLogin(LoginViewModel model)
{
+
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
@@ -67,8 +73,6 @@ namespace Yavsc.Controllers
var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
- _logger.LogInformation(1, "User logged in.");
-
return RedirectToLocal(model.ReturnUrl);
}
if (result.RequiresTwoFactor)
@@ -86,7 +90,9 @@ namespace Yavsc.Controllers
return View(model);
}
}
+
// If we got this far, something failed, redisplay form
+ ModelState.AddModelError(string.Empty, "Unexpected behavior: something failed ... you could try again, or contact me ...");
return View(model);
}
//
@@ -130,11 +136,12 @@ namespace Yavsc.Controllers
// POST: /Account/LogOff
[HttpPost]
[ValidateAntiForgeryToken]
- public async Task LogOff()
+ public async Task LogOff(string returnUrl = null)
{
await _signInManager.SignOutAsync();
_logger.LogInformation(4, "User logged out.");
- return RedirectToAction(nameof(HomeController.Index), "Home");
+ if (returnUrl==null) return RedirectToAction(nameof(HomeController.Index), "Home");
+ return Redirect(returnUrl);
}
//
diff --git a/Yavsc/src/Controllers/OAuthController.cs b/Yavsc/src/Controllers/OAuthController.cs
index 549071e5..71c63377 100644
--- a/Yavsc/src/Controllers/OAuthController.cs
+++ b/Yavsc/src/Controllers/OAuthController.cs
@@ -46,7 +46,7 @@ ILogger _logger;
[HttpGet("~/signin")]
- public ActionResult SignIn(string returnUrl = "/Account/ExternalLoginCallback") {
+ public ActionResult SignIn(string returnUrl = null) {
// Note: the "returnUrl" parameter corresponds to the endpoint the user agent
// will be redirected to after a successful authentication and not
// the redirect_uri of the requesting client application.
@@ -62,7 +62,7 @@ ILogger _logger;
}
[HttpPost("~/signin")]
- public IActionResult SignIn( string Provider, string ReturnUrl ) {
+ public IActionResult SignIn( string Provider, string ReturnUrl, string AfterLoginRedirectUrl) {
// Note: the "provider" parameter corresponds to the external
// authentication provider choosen by the user agent.
if (string.IsNullOrEmpty(Provider)) {
@@ -86,8 +86,17 @@ ILogger _logger;
// Instruct the middleware corresponding to the requested external identity
// provider to redirect the user agent to its own authorization endpoint.
// Note: the authenticationScheme parameter must match the value configured in Startup.cs
-
+
+ // If AfterLoginRedirectUrl is non null,
+ // This is a web interface access,
+ // and the wanted redirection
+ // after the successfull authentication
+ if (AfterLoginRedirectUrl!=null) {
+ ReturnUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = AfterLoginRedirectUrl });
+ }
+
var properties = _signInManager.ConfigureExternalAuthenticationProperties(Provider, ReturnUrl);
+
return new ChallengeResult(Provider, properties);
}
diff --git a/Yavsc/src/ViewModels/Account/LoginViewModel.cs b/Yavsc/src/ViewModels/Account/LoginViewModel.cs
index bc8f90b6..4cf86f10 100755
--- a/Yavsc/src/ViewModels/Account/LoginViewModel.cs
+++ b/Yavsc/src/ViewModels/Account/LoginViewModel.cs
@@ -16,7 +16,19 @@ namespace Yavsc.ViewModels.Account
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
+
+ ///
+ /// This value indicates the OAuth client method recieving the code,
+ /// in case of.
+ ///
+ ///
public string ReturnUrl { get; set; }
+ ///
+ /// This is the Url redirection used after a successfull resource grant
+ /// to a legacy web browser client.
+ ///
+ ///
+ public string AfterLoginRedirectUrl { get; set; }
public IEnumerable ExternalProviders { get; set; }
}