Skip to content

Commit

Permalink
identity: confirm email automatically on self hosted instances
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Aug 1, 2024
1 parent 3c8c8eb commit 2f5bd75
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Streetwriters.Identity/Controllers/SignupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task<IActionResult> Signup([FromForm] SignupForm form)
var result = await UserManager.CreateAsync(new User
{
Email = form.Email,
EmailConfirmed = false,
EmailConfirmed = Constants.IS_SELF_HOSTED,
UserName = form.Username ?? form.Email,
}, form.Password);

Expand Down Expand Up @@ -101,15 +101,18 @@ public async Task<IActionResult> Signup([FromForm] SignupForm form)
if (result.Succeeded)
{
var user = await UserManager.FindByEmailAsync(form.Email);

await UserManager.AddToRoleAsync(user, client.Id);
if (Constants.IS_SELF_HOSTED)
{
await UserManager.AddClaimAsync(user, UserService.SubscriptionTypeToClaim(client.Id, Common.Enums.SubscriptionType.PREMIUM));
await UserManager.AddClaimAsync(user, new Claim("platform", PlatformFromUserAgent(base.HttpContext.Request.Headers.UserAgent)));

var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.TokenLink(user.Id.ToString(), code, client.Id, TokenType.CONFRIM_EMAIL, Request.Scheme);
await EmailSender.SendConfirmationEmailAsync(user.Email, callbackUrl, client);
}
else
{
await UserManager.AddClaimAsync(user, new Claim("platform", PlatformFromUserAgent(base.HttpContext.Request.Headers.UserAgent)));
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.TokenLink(user.Id.ToString(), code, client.Id, TokenType.CONFRIM_EMAIL, Request.Scheme);
await EmailSender.SendConfirmationEmailAsync(user.Email, callbackUrl, client);
}
return Ok(new
{
userId = user.Id.ToString()
Expand Down

0 comments on commit 2f5bd75

Please sign in to comment.