Inheritance: IValidatableObject
Esempio n. 1
0
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "Home");

            var user = new UserView();

            return View(user);
        }
Esempio n. 2
0
        public ActionResult ChangeEmail(UserView userView)
        {
            if (User.Identity.Name != userView.Name)
                return RedirectToAction("Index", new {name = userView.Name});

            if (!(ViewBag.success=ModelState.IsValidField("Email", userView)))
                return PartialView("_EditEmailForm", userView);

            var databaseManager = (DataBaseManager) HttpContext.Items["DataBaseManager"];

            databaseManager.User.ChangeEmail(userView.Name, userView.Email);

            return PartialView("_EditEmailForm", userView);
        }
Esempio n. 3
0
        public ActionResult ChangePassword(UserView userView, string currentPassword)
        {
            if (User.Identity.Name != userView.Name)
                return RedirectToAction("Index", new { name = userView.Name });

            if(!ModelState.IsValidField("Password", userView))
                return PartialView("_EditPasswordForm", userView);

            var databaseManager = (DataBaseManager) HttpContext.Items["DataBaseManager"];

            if (!(ViewBag.success=databaseManager.Authentication.Authenticate(userView.Name, currentPassword)))
            {
                ModelState.AddModelError("currentPassword", "");
                return PartialView("_EditPasswordForm", userView);
            }

            databaseManager.User.ChangePassword(userView.Name, userView.Password);

            return PartialView("_EditPasswordForm", new UserView(){Name = userView.Name});
        }
Esempio n. 4
0
        public ActionResult Index(UserView user)
        {
            if (!ModelState.IsValid)
                return View(user);

            try
            {
                var dataBaseManager = (DataBaseManager)HttpContext.Items["DataBaseManager"];

                dataBaseManager.User.Create(user.Name, user.Password, user.Email);

                FormsAuthentication.SetAuthCookie(user.Name, false);

                return RedirectToAction("Index", "Login");
            }
            catch
            {
                ModelState.AddModelError("", "An error occured, please try again.");
                return View();
            }
        }
Esempio n. 5
0
        public ActionResult Index(string returnUrl, UserView user)
        {
            try
            {
                var dataBaseManager = (DataBaseManager)HttpContext.Items["DataBaseManager"];

                var dbUser = dataBaseManager.User.Get(user.Name);

                if (dbUser == null)
                {
                    ModelState.AddModelError("Name", "This user does not exist.");
                    Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return View(user);
                }

                if (!dataBaseManager.Authentication.Authenticate(user.Name, user.Password))
                {
                    ModelState.AddModelError("Password", "Incorrect password.");
                    Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    return View(user);
                }

                FormsAuthentication.SetAuthCookie(user.Name, false);

                if (returnUrl != null)
                    return Redirect(returnUrl);

                return RedirectToAction("Index", "Home");
            }
            catch
            {
                ModelState.AddModelError("", "An error occured, please try again.");
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return View();
            }
        }
Esempio n. 6
0
 public ActionResult Index()
 {
     var user = new UserView();
     return View(user);
 }
Esempio n. 7
0
        public ActionResult Leave(UserView userView)
        {
            var databaseManager = (DataBaseManager)HttpContext.Items["DataBaseManager"];

            databaseManager.User.Delete(User.Identity.Name);

            FormsAuthentication.SignOut();

            return RedirectToAction("Index", "Home");
        }