public ActionResult AddCombo() { //var name = User.Identity.Name; ComboAddViewModel model = new ComboAddViewModel(); return(View(model)); }
public ActionResult AddCombo(ComboAddViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = new ApplicationUser { Email = model.Email, UserName = model.Email }; string password = RandomPassword(); string regex = @"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{6,9}$"; var match = Regex.Match(password, regex, RegexOptions.IgnoreCase); if (!match.Success) { //Console.WriteLine($"Поганий пароль - {str}"); } var res = UserManager.CreateAsync(user, "Qwerty1-").Result; //manager.AddToRole(user.Id, "AppAdmin"); if (res.Succeeded) { TCombo combo = new TCombo { Name = model.Name, Image = model.Image }; _context.Combos.Add(combo); _context.SaveChanges(); var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "tanyavadim1234"), EnableSsl = true }; client.Send("*****@*****.**", model.Email, "Новий пароль", $"Пароль: {password}"); } return(RedirectToAction("index")); }