public async Task <IActionResult> ForgetPassword(string email) { if (email == null) { return(NotFound()); } var user = await _manager.FindByEmailAsync(email); if (user == null) { return(NotFound()); } var token = await _manager.GeneratePasswordResetTokenAsync(user); var encodeToken = Encoding.UTF8.GetBytes(token); var newToken = WebEncoders.Base64UrlEncode(encodeToken); var ConfirmLink = $"http://localhost:4200/PasswordConfirm?ID={user.Id}&token={newToken}"; var txt = "Please confirm Password"; var link = "<a href=\"" + ConfirmLink + "\">Confirm Password</a>"; var subject = "Password Confirm"; if (await SenderGridApi.Execute(user.Email, user.UserName, subject, txt, link)) { // return Ok(link); return(new ObjectResult(new { token = newToken })); } return(StatusCode(StatusCodes.Status400BadRequest)); }
public async Task <IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { if (await EmailExists(model.Email)) { return(BadRequest("Email is used")); } if (await UserExists(model.Username)) { return(BadRequest("Username is used")); } else { var user = new ApplicationUser { UserName = model.Username, PhoneNumber = model.Phone, Country = model.Country, Email = model.Email }; var result = await _manager.CreateAsync(user, model.Password); if (result.Succeeded) { var token = await _manager.GenerateEmailConfirmationTokenAsync(user); //var ConfirmLinkAsp = Url.Action("ConfirmEmail", "Account", new //{ // id = user.Id, // token = HttpUtility.UrlEncode(token) //}, Request.Scheme); var encodeToken = Encoding.UTF8.GetBytes(token); var newToken = WebEncoders.Base64UrlEncode(encodeToken); var ConfirmLink = $"http://localhost:4200/RegisterConfirm?ID={user.Id}&token={newToken}"; var txt = "Please confirm your registration at our site"; var link = "<a href=\"" + ConfirmLink + "\">Confirm registration</a>"; var subject = "Registeration Confirm"; if (await SenderGridApi.Execute(user.Email, user.UserName, subject, txt, link)) { // return Ok(link); return(StatusCode(StatusCodes.Status200OK)); } } else { return(BadRequest(result.Errors)); } } } return(StatusCode(StatusCodes.Status400BadRequest)); }