예제 #1
0
        public IActionResult CreatePlayer(Models.PlayerModel player)
        {
            if (ModelState.IsValid)
            {
                if (DataLibrary.DataAccess.SQLDataAccess.GetPlayerInfo(player.Username).Username == player.Username)
                {
                    ModelState.AddModelError("Username",
                                             "The entered username already exists. Please enter a different username.");
                }
                else
                {
                    DataLibrary.Models.PlayerModel playerData = new DataLibrary.Models.PlayerModel();
                    playerData.DisplayName = player.DisplayName;
                    playerData.Email       = player.Email;
                    playerData.Password    = player.Password;
                    playerData.Username    = player.Username;

                    DataLibrary.DataAccess.SQLDataAccess.CreatePlayer(playerData);
                    HttpContext.Session.SetString("DisplayName", player.DisplayName);
                    HttpContext.Session.SetString("Username", player.Username);
                    HttpContext.Session.SetInt32("Permission", 0);

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

            return(View(player));
        }
예제 #2
0
        public IActionResult Login(LoginModel login)
        {
            DataLibrary.Models.PlayerModel player = new DataLibrary.Models.PlayerModel();
            player.Username = login.Username;
            player.Password = login.Password;
            if (DataLibrary.DataAccess.SQLDataAccess.VerifyPlayer(player))
            {
                HttpContext.Session.SetString("DisplayName", player.DisplayName);
                HttpContext.Session.SetString("Username", player.Username);
                HttpContext.Session.SetInt32("Permission", player.Permission);

                switch (player.Permission)
                {
                case 0:
                    return(RedirectToAction("PlayerHome", "Home"));

                case 1:
                    return(RedirectToAction("DevHome", "Developer"));

                case 2:
                    return(RedirectToAction("AdminHome", "Home"));

                default:
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                ModelState.AddModelError("ModelOnly", "Username/Password combination was incorrect.");
                return(View("Index", login));
            }
        }
예제 #3
0
 public IActionResult EditPlayer(Models.PlayerModel player)
 {
     DataLibrary.Models.PlayerModel playerData = new DataLibrary.Models.PlayerModel();
     playerData.Username    = HttpContext.Session.GetString("Username");
     playerData.DisplayName = player.DisplayName;
     HttpContext.Session.SetString("DisplayName", player.DisplayName);
     playerData.Password = player.Password;
     playerData.Email    = player.Email;
     DataLibrary.DataAccess.SQLDataAccess.EditPlayer(playerData);
     return(RedirectToAction("PlayerHome", "Home"));
 }
예제 #4
0
 public IActionResult EditPlayer()
 {
     Models.PlayerModel             player     = new Models.PlayerModel();
     DataLibrary.Models.PlayerModel playerData = DataLibrary.DataAccess.SQLDataAccess.GetPlayerInfo(
         HttpContext.Session.GetString("Username"));
     player.Username    = playerData.Username;
     player.DisplayName = playerData.DisplayName;
     player.Password    = playerData.Password;
     player.Email       = playerData.Email;
     return(View(player));
 }