コード例 #1
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                var userExisted = _userRepository.Query.Where(u => u.Username == user.Username).FirstOrDefault();
                if (userExisted == null)
                {
                    //TODO: Add checking if user exists already.
                    user.Password = Crypto.HashPassword(user.Password);

                    _userRepository.SaveOrUpdate(user);
                    TempData["success"] = "A user is successfully added!";
                    return RedirectToAction("Error", "Home", new { Error = "Thank you, your account has been successfully created." });
                }
                else
                {
                    return RedirectToAction("Error", "Home", new { Error = "Your Email or Username has been taken, please try another one." });
                }

            }

            return View();
        }
コード例 #2
0
        public ActionResult ResetForm(User user)
        {
            if (!String.IsNullOrWhiteSpace(user.Password))
            {
                var _user = _userRepository.GetById(user.Id);
                _user.Password = user.Password;
                _user.Password = Crypto.HashPassword(user.Password);

                _userRepository.SaveOrUpdate(_user);
                TempData["success"] = "A user is successfully edited!";
                return RedirectToAction("Index", "Home");
            }
            return RedirectToAction("Error", "Home", new { error = "Your password is not valid, please enter again." });
        }
コード例 #3
0
        public ActionResult ResetPassword(User user)
        {
            ViewBag.IsUser = false;
            User _user = _userRepository.Query.Where(u => u.Username == user.Username).FirstOrDefault();
            if (_user != null)
            {
                ViewBag.IsUser = true;
                ViewBag.Error = "";
                if (String.IsNullOrEmpty(_user.SecurityQuestion))
                {
                    return RedirectToAction("Error", "Home", new { error = " Your security question is not set, please contact administrator." });
                }
                else if (user.SecurityAnswer != _user.SecurityAnswer)
                {
                    ViewBag.Error = "Your answer is not correct, please try again";
                    return View(_user);
                }
                else if (user.SecurityAnswer == _user.SecurityAnswer)
                {
                    return RedirectToAction("ResetForm", new { Id = _user.Id });
                }
                else
                {
                    return View();
                }
            }

            return View(user);
        }
コード例 #4
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                var _user = _userRepository.Query.Where(u => u.Id == user.Id).FirstOrDefault();
                var updatedUser = AutoMapper.Mapper.Map(user, _user);

                _userRepository.SaveOrUpdate(updatedUser);

                return RedirectToAction("Details", new { id = user.Id });
            }

            return View();
        }