Exemplo n.º 1
0
        public ActionResult ConfirmAccount(StudentsConfirmAccountVM model)
        {
            if (ModelState.IsValid)
            {
                Student student = unitOfWork.StudentRepository.GetById(model.Id);
                student.Username = model.Username;

                if (student != null)
                {
                    if (PasswordHasher.Equals(model.Password, student.Salt, student.Hash))
                    {
                        var passPhrase = PasswordHasher.Hash(model.NewPassword);
                        student.Hash        = passPhrase.Hash;
                        student.Salt        = passPhrase.Salt;
                        student.IsConfirmed = true;
                        unitOfWork.StudentRepository.Update(student);
                        unitOfWork.Save();

                        TempData.FlashMessage("Your account has been confirmed. Please, login!");
                        return(RedirectToAction("Login", "Account"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Incorrect Password");
                    }
                }
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult ConfirmAccount(int?id)
        {
            if (AuthenticationManager.LoggedUser != null)
            {
                TempData.FlashMessage("You are logged in! Please log out and then verify!", null, FlashMessageTypeEnum.Red);
                return(RedirectToAction("Index", "Home"));
            }

            if (!id.HasValue)
            {
                return(RedirectToAction("Index", "Home"));
            }

            Student student = unitOfWork.StudentRepository.GetById(id.Value);

            if (student == null || student.IsConfirmed)
            {
                return(RedirectToAction("Index", "Home"));
            }

            StudentsConfirmAccountVM model = new StudentsConfirmAccountVM();

            model.Id = id.Value;

            return(View(model));
        }