public async Task<IdentityResult> Change([FromBody] UserSet userSet) { Noster noster = _unitofWork.Noster.GetForToken(userSet.Username); return await _userManager.ResetPasswordAsync(noster, userSet.ResetToken, userSet.NewPassword); }
public async Task<object> Register([FromBody] RegisterDto model) { var user = new Noster { UserName = model.Email, Email = model.Email, CreationDate = DateTime.Now, RefreshToken = GenerateRefreshToken(), RefreshExpiration = DateTime.Now.AddDays(1) }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, false); MailHelper.sendSignUpAlert(model.Email); return await GenerateJwtToken(model.Email, user); } else { throw new ApplicationException("UNKNOWN_ERROR"); } }
public async Task Reset([FromBody] UserSet userSet) { Noster noster = _unitofWork.Noster.GetForToken(userSet.Username); if (noster != null) { var resetToken = await _userManager.GeneratePasswordResetTokenAsync(noster); MailHelper.sendReset("*****@*****.**", userSet.Username, resetToken); } //return resetToken; //TODO: probably send an email, text of the reset token to the user }
private async Task<object> GenerateJwtToken(string email, Noster user) { var claims = new List<Claim> { new Claim(JwtRegisteredClaimNames.Sub, email), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(ClaimTypes.NameIdentifier, user.Id) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SOME_RANDOM_KEY_DO_NOT_SHARE")); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); //var expires = DateTime.Now.AddDays(Convert.ToDouble(30)); var expires = DateTime.Now.AddMinutes(Convert.ToDouble(60)); var token = new JwtSecurityToken( "https://localhost:57096", "https://localhost:57096", claims, expires: expires, signingCredentials: creds ); return new JwtSecurityTokenHandler().WriteToken(token); }