//const string TO = "*****@*****.**"; // Specify where you want this email sent. // This value may/may not be constant. // To get started use one of your email // addresses. public string EmailFromArvixe(RegisteredUser message) { // Use credentials of the Mail account that you created with the steps above. const string FROM = "*****@*****.**"; const string FROM_PWD = "123456789"; const bool USE_HTML = true; // Get the mail server obtained in the steps described above. const string SMTP_SERVER = "143.95.249.35"; try { MailMessage mailMsg = new MailMessage(FROM, message.Email); mailMsg.Subject = message.Subject; mailMsg.Body = message.Body; mailMsg.IsBodyHtml = USE_HTML; SmtpClient smtp = new SmtpClient(); smtp.Port = 25; smtp.Host = SMTP_SERVER; smtp.Credentials = new System.Net.NetworkCredential(FROM, FROM_PWD); smtp.Send(mailMsg); } catch (System.Exception ex) { return ex.Message; } return SUCCESS; }
public ActionResult Register(RegisteredUser newUser) { // TAKING THE WRONG MODEL AS INPUT??? var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore) { UserLockoutEnabledByDefault = true, DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0), MaxFailedAccessAttemptsBeforeLockout = 3 }; var identityUser = new IdentityUser() { UserName = newUser.UserName, Email = newUser.Email }; // this threw an error, but it also worked so what gives??? IdentityResult result = manager.Create(identityUser, newUser.Password); if (result.Succeeded) { CreateTokenProvider(manager, EMAIL_CONFIRMATION); // identityUser.Id use this to create an entry in our accounts table var code = manager.GenerateEmailConfirmationToken(identityUser.Id); var callbackUrl = Url.Action("VerifiedEmail", "Accounts", new { userId = identityUser.Id, code = code }, protocol: Request.Url.Scheme); string email = "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">Confirm Registration</a>"; ViewBag.FakeConfirmation = email; UserAccountVMRepo uaRepo = new UserAccountVMRepo(); uaRepo.CreateAccount(newUser.FirstName, newUser.LastName, identityUser.Id); // CREATE WITH CONSUMER ROLE BY DEFAULT SecurityEntities context = new SecurityEntities(); AspNetUser user = context.AspNetUsers .Where(u => u.UserName == newUser.UserName).FirstOrDefault(); AspNetRole role = context.AspNetRoles .Where(r => r.Name == "consumer").FirstOrDefault(); user.AspNetRoles.Add(role); context.SaveChanges(); MailHelper mailer = new MailHelper(); string response = mailer.EmailFromArvixe( new RegisteredUser(newUser.Email, newUser.Subject = "Confirm Email", newUser.Body = email)); ViewBag.Response = response; return View("ConfirmEmail"); } return View(); }
public ActionResult ForgotPassword(string email, RegisteredUser userRecovery) { var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore); var user = manager.FindByEmail(email); CreateTokenProvider(manager, PASSWORD_RESET); var code = manager.GeneratePasswordResetToken(user.Id); var callbackUrl = Url.Action("ResetPassword", "Accounts", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); var body = "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"; MailHelper mailer = new MailHelper(); string response = mailer.EmailFromArvixe( new RegisteredUser(userRecovery.Email = email, userRecovery.Subject = "Password Recovery Email", userRecovery.Body = body)); return View("PasswordEmail"); }