public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { if (_repository.IsThereSameEmail(model.Email)) { model.Country = _repository.GetCountries(); ModelState.AddModelError("Email", "Korisnik sa istom email adresom je već registrovan. "); ModelState.AddModelError(string.Empty, "Korisnik sa istom email adresom je već registrovan. "); return(View(model)); } else { var user = new StoreUser { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, UserName = model.Email, Address = model.Address, PostalNumber = model.PostalNumber, City = model.City, CountryId = model.CountryId, PhoneNumber = model.PhoneNumber }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme); try { MimeMessage message = new MimeMessage(); MailboxAddress from = new MailboxAddress("DevitoAnonymo", "*****@*****.**"); message.From.Add(from); MailboxAddress to = new MailboxAddress(model.FirstName + " " + model.LastName, "*****@*****.**"); //promeniti da stize na model.Email message.To.Add(to); message.Subject = "Aktivacija naloga - DevitoAnonymo.com"; BodyBuilder bodyBuilder = new BodyBuilder(); bodyBuilder.HtmlBody = "<h1>Aktivacija naloga - DevitoAnonymo.com</h1><br/>" + "<h3>Da biste aktivirali svoj nalog, kliknite na sledeći link:</h3>" + confirmationLink + "<br/><hr style='width:100%'/><p><strong>Ukoliko postoji problem sa pristupom nalogu, javite se na email: [email protected]</strong></p>"; message.Body = bodyBuilder.ToMessageBody(); SmtpClient client = new SmtpClient(); await client.ConnectAsync("Smtp.gmail.com", 465, true); await client.AuthenticateAsync("*****@*****.**", "zdmmgzjsmsiizygb"); await client.SendAsync(message); await client.DisconnectAsync(true); client.Dispose(); } catch (Exception e) { throw new Exception(e.Message); } FlashMessage.Info("Uspešno ste registrovani. Pre nego što se prijavite, molimo vas potvrdite svoj nalog putem aktivacionog linka koji vam je poslat na email. "); return(Redirect("/Account/Login")); } else { foreach (var error in result.Errors) { ModelState.TryAddModelError(error.Code, error.Description); } return(View(model)); } } } else { return(View(model)); } }