public ActionResult ResetPassword(RegisteredUserVM currentUser, string passwordToken, string userID) { CaptchaHelper captchaHelper = new CaptchaHelper(); string captchaResponse = captchaHelper.CheckRecaptcha(); ViewBag.CaptchaResponse = captchaResponse; if (captchaResponse == "Valid") { var userStore = new UserStore <IdentityUser>(); UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore); var user = manager.FindById(userID); CreateTokenProvider(manager, PASSWORD_RESET); if (currentUser.Password == currentUser.ConfirmPassword) { IdentityResult result = manager.ResetPassword(userID, passwordToken, currentUser.Password); if (result.Succeeded) { ViewBag.Result = "The password has been reset."; } else { ViewBag.Result = "Failed, password has to be at least 6 characters!"; } } } else { ViewBag.Result = "The password has not been reset."; } return(View()); }
static public void sendEmail(RegisteredUserVM userInfo, string confirmLink) { MailMessage mailMsg = new MailMessage(); // To mailMsg.To.Add(new MailAddress(userInfo.Email)); // From mailMsg.From = new MailAddress("*****@*****.**", "OneList Task Management"); // Subject and multipart/alternative Body mailMsg.Subject = "Email Confirmation"; string text = "A message from OneList"; //string html = @"<p>Please confirm your account by clicking this link: < a href =\"" // + comfirmLink + "\">Confirm Registration</a></p>"; string body = "<p>Thank you for using OneList! Please confirm your account by clicking this link: < a href =" + confirmLink + "\">here</a></p>"; mailMsg.AlternateViews.Add( AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain)); mailMsg.AlternateViews.Add( AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html)); // Init SmtpClient and send SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587)); System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "Ear20090706"); smtpClient.Credentials = credentials; smtpClient.Send(mailMsg); }
public async Task <ActionResult> MyProfile() { string Id = this.User.Identity.GetUserId(); //var user = UserManager.FindById(Id); RegisteredUserVM model = new RegisteredUserVM(); model.MyProfileView = objUser.GetProfileDetails(Id); //model.SchoolList = objschool.GetSchoolList(""); return(View(model)); }
public async Task <ActionResult> MyProfile(RegisteredUserVM Item) { var user = await UserManager.FindByIdAsync(Item.MyProfileView.id); if (user == null) { return(HttpNotFound()); } user.PhoneNumber = Item.MyProfileView.PhoneNumber; user.UserName = Item.MyProfileView.Name; user.Designation = Item.MyProfileView.Designation; user.Gender = Item.MyProfileView.Gender; if ((string.IsNullOrEmpty(Item.MyProfileView.PhoneNumber)) || (string.IsNullOrEmpty(Item.MyProfileView.Name)) || (string.IsNullOrEmpty(Item.MyProfileView.Designation)) || (string.IsNullOrEmpty(Item.MyProfileView.Gender))) { if (string.IsNullOrEmpty(Item.MyProfileView.PhoneNumber)) { ModelState.AddModelError("MyProfileView.PhoneNumber", "PhoneNumber cannot be empty"); } if (string.IsNullOrEmpty(Item.MyProfileView.Name)) { ModelState.AddModelError("MyProfileView.Name", "User Name cannot be empty"); } if (string.IsNullOrEmpty(Item.MyProfileView.Designation)) { ModelState.AddModelError("MyProfileView.Designation", "Designation cannot be empty"); } if (string.IsNullOrEmpty(Item.MyProfileView.Gender)) { ModelState.AddModelError("MyProfileView.Gender", "Gender cannot be empty"); } return(View(Item)); } if (ModelState.IsValid) { var appDbContext = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); try { var result = await UserManager.UpdateAsync(user); TempData["ErrMsg"] = "Success: Profile record Updated Succesfully."; return(RedirectToAction("MyProfile", "Account")); } catch (Exception) { TempData["ErrMsg"] = "Error: Profile record could not be Updated, please contact Administrator."; } } return(View(Item)); }
public ActionResult UserList(int PageNo = 1, int PageSize = 10, string searchTerm = "") { int TotalRecords = 0; RegisteredUserVM model = new RegisteredUserVM(); model.UserList = objUser.GetUsersPaged(PageNo, PageSize, searchTerm, out TotalRecords); model.PagingInfo = new PagingInfo { CurrentPage = PageNo, ItemsPerPage = PageSize, TotalItems = TotalRecords }; if (Request.IsAjaxRequest()) { return(PartialView("_pvUserList", model)); } return(View(model)); }
public ActionResult Register(RegisteredUserVM newUser) { var userStore = new UserStore <IdentityUser>(); UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore) { UserLockoutEnabledByDefault = true, DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0), MaxFailedAccessAttemptsBeforeLockout = 5 }; var identityUser = new IdentityUser() { UserName = newUser.UserName, Email = newUser.Email }; if (ModelState.IsValid) { CaptchaHelper captchaHelper = new CaptchaHelper(); OneListCAEntities context = new OneListCAEntities(); string captchaResponse = captchaHelper.CheckRecaptcha(); if (captchaResponse == "Valid") { if (manager.FindByEmail(newUser.Email) == null) { ViewBag.CaptchaResponse = captchaResponse; IdentityResult result = manager.Create(identityUser, newUser.Password); if (result.Succeeded) { AspNetUser user = context.AspNetUsers .Where(u => u.UserName == newUser.UserName).FirstOrDefault(); AspNetRole role = new AspNetRole(); role.Id = "User"; role.Name = "User"; user.AspNetRoles.Add(context.AspNetRoles.Find(role.Id)); context.SaveChanges(); //add information of user and password to table users in core CreateTokenProvider(manager, EMAIL_CONFIRMATION); var code = manager.GenerateEmailConfirmationToken(identityUser.Id); var callbackUrl = Url.Action("ConfirmEmail", "Home", 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>"; SendGrid.sendEmail(newUser, callbackUrl); ViewBag.Result = "Please check your email to activate your account!"; } else { ViewBag.Result = "User already exist!"; } } else { ViewBag.Result = "User already exist!"; } } else { ViewBag.Result = "Registration failed!"; } } return(View()); }