public ActionResult ForgotPassword(string id, LogInModel logIn) { var email = logIn.Email; var volunteer = volunteerCollection.AsQueryable <VolunteerModel>().SingleOrDefault(x => x.Email == email); if (volunteer == null) { ViewBag.Message = "Your are not Registered... Please Register First!!!! "; } else { var filter = Builders <VolunteerModel> .Filter.Eq("_id", volunteer.Id); string password = Membership.GeneratePassword(12, 1); var update = Builders <VolunteerModel> .Update .Set("Password", password) .Set("ConfirmPassword", password); var result = volunteerCollection.UpdateOne(filter, update); MailAddressModel mode = new MailAddressModel(); mode.To = email; mode.From = "*****@*****.**"; mode.Subject = "Hello"; mode.Body = "Hello, use the following temporary password to log in and make sure you change it as soon as you can: <h2>" + password + "</h2> "; GenerateNewPassword(mode); ViewBag.Message = "Email was sent to you with a temporary password...."; } return(View()); }
public ActionResult AddRole(string id, VolunteerModel volunteer) { var list = new List <string>() { null, "Admin", "Moderator", "Volunteer" }; ViewBag.list = list; var volunteerId = new ObjectId(id); var vol = volunteerCollection.AsQueryable <VolunteerModel>().SingleOrDefault(x => x.Id == volunteerId); var email = vol.Email; try { // TODO: Add update logic here var filter = Builders <VolunteerModel> .Filter.Eq("_id", ObjectId.Parse(id)); if (volunteer.Role == null) { var update = Builders <VolunteerModel> .Update .Set("Active", "No") .Set("Role", volunteer.Role); var result = volunteerCollection.UpdateOne(filter, update); } else { MailAddressModel mode = new MailAddressModel(); mode.To = email; mode.From = Session["Email"].ToString(); mode.Subject = "Hello"; mode.Body = "Hello, your account has been activated!!! Please log in ..."; SendEmail(mode); var update = Builders <VolunteerModel> .Update .Set("Active", "Yes") .Set("Role", volunteer.Role); var result = volunteerCollection.UpdateOne(filter, update); } List <VolunteerModel> volunteers = volunteerCollection.AsQueryable <VolunteerModel>().ToList(); volunteerList = new List <string>(); foreach (var volun in volunteers) { if (volun.Active == "Yes") { volunteerList.Add(volun.Name.ToString()); } } Session["VolunteerList"] = volunteerList; return(RedirectToAction("../Volunteers/Index")); } catch { return(View()); } }
public void SendEmail(MailAddressModel model) { MailMessage mail = new MailMessage(); mail.To.Add(model.To); mail.From = new MailAddress(model.From); mail.Subject = model.Subject; string Body = model.Body; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "TestingPass"); // Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); }