mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
passwordless sign in for admin
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Bit.Admin.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Bit.Admin.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
[Authorize]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
|
48
src/Admin/Controllers/LoginController.cs
Normal file
48
src/Admin/Controllers/LoginController.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Admin.Models;
|
||||
using Bit.Core.Identity;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Bit.Admin.Controllers
|
||||
{
|
||||
public class LoginController : Controller
|
||||
{
|
||||
private readonly PasswordlessSignInManager<IdentityUser> _signInManager;
|
||||
|
||||
public LoginController(
|
||||
PasswordlessSignInManager<IdentityUser> signInManager)
|
||||
{
|
||||
_signInManager = signInManager;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Index(LoginModel model)
|
||||
{
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
await _signInManager.PasswordlessSignInAsync(model.Email);
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Confirm(string email, string token)
|
||||
{
|
||||
var result = await _signInManager.PasswordlessSignInAsync(email, token, false);
|
||||
if(!result.Succeeded)
|
||||
{
|
||||
return View("Error");
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user