public void TestLoginFail() { UserSqlDal dal = new UserSqlDal(); UserModel a = dal.Login("Boa"); UserModel b = dal.Login("arglefargle"); UserModel c = dal.Login("Bo"); Assert.IsNull(a); Assert.IsNull(b); Assert.IsNull(c); //Assert.AreNotEqual(50000, a.CurrentMoney); //Assert.AreNotEqual("admin", a.Privilege); }
public void TestAddUser() { UserModel newUser = new UserModel(); newUser.Username = "******"; newUser.Password = "******"; newUser.ConfirmPassword = "******"; newUser.CurrentMoney = 9001; newUser.HighestMoney = 9001; newUser.IsOnline = true; newUser.Privilege = "duck"; newUser.IsTaken = false; newUser.LoginFail = false; //add salt that matches their formatting //TEST THIS TOMORROW newUser.Salt = "UBROKEIT"; UserSqlDal dal = new UserSqlDal(); bool confirm = dal.Register(newUser); Assert.AreEqual(true, confirm); List <UserModel> allUsers = new List <UserModel>(); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM users ORDER BY username DESC;", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UserModel u = new UserModel(); u.Username = Convert.ToString(reader["username"]); u.Password = Convert.ToString(reader["password"]); u.CurrentMoney = Convert.ToInt32(reader["current_money"]); u.HighestMoney = Convert.ToInt32(reader["highest_money"]); u.Privilege = Convert.ToString(reader["privilege"]); u.IsOnline = Convert.ToBoolean(reader["is_online"]); u.Salt = Convert.ToString(reader["salt"]); allUsers.Add(u); } Assert.IsNotNull(allUsers); Assert.AreEqual(4, allUsers.Count); Assert.AreEqual("Boa", allUsers[3].Username); Assert.AreEqual("aaa", allUsers[3].Password); Assert.AreEqual(50000, allUsers[2].CurrentMoney); Assert.AreEqual("omg-hash", allUsers[1].Salt); } }
public ActionResult SitAtTable(int TableID) { TableSqlDal dal = new TableSqlDal(); UserSqlDal userDal = new UserSqlDal(); string username = (string)Session["Username"]; UserModel currentUser = userDal.Login(username); Table table = dal.FindTable(TableID); UserAndTable ut = new UserAndTable(); ut.Table = table; ut.User = currentUser; return(View("TakeSeat", ut)); }
public void CreateNewUserTest() { UserSqlDal userDal = new UserSqlDal(connectionString); User u = new User() { Name = "NewUser", Password = "******" }; Company c = new Company { Name = "temporaryComp", Password = "******" }; CreateCompany(); bool createdUser = userDal.CreateNewUser(u, c); Assert.IsTrue(createdUser); }
public ActionResult Register(UserModel user) { UserSqlDal dal = new UserSqlDal(); if (ModelState.IsValid) { var newUser = new UserModel { Username = user.Username, Password = user.Password, }; List <string> existingUsers = dal.GetAllUsernames(); foreach (string name in existingUsers) { if (name == user.Username) { user.IsTaken = true; return(View("Register", user)); } } var hashProvider = new HashProvider(); user.Password = hashProvider.HashPassword(user.Password); user.Salt = hashProvider.SaltValue; dal.Register(user); Session["user"] = user; Session["username"] = user.Username; user.IsTaken = false; return(RedirectToAction("LoggedInLanding", "Home")); } else { return(View("Register", user)); } }
public ActionResult TakeSeat(UserAndTable model) { int tableID = model.Table.TableID; string userName = model.User.Username; int MoneyAdded = model.MoneyToTheTable; int MaxBuyIn = model.Table.MaxBuyIn; UserSqlDal uDal = new UserSqlDal(); UserModel user = uDal.GetUserByUserName(userName); int UserMoney = user.CurrentMoney; TableSqlDal dal = new TableSqlDal(); if (MoneyAdded <= UserMoney && MoneyAdded <= MaxBuyIn && MoneyAdded > 0) { int newMoneyValue = UserMoney - MoneyAdded; uDal.UpdateMoney(userName, newMoneyValue); bool isAdded = dal.AddPlayerToTable(tableID, userName, MoneyAdded); dal.InsertIntoHandSeat(tableID, dal.GetHandID(tableID), userName); return(RedirectToAction("JoinedTable", "Game", new { id = tableID })); } else { Table table = dal.FindTable(tableID); UserAndTable ut = new UserAndTable(); ut.Table = table; ut.User = user; ut.WasFailure = true; return(View("TakeSeat", ut)); } }
public ActionResult LeaveTable() { string userName = (string)Session["Username"]; int tableID = 0; UserSqlDal uDal = new UserSqlDal(); UserModel user = uDal.Login(userName); tableID = uDal.GetTableByPlayer(userName); TableSqlDal tDal = new TableSqlDal(); Table table = tDal.FindTable(tableID); tDal.LeaveTable(userName, tableID); user = uDal.Login(userName); if (user.CurrentMoney < 100) { return(RedirectToAction("MoneyReset", "User")); } return(RedirectToAction("LoggedInLanding", "Home")); }
public ActionResult Logout() { UserModel user = new UserModel(); user = (UserModel)Session["user"]; string username = (string)Session["username"]; UserSqlDal dal = new UserSqlDal(); bool inGame = dal.CheckStatus(username); if (inGame) { return(RedirectToAction("LeaveTable", "Table")); } if (user != null) { user.IsOnline = false; Session.Abandon(); } return(RedirectToAction("Index", "Home")); }