public IActionResult Revalidate(RevalidateModel model)
        {
            var user = UserHelper.GetUser(model.id);

            // Uses the hasher to compare the user's password and the
            // password that they just entered.
            if (Hasher.ValidatePassword(model.Password, user.Password))
            {
                // Let them update their details if they got it right.
                UpdateUser ret = new UpdateUser()
                {
                    UserID    = user.UserID,
                    Username  = user.Username,
                    Firstname = user.First_Name,
                    Lastname  = user.Last_Name
                };
                return(View("Update", ret));
            }
            // If the user got the password wrong
            // they probably aren't the user
            // so log them out.
            UserHelper.LogOut(HttpContext.Session);
            OrganisationHelper.LogOut(HttpContext.Session);
            return(RedirectToAction("Index", "Home"));
        }
 public IActionResult Logout(string returnUrl)
 {
     UserHelper.LogOut(HttpContext.Session);
     OrganisationHelper.LogOut(HttpContext.Session);
     if (!string.IsNullOrEmpty(returnUrl))
     {
         return(Redirect(returnUrl));
     }
     return(RedirectToAction("Index", "Home"));
 }
        public IActionResult Update(UpdateUser model)
        {
            // Check if the user has enetered correct details
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Check that the user hasn't passed a XSS attack
            // or tried to update form data.
            if (UserHelper.GetUserId(HttpContext.Session) == model.UserID)
            {
                var user = UserHelper.GetUser(model.UserID);

                // Checks if the user has updated their password
                if (!string.IsNullOrWhiteSpace(model.Password) && !string.IsNullOrWhiteSpace(model.VerifyPassword))
                {
                    // If the password and verification are not the same
                    // return the model with an error.
                    if (model.Password != model.VerifyPassword)
                    {
                        return(View(model));
                    }
                    // if they are update the users password.
                    user.Password = Hasher.Hash(model.Password);
                }
                // Update their names to things that have changed.
                user.First_Name = model.Firstname;
                user.Last_Name  = model.Lastname;
                user.Username   = model.Username;

                // Update the database
                DatabaseConnector.Update(user);

                return(View("Index", user));
            }
            // If their is an XSS attempt log the user out.
            UserHelper.LogOut(HttpContext.Session);
            OrganisationHelper.LogOut(HttpContext.Session);
            return(RedirectToAction("Index", "Home"));
        }