public ActionResult CheckIfSettings()
        {
            string       setting    = _dal.CheckSetting();
            CheckSetting theSetting = new CheckSetting();

            theSetting.SettingValue = setting;
            var jsonResult = Json(theSetting, JsonRequestBehavior.AllowGet);

            return(jsonResult);
        }
Example #2
0
        public ActionResult Login(LoginViewModel model)
        {
            ActionResult result = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception();
                }

                UserItem user = null;
                try
                {
                    user = _dal.GetUserItem(model.Username);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("invalid-user", "Either the username or the password is invalid.");
                    throw;
                }

                PasswordHelper passHelper = new PasswordHelper(model.Password, user.Salt);
                if (!passHelper.Verify(user.Hash))
                {
                    ModelState.AddModelError("invalid-user", "Either the username or the password is invalid.");
                    throw new Exception();
                }

                // Happy Path
                base.LogUserIn(user);
                string isSetting = _dal.CheckSetting();
                if (isSetting == "0")
                {
                    bool okay = _dal.SwitchSettings(2);
                    result = RedirectToAction("Settings", "StockGame");
                }
                else
                {
                    result = RedirectToAction("Game", "StockGame");
                }
            }
            catch (Exception)
            {
                result = View("Login");
            }

            return(result);
        }