public async Task <bool> SendProfessionalInvitation(ProfessionalInvitationModel invitationModel) { var Token = Guid.NewGuid().ToString(); //Send Email using (var emailHelper = new CummunicationHelper(Configuration)) { WelcomeEmail email = new WelcomeEmail { Name = invitationModel.Fname, VerifyUrl = invitationModel.VerifyUrl + "?invitationToken=" + Token }; await emailHelper.SendEmailInvitation(email, invitationModel.Email); } return(await _userRepository.SendInvitation(invitationModel, Token)); }
public async Task <bool> SetUserEmail(string emailId, Guid userId) { Helper helper = new Helper(); //Generate 6 digit OTP var newToken = helper.CodeGenerator(6); DateTime expiryOn = DateTime.Now.AddMinutes(3); //Send Email using (var emailHelper = new CummunicationHelper(Configuration)) { WelcomeEmail email = new WelcomeEmail { Name = string.Empty }; await emailHelper.SendEmailVerifyCode(email, newToken, emailId); } //Update to Db return(await _userRepository.UpdateEmail(emailId, expiryOn, newToken, userId)); }
public async Task <ActionResult> ForgotPasswordLink([FromBody] ForgotPasswordRequest user) { try { var existingUser = await _userManager.FindByName(user.Email); if (existingUser == null) { return(BadRequest(new { message = "There are no accounts linked to this email!" })); } Random r = new Random(); int randNum = r.Next(1000000); string code = randNum.ToString("D6"); var userWithCode = await _authManager.ForgotPasswordCode(existingUser.Id, code); //var body = $"Reset password code is: {userWithCode.ForgotPasswordCode} "; //var subject = "Reset password code"; //await _emailService.SendEmail(existingUser.Username, existingUser.Username, body, subject); using (var emailHelper = new CummunicationHelper(_config)) { Common email = new Common { Name = existingUser.Email }; await emailHelper.SendForgotPassword(email, code, existingUser.Email); } return(Ok()); } catch (Exception ex) { _logger.LogError("An error has been thrown in AuthController:ForgotPassword"); return(BadRequest(ex)); } }
public async Task <Guid> RegisterAsync(User user, string verificationurl, int role) { var desiredRole = await _commonRepository.FindRoleByName(Enum.GetName(typeof(RoleType), role)); user.Id = Guid.NewGuid(); user.UserProfile.Id = Guid.NewGuid(); user.RoleId = desiredRole.Id; if (!string.IsNullOrEmpty(user.Password)) { var hashed = _hasher.Hash(user.Password); user.Password = hashed.hashed; user.Salt = hashed.salt; } user.UserCode = role == 1 ? "TCC" + helper.GenerateUserCode() : "TCP" + helper.GenerateUserCode(); var token = Guid.NewGuid().ToString(); //Send Email using (var emailHelper = new CummunicationHelper(Configuration)) { WelcomeEmail email = new WelcomeEmail { Name = string.Empty, VerifyUrl = verificationurl + token }; await emailHelper.SendEmailVerifyEmail(email, user.Email); } user.VerifyToken = token; user.TokenExpiry = DateTime.UtcNow.AddDays(1); var result = await _authRepository.RegisterAsync(user); return(result.Id); }