Browse Source

success/error messages for admin

pull/288/head
Kyle Spearrin 8 years ago
parent
commit
40dff2cd6e
  1. 1
      src/Admin/Controllers/HomeController.cs
  2. 29
      src/Admin/Controllers/LoginController.cs
  3. 2
      src/Admin/Models/LoginModel.cs
  4. 7
      src/Admin/Startup.cs
  5. 8
      src/Admin/Views/Login/Index.cshtml
  6. 2
      src/Core/Utilities/ServiceCollectionExtensions.cs

1
src/Admin/Controllers/HomeController.cs

@ -7,7 +7,6 @@ using Bit.Core; @@ -7,7 +7,6 @@ using Bit.Core;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Linq;
namespace Bit.Admin.Controllers
{

29
src/Admin/Controllers/LoginController.cs

@ -16,11 +16,19 @@ namespace Bit.Admin.Controllers @@ -16,11 +16,19 @@ namespace Bit.Admin.Controllers
_signInManager = signInManager;
}
public IActionResult Index(string returnUrl = null)
public IActionResult Index(string returnUrl = null, string error = null, string success = null,
bool accessDenied = false)
{
if(string.IsNullOrWhiteSpace(error) && accessDenied)
{
error = "Access denied. Please log in.";
}
return View(new LoginModel
{
ReturnUrl = returnUrl
ReturnUrl = returnUrl,
Error = error,
Success = success
});
}
@ -32,7 +40,11 @@ namespace Bit.Admin.Controllers @@ -32,7 +40,11 @@ namespace Bit.Admin.Controllers
{
await _signInManager.PasswordlessSignInAsync(model.Email,
Url.Action("Confirm", "Login", new { returnUrl = model.ReturnUrl }, Request.Scheme));
return RedirectToAction("Index", "Home");
return RedirectToAction("Index", new
{
success = "If a valid admin user with this email address exists, " +
"we've sent you an email with a secure link to log in."
});
}
return View(model);
@ -43,8 +55,10 @@ namespace Bit.Admin.Controllers @@ -43,8 +55,10 @@ namespace Bit.Admin.Controllers
var result = await _signInManager.PasswordlessSignInAsync(email, token, true);
if(!result.Succeeded)
{
// TODO: error?
return RedirectToAction("Index");
return RedirectToAction("Index", new
{
error = "This login confirmation link is invalid. Try logging in again."
});
}
if(!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
@ -60,7 +74,10 @@ namespace Bit.Admin.Controllers @@ -60,7 +74,10 @@ namespace Bit.Admin.Controllers
public async Task<IActionResult> Logout()
{
await _signInManager.SignOutAsync();
return RedirectToAction("Index");
return RedirectToAction("Index", new
{
success = "You have been logged out."
});
}
}
}

2
src/Admin/Models/LoginModel.cs

@ -8,5 +8,7 @@ namespace Bit.Admin.Models @@ -8,5 +8,7 @@ namespace Bit.Admin.Models
[EmailAddress]
public string Email { get; set; }
public string ReturnUrl { get; set; }
public string Error { get; set; }
public string Success { get; set; }
}
}

7
src/Admin/Startup.cs

@ -47,6 +47,13 @@ namespace Bit.Admin @@ -47,6 +47,13 @@ namespace Bit.Admin
// Identity
services.AddPasswordlessIdentityServices<ReadOnlyEnvIdentityUserStore>(globalSettings);
if(globalSettings.SelfHosted)
{
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Path = "/admin";
});
}
// Services
services.AddBaseServices();

8
src/Admin/Views/Login/Index.cshtml

@ -5,6 +5,14 @@ @@ -5,6 +5,14 @@
<div class="row justify-content-md-center">
<div class="col col-lg-6 col-md-8">
@if(!string.IsNullOrWhiteSpace(Model.Success))
{
<div class="alert alert-success" role="alert">@Model.Success</div>
}
else if(!string.IsNullOrWhiteSpace(Model.Error))
{
<div class="alert alert-danger" role="alert">@Model.Error</div>
}
<div class="card">
<div class="card-body">
<p>Please enter your email address below to log in.</p>

2
src/Core/Utilities/ServiceCollectionExtensions.cs

@ -220,7 +220,7 @@ namespace Bit.Core.Utilities @@ -220,7 +220,7 @@ namespace Bit.Core.Utilities
{
options.LoginPath = "/login";
options.LogoutPath = "/";
options.AccessDeniedPath = "/login?accessDenied=1";
options.AccessDeniedPath = "/login?accessDenied=true";
options.Cookie.Name = $"Bitwarden_{globalSettings.ProjectName}";
options.Cookie.HttpOnly = true;
options.Cookie.Expiration = options.ExpireTimeSpan = TimeSpan.FromDays(2);

Loading…
Cancel
Save