public async Task <IHttpActionResult> ForgotPassword([FromBody] ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByEmailAsync(model.Email); if (user == null) { //ModelState.AddModelError("email", "Invalid email. Enter your registered email*"); //return this.JsonError(HttpStatusCode.BadRequest, 0, "Warning", ModelState); } else { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = string.Format("{0}/#/set-new-password?userId={1}&code={2}", Url.Link("Default", new { controller = "account" }), user.Id, Uri.EscapeDataString(code)); await EmailNitificationHelper.Create().SendEmailResetPassword(user, UserManager, callbackUrl); } return(this.Ok()); } else { return(JsonError(HttpStatusCode.BadRequest, 10, "Warning", ModelState)); } }
/// <summary> /// Register User Internal /// </summary> /// <param name="model"></param> /// <returns></returns> internal async Task <RegisterUserResult> RegisterInternal(RegisterGeneralModel model) { var userResult = new RegisterUserResult(); using (IUnitOfWork unitOfWork = UnitOfWork.Create()) { var checkUserEmail = unitOfWork.UserRepository.GetAll().FirstOrDefault(a => a.Email == model.Email || a.UserName == model.Email); if (checkUserEmail != null) { userResult.AddError(HttpStatusCode.BadRequest, 10, "This email is already taken ***"); return(userResult); } unitOfWork.BeginTransaction(); //Create user record var user = new ApplicationUser { Id = Guid.NewGuid().ToString(), FirstName = model.FirstName ?? string.Empty, LastName = model.LastName ?? string.Empty, UserName = model.Email, Email = model.Email, //AvatarFileId = model.AvatarFileId, HasTempPassword = true, CreatedById = DbConstants.AdminUserId, CreatedDate = DateTime.Now }; if (!string.IsNullOrEmpty(model.UserName)) { var names = model.UserName.Split(' '); user.FirstName = names[0]; user.LastName = names.Length > 1 ? names[1] : ""; } if (!string.IsNullOrEmpty(model.Password)) { user.PasswordHash = new PasswordHasher().HashPassword(model.Password); } user.AutopilotTrack = true; user.SecurityStamp = Guid.NewGuid().ToString(); #region Need To redo { ISchedulerFactory factory = new StdSchedulerFactory(); IScheduler scheduler = factory.GetScheduler(); JobDataMap dataMap = new JobDataMap(); dataMap["registermodel"] = model; dataMap["userId"] = user.Id; dataMap["OperationType"] = "Registration"; var job = JobBuilder.Create <UpdateContactJob>() .WithIdentity("UpdateContactJob").UsingJobData(dataMap) .Build(); var jobKey = new JobKey("UpdateContactJob"); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1") .StartAt(DateTime.Now) .ForJob(jobKey) .Build(); if (!scheduler.CheckExists(jobKey)) { scheduler.ScheduleJob(job, trigger); } scheduler.Start(); } #endregion unitOfWork.UserRepository.Insert(user); await unitOfWork.SaveAsync(); ApplicationUserRole userRole = new ApplicationUserRole(); userRole.RoleId = DataLayer.DbConstants.CustomerUserRole; userRole.UserId = user.Id; unitOfWork.UserRoleRepository.Insert(userRole); await unitOfWork.SaveAsync(); Address address = new Address(); address.CreatedById = user.Id; address.CreatedDate = DateTime.Now; unitOfWork.AddressRepository.Insert(address); await unitOfWork.SaveAsync(); CustomerDetails customer = new CustomerDetails(); customer.Id = Guid.NewGuid(); customer.CreatedById = user.Id; customer.CreatedDate = DateTime.Now; customer.UserId = user.Id; customer.ContactPhone = model.ContactPhone; customer.AddressId = address.Id; customer.ModifiedReason = "created"; unitOfWork.CustomerDetailsRepository.Insert(customer); await unitOfWork.SaveAsync(); if (!string.IsNullOrEmpty(model.Provider) && !string.IsNullOrEmpty(model.ExternalAccessToken)) { var loginInfo = await this.SignInManager.AuthenticationManager.GetExternalLoginInfoAsync(); ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(loginInfo.ExternalIdentity as ClaimsIdentity); ApplicationUserLogin userLogin = new ApplicationUserLogin(); userLogin.UserId = user.Id; userLogin.ProviderKey = loginInfo.Login.ProviderKey; userLogin.LoginProvider = loginInfo.Login.LoginProvider; unitOfWork.UserLoginRepository.Insert(userLogin); await unitOfWork.SaveAsync(); } unitOfWork.CommitTransaction(); if (model.Provider == null) { //Senf verification Email { string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = string.Format("{0}/#/confirm-email?userId={1}&code={2}", Url.Link("Default", new { controller = "account" }), user.Id, Uri.EscapeDataString(code)); await EmailNitificationHelper.Create().SendConfirmationEmail(user, UserManager, callbackUrl); } } userResult.UserId = user.Id; return(userResult); } }
public Task SendAsync(IdentityMessage message) { return(EmailNitificationHelper.Create().ConfigSendGridasync(message)); }