/// <summary> /// Notifies the given user of the token /// </summary> /// <param name="token">The token to send</param> /// <param name="manager">The manger that requested it</param> /// <param name="user">The user to send the token to</param> /// <returns>A task that is sending the token</returns> public override Task NotifyAsync(string token, Microsoft.AspNet.Identity.UserManager <Model.Users.User, string> manager, Model.Users.User user) { TextParser parser = new TextParser(this.Manager); TextDefinition subject = parser.ParseMessage(this.Subject, new Dictionary <ReplaceableObjectKeys, object>() { { ReplaceableObjectKeys.Code, token }, { ReplaceableObjectKeys.User, user } }); TextDefinition body = parser.ParseMessage(this.BodyFormat, new Dictionary <ReplaceableObjectKeys, object>() { { ReplaceableObjectKeys.Code, token }, { ReplaceableObjectKeys.User, user } }); new TaskFactory().StartNew(() => { SmtpMailClient.SendMail(user.Email, subject.Text, body.Text, body.Html); }); return(Task.FromResult <int>(0)); }
public ActionResult Registre(Models.UserRegistreViewModel userRegistreViewModel) { if (!this.ModelState.IsValid) { return(View()); } #region Server Side Validation bool modelStateFail = false; if (string.IsNullOrEmpty(userRegistreViewModel.Name)) { this.ModelState.AddModelError("Name", "Name field is required!"); modelStateFail = true; } if (string.IsNullOrEmpty(userRegistreViewModel.Login)) { this.ModelState.AddModelError("Login", "Login field is required!"); modelStateFail = true; } if (string.IsNullOrEmpty(userRegistreViewModel.Password)) { this.ModelState.AddModelError("Password", "Password field is required!"); modelStateFail = true; } if (string.IsNullOrEmpty(userRegistreViewModel.PasswordConfirm)) { this.ModelState.AddModelError("PasswordConfirm", "Confirm password field is required!"); modelStateFail = true; } if (string.IsNullOrEmpty(userRegistreViewModel.Email)) { this.ModelState.AddModelError("Email", "Emailfield is required!"); modelStateFail = true; } if (string.IsNullOrEmpty(userRegistreViewModel.EmailConfirm)) { this.ModelState.AddModelError("EmailConfirm", "Confirm email field is required!"); modelStateFail = true; } if (!userRegistreViewModel.Email.Equals(userRegistreViewModel.EmailConfirm)) { this.ModelState.AddModelError("EmailConfirm", "Confirm email is different!"); modelStateFail = true; } if (!userRegistreViewModel.Password.Equals(userRegistreViewModel.PasswordConfirm)) { this.ModelState.AddModelError("PasswordConfirm", "Confirm password is different!"); modelStateFail = true; } if (iServiceUser.AlreadyRegistredEmail(userRegistreViewModel.Email)) { this.ModelState.AddModelError("Email", "Email alread registred!"); modelStateFail = true; } if (modelStateFail) { return(View()); } #endregion User user = new Model.Users.User() { Name = userRegistreViewModel.Name, Login = userRegistreViewModel.Login, Email = userRegistreViewModel.Email, Password = userRegistreViewModel.Password, UserType = userRegistreViewModel.UserType }; this.iServiceUser.Insert(user); this.iUnitOfWorkAsync.SaveChanges(); IServiceRole serviceRole = DependencyResolver.Current.GetService <ServiceRole>(); string roleName = ""; if (user.UserType == Model.Enums.UserType.Supplier) { roleName = "Supplier"; IServiceSupplierInfo serviceSupplierInfo = DependencyResolver.Current.GetService <ServiceSupplierInfo>(); SupplierInfo SupplierInfo = new SupplierInfo(); SupplierInfo.User = user; serviceSupplierInfo.Insert(SupplierInfo); } else if (user.UserType == Model.Enums.UserType.Custumer) { roleName = "Custumer"; IServiceCustumerInfo seviceCustumerInfo = DependencyResolver.Current.GetService <ServiceCustumerInfo>(); CustumerInfo custumerInfo = new CustumerInfo(); custumerInfo.User = user; seviceCustumerInfo.Insert(custumerInfo); } serviceRole.AddUserOnRole(roleName, user); this.iUnitOfWorkAsync.SaveChanges(); FormsAuthentication.SetAuthCookie(user.Email, false); ModelState.Remove("Password"); return(RedirectToAction("Edit", "User", new { id = user.ID })); //return View(); }