Ejemplo n.º 1
0
 public async Task<IActionResult> RegisterUser([FromBody] RegisterUserModel model)
 {
     if (await userManager.FindByEmailAsync(model.Email) != null)
     {
         return BadRequest("User already exists");
     }
     var invitation = await invitationProvider.GetInvitation(model.InvitationId);
     if (invitation == null)
     {
         return BadRequest("Invitation not found");
     }
     var identityResult = await userManager.CreateAsync(new ApplicationUser
     {
         UserName = model.Email,
         Email = model.Email
     }, model.Password);
     if (!identityResult.Succeeded) return BadRequest("Something went wrong!");
     var user = await userManager.FindByEmailAsync(model.Email);
     await usersProvider.AddPerson(new Person
     {
         Id = user.Id,
         ApplicationUserId = user.Id,
         FirstName = model.FirstName,
         LastName = model.LastName,
         CompanyId = invitation.CompanyId
     });
     await invitationProvider.DeleteInvitation(model.InvitationId);
     // var token = await userManager.GenerateEmailConfirmationTokenAsync(user);
     // await emailProvider.SendConfirmEmail(user, token);
     var appToken = await jwtFactory.GenerateEncodedToken(user);
     var newRefreshToken = jwtFactory.GenerateRefreshToken();
     user.RefreshToken = newRefreshToken;
     await userManager.UpdateAsync(user);
     return new ObjectResult(new
     {
         token = appToken,
         refreshToken = newRefreshToken
     });
 }