Esempio n. 1
0
        public ActionResult LoginRegister(UserInfoModel newUser, int logCode)
        {
            if (logCode == Register)
            {
                if (ModelState.IsValid)
                {
                    if (!userInfoDAL.CheckAvailability(newUser.Email))
                    {
                        ViewBag.ErrorMessage = "Email has already been taken";
                        return(View("LoginRegister"));
                    }

                    userInfoDAL.SaveNewUser(newUser);
                    var user = userInfoDAL.SelectUserByEmail(newUser.Email);
                    Session["User"] = user;

                    return(RedirectToAction("Game", "Home"));
                }
                else
                {
                    return(View("LoginRegister"));
                }
            }
            if (logCode == Login)
            {
                string providedPassword = newUser.Password;

                if (userInfoDAL.CheckAvailability(newUser.Email) == false)
                {
                    UserInfoModel user = userInfoDAL.SelectUserByEmail(newUser.Email);

                    if (user.Password == providedPassword)
                    {
                        Session["User"] = user;
                        return(RedirectToAction("Game", "Home"));
                    }
                }
                else
                {
                    ViewBag.LoginError = "Login or password was incorrect.";
                }
            }
            return(View("LoginRegister"));
        }