示例#1
0
        public IActionResult CheckUser([FromRoute] string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(BadRequest());
            }

            var user = db.Users.Where(u => u.UserCode == code).SingleOrDefault();

            if (user is null)
            {
                return(NotFound());
            }

            ForgotPassword item = new Models.ForgotPassword
            {
                UserCode          = user.UserCode,
                SecurityQuestion1 = user.SecurityQuestion1,
                SecurityQuestion2 = user.SecurityQuestion2,
                SecurityQuestion3 = user.SecurityQuestion3,
                SecurityQuestion4 = user.SecurityQuestion4,
                Password          = user.Password
            };

            return(Json(item));
        }
        public async Task <IActionResult> ForgotPassword(Models.ForgotPassword args)
        {
            ViewData["Title"] = "Forgot Password";
            ViewBag.ReCaptcha = captcha;

            if (!ModelState.IsValid)
            {
                return(View());
            }



            var bll_user = endUserBusiness;

            var user = await bll_user.GetByEmail(args.Email);

            if (user != null)
            {
                // Generate ConfirmationCode
                Guid   g          = Guid.NewGuid();
                string guidString = Convert.ToBase64String(g.ToByteArray());
                guidString = guidString.Replace("=", "");
                guidString = guidString.Replace("+", "");

                user.ConfirmationCode   = guidString;
                user.ConfirmationExpiry = DateTime.Now.AddHours(12);

                await bll_user.Edit(user);

                // Send email
                await smtp.SendEmail(args.Email,
                                     "Your Agenda Credentials",
                                     "Please click the link below to validate and change your password:<br/>http://" + Request.Host.Value + "/authentication/newpassword/?userid=" + user.UserId + "&code=" + guidString);

                TempData["notice"] = "Thank you. Please check your email for confirmation.";

                return(Redirect("~/"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Email is not found");
                return(View());
            }
        }
示例#3
0
 public ActionResult ForgotPassword(Models.ForgotPassword model)
 {
     if (ModelState.IsValid)
     {
         var isExist = IsEmailExist(model.EmailID);
         if (isExist == false)
         {
             ModelState.AddModelError("EmailID", "Email does not Exist");
             return(View(model));
         }
         Users  obj = dbobj.Users.Where(x => x.EmailID == model.EmailID).FirstOrDefault();
         String pwd = Membership.GeneratePassword(6, 2);
         obj.Password = pwd;
         dbobj.SaveChanges();
         SendPassword(obj.EmailID, pwd);
         TempData["Success"] = "New password has been sent to your email";
     }
     return(RedirectToAction("Login"));
 }
 public ActionResult ForgotPassword(Models.ForgotPassword forgotPassword)
 {
     if (ModelState.IsValid)
     {
         Tuple <bool, String> updateToken = SetForgotPasswordToken(forgotPassword.EmailAddress);
         if (updateToken.Item1)
         {
             var    lnkHref = Url.Action("ResetPassword", "Login", new { email = forgotPassword.EmailAddress, token = updateToken.Item2 }, "https");
             String body    = "Hi there!\nYour reset password link is " + lnkHref + ".\nClick on this link to reset your LuckyWheel admin account's password.\n\nBest regards,\nLuckyWheel Team";
             SendEmail("LuckyWheel | Reset Password Link (Admin Account)", body, forgotPassword.EmailAddress);
             return(RedirectToAction("AdminIndex", "Login"));
         }
         else
         {
             ViewBag.ErrorMessage = "No such email address is registered under LuckyWheel.";
             return(View());
         }
     }
     return(View());
 }
示例#5
0
        public ActionResult ForgotPassword(Models.ForgotPassword forgotPassword)
        {
            string email = forgotPassword.EmailId;

            Session["forgotPassword"] = null;

            if (email != null)
            {
                var model = new Job_Candidate_Application_Entities();

                var user = model.Tbl_Users.Find(email);

                if (user != null)
                {
                    Session["forgotPassword"] = "******";
                    var    guid      = Guid.NewGuid();      //create unique global id
                    string firstName = user.User_First_Name;
                    if (forgotPassword.updateGuid(email, guid.ToString()))
                    {
                        //guid was updated in database, send email to user
                        Manager.EmailManager.SendForgotPasswordEmail(firstName, email, guid.ToString());
                    }
                    return(View());
                }
                else
                {
                    Session["forgotPassword"] = "******";
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("", "Error occurred. Try again!!");
                return(View());
            }

            //something happened, send user back to home page
            return(RedirectToAction("Index", "Home"));
        }