1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

verify email apis

This commit is contained in:
Kyle Spearrin 2017-07-05 15:35:46 -04:00
parent d42a47e5f0
commit 87a216e523
7 changed files with 34 additions and 9 deletions

View File

@ -103,7 +103,7 @@ namespace Bit.Api.Controllers
await Task.Delay(2000);
throw new BadRequestException(ModelState);
}
[HttpPost("verify-email")]
public async Task PostVerifyEmail()
{
@ -118,14 +118,26 @@ namespace Bit.Api.Controllers
[HttpPost("verify-email-token")]
[AllowAnonymous]
public async Task PostVerifyEmailToken()
public async Task PostVerifyEmailToken([FromBody]VerifyEmailRequestModel model)
{
var user = await _userService.GetUserByIdAsync(new Guid());
var user = await _userService.GetUserByIdAsync(new Guid(model.UserId));
if(user == null)
{
throw new UnauthorizedAccessException();
}
await _userService.ConfirmEmailAsync(user, "");
var result = await _userService.ConfirmEmailAsync(user, model.Token);
if(result.Succeeded)
{
return;
}
foreach(var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
await Task.Delay(2000);
throw new BadRequestException(ModelState);
}
[HttpPut("password")]

View File

@ -205,7 +205,7 @@ namespace Bit.Api
else
{
//return $"http://localhost:{port}";
return $"http://192.168.1.6:{port}"; // Desktop external
return $"http://192.168.1.4:{port}"; // Desktop external
}
}
}

View File

@ -80,7 +80,7 @@ namespace Bit.Core.Identity
public Task<bool> GetEmailConfirmedAsync(User user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(true); // all emails are confirmed
return Task.FromResult(user.EmailVerified);
}
public Task<string> GetNormalizedEmailAsync(User user, CancellationToken cancellationToken = default(CancellationToken))
@ -121,7 +121,7 @@ namespace Bit.Core.Identity
public Task SetEmailConfirmedAsync(User user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
{
// do nothing
user.EmailVerified = confirmed;
return Task.FromResult(0);
}

View File

@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.Models.Api
{
public class VerifyEmailRequestModel
{
[Required]
public string UserId { get; set; }
[Required]
public string Token { get; set; }
}
}

View File

@ -35,7 +35,7 @@ namespace Bit.Core.Services
var message = CreateDefaultMessage("Verify Your Email", email);
var model = new VerifyEmailModel
{
Token = token,
Token = WebUtility.UrlEncode(token),
UserId = userId,
WebVaultUrl = _globalSettings.BaseVaultUri,
SiteName = _globalSettings.SiteName

View File

@ -294,7 +294,7 @@ namespace Bit.Core.Services
{
if(user.EmailVerified)
{
throw new BadRequestException("Email already verifed.");
throw new BadRequestException("Email already verified.");
}
var token = await base.GenerateEmailConfirmationTokenAsync(user);

View File

@ -103,6 +103,7 @@ namespace Bit.Core.Utilities
identityBuilder
.AddUserStore<UserStore>()
.AddRoleStore<RoleStore>()
.AddTokenProvider<DataProtectorTokenProvider<User>>(TokenOptions.DefaultProvider)
.AddTokenProvider<AuthenticatorTokenProvider>(TwoFactorProviderType.Authenticator.ToString())
.AddTokenProvider<YubicoOtpTokenProvider>(TwoFactorProviderType.YubiKey.ToString())
.AddTokenProvider<DuoWebTokenProvider>(TwoFactorProviderType.Duo.ToString())