public bool ConfirmEmail(Guid tokenId) { bool result = false; Token token = UserTokensService.Get(tokenId); ApplicationUserManager userManager = UserService.GetUserManager(); ApplicationUser user = userManager.FindByName(token.UserName); if (user != null) { // Set the EmailConfirmed flag in AspNetUsers table DataProvider.ExecuteNonQuery(GetConnection, "dbo.AspNetUsers_UpdateEmailConfirmed" , inputParamMapper : delegate(SqlParameterCollection UpdateEmailConfirmed) { UpdateEmailConfirmed.AddWithValue("@EmailConfirmed", true); UpdateEmailConfirmed.AddWithValue("@UserName", token.UserName); }); // Insert new record in Users table ApplicationUser au = UserService.GetUserbyUserName(token.UserName); UserInfoAddRequest req = new UserInfoAddRequest(); req.UserName = token.UserName; req.Phone = au.PhoneNumber; req.Email = au.Email; Insert(req, au.Id); // Delete the token from UserTokens table UserTokensService.Delete(tokenId); result = true; } return(result); }
public static bool ResetPassword(ResetPasswordRequest model) { if (string.IsNullOrEmpty(model.NewPassword)) { throw new Exception("You must provide a password"); } Guid tokenGuid = new Guid(model.TokenId); Token token = UserTokensService.Get(tokenGuid); // Given the token, Get the UserName ApplicationUser applicationUser = GetUserbyUserName(token.UserName); // From the UserName, get UserId bool success = ChangePassWord(applicationUser.Id, model.NewPassword); // applicationUser has the email we needed to use ChangePassWord if (success) { UserTokensService.Delete(tokenGuid); } return(success); }