mirror of
https://github.com/bitwarden/server.git
synced 2025-04-07 05:58:13 -05:00
success/error messages for admin
This commit is contained in:
parent
674077d453
commit
40dff2cd6e
@ -7,7 +7,6 @@ using Bit.Core;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Bit.Admin.Controllers
|
namespace Bit.Admin.Controllers
|
||||||
{
|
{
|
||||||
|
@ -16,11 +16,19 @@ namespace Bit.Admin.Controllers
|
|||||||
_signInManager = signInManager;
|
_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
|
return View(new LoginModel
|
||||||
{
|
{
|
||||||
ReturnUrl = returnUrl
|
ReturnUrl = returnUrl,
|
||||||
|
Error = error,
|
||||||
|
Success = success
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +40,11 @@ namespace Bit.Admin.Controllers
|
|||||||
{
|
{
|
||||||
await _signInManager.PasswordlessSignInAsync(model.Email,
|
await _signInManager.PasswordlessSignInAsync(model.Email,
|
||||||
Url.Action("Confirm", "Login", new { returnUrl = model.ReturnUrl }, Request.Scheme));
|
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);
|
return View(model);
|
||||||
@ -43,8 +55,10 @@ namespace Bit.Admin.Controllers
|
|||||||
var result = await _signInManager.PasswordlessSignInAsync(email, token, true);
|
var result = await _signInManager.PasswordlessSignInAsync(email, token, true);
|
||||||
if(!result.Succeeded)
|
if(!result.Succeeded)
|
||||||
{
|
{
|
||||||
// TODO: error?
|
return RedirectToAction("Index", new
|
||||||
return RedirectToAction("Index");
|
{
|
||||||
|
error = "This login confirmation link is invalid. Try logging in again."
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
|
if(!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
|
||||||
@ -60,7 +74,10 @@ namespace Bit.Admin.Controllers
|
|||||||
public async Task<IActionResult> Logout()
|
public async Task<IActionResult> Logout()
|
||||||
{
|
{
|
||||||
await _signInManager.SignOutAsync();
|
await _signInManager.SignOutAsync();
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index", new
|
||||||
|
{
|
||||||
|
success = "You have been logged out."
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,7 @@ namespace Bit.Admin.Models
|
|||||||
[EmailAddress]
|
[EmailAddress]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
public string ReturnUrl { get; set; }
|
public string ReturnUrl { get; set; }
|
||||||
|
public string Error { get; set; }
|
||||||
|
public string Success { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,13 @@ namespace Bit.Admin
|
|||||||
|
|
||||||
// Identity
|
// Identity
|
||||||
services.AddPasswordlessIdentityServices<ReadOnlyEnvIdentityUserStore>(globalSettings);
|
services.AddPasswordlessIdentityServices<ReadOnlyEnvIdentityUserStore>(globalSettings);
|
||||||
|
if(globalSettings.SelfHosted)
|
||||||
|
{
|
||||||
|
services.ConfigureApplicationCookie(options =>
|
||||||
|
{
|
||||||
|
options.Cookie.Path = "/admin";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
services.AddBaseServices();
|
services.AddBaseServices();
|
||||||
|
@ -5,6 +5,14 @@
|
|||||||
|
|
||||||
<div class="row justify-content-md-center">
|
<div class="row justify-content-md-center">
|
||||||
<div class="col col-lg-6 col-md-8">
|
<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">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p>Please enter your email address below to log in.</p>
|
<p>Please enter your email address below to log in.</p>
|
||||||
|
@ -220,7 +220,7 @@ namespace Bit.Core.Utilities
|
|||||||
{
|
{
|
||||||
options.LoginPath = "/login";
|
options.LoginPath = "/login";
|
||||||
options.LogoutPath = "/";
|
options.LogoutPath = "/";
|
||||||
options.AccessDeniedPath = "/login?accessDenied=1";
|
options.AccessDeniedPath = "/login?accessDenied=true";
|
||||||
options.Cookie.Name = $"Bitwarden_{globalSettings.ProjectName}";
|
options.Cookie.Name = $"Bitwarden_{globalSettings.ProjectName}";
|
||||||
options.Cookie.HttpOnly = true;
|
options.Cookie.HttpOnly = true;
|
||||||
options.Cookie.Expiration = options.ExpireTimeSpan = TimeSpan.FromDays(2);
|
options.Cookie.Expiration = options.ExpireTimeSpan = TimeSpan.FromDays(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user