public bool DeletePlayer(Player player) { Player playerDeleted = null; bool response = false; try { using (UNODBEntities db = new UNODBEntities()) { playerDeleted = db.Players.Remove(player); db.SaveChanges(); } } catch (Exception e) { throw e; } if (playerDeleted != null) { response = true; } else if (playerDeleted == null) { response = false; } return(response); }
public bool VerifyPlayer(string username) { bool result = false; Player playerToVerify = null; try { using (UNODBEntities db = new UNODBEntities()) { playerToVerify = SearchPlayer(username); if (playerToVerify != null) { playerToVerify.isVerified = true; result = true; db.SaveChanges(); } } } catch (Exception e) { throw e; } return(result); }
/* * public void Login(string username, string password) * { * bool result = false; * Player player = null; * * try * { * using (UNODBEntities db = new UNODBEntities()) * { * try * { * player = db.Players.Where(a => a.username == username && a.password == password).FirstOrDefault(); * } * catch(Exception e) * { * throw e; * } * * if(player != null) * { * if(!IsLogged(player)) * { * result = true; * * player.isLogged = true; * * db.SaveChanges(); * } * else * { * result = false; * throw new PlayerAlreadyLoggedException(resourceManager.GetString("PlayerAlreadyLogged")); * } * }else if(player == null) * { * result = false; * } * } * } * catch(Exception e) * { * throw e; * } * * LoginCallback.LoginVerification(result); * } */ public void Login(string username, string password) { int result = 0; Player player = null; DataManager dataManager = new DataManager(); const int SUCCEDED = 1, INCORRECT_DATA = 2, PLAYER_ALREADY_LOGGED = 3, PLAYER_WITHOUT_VERIFICATION = 4; try { using (UNODBEntities db = new UNODBEntities()) { try { player = db.Players.Where(a => a.username == username).FirstOrDefault(); } catch (Exception e) { throw e; } if (player != null && dataManager.VerifyPassword(password, player.password)) { if (!IsLogged(player)) { if (CheckPlayerVerification(player)) { result = SUCCEDED; player.isLogged = true; db.SaveChanges(); } else { result = PLAYER_WITHOUT_VERIFICATION; } } else { result = PLAYER_ALREADY_LOGGED; } } else { result = INCORRECT_DATA; } } } catch (Exception e) { throw e; } LoginCallback.LoginVerification(result); }
public bool ChangePlayerToken(string username, string newToken) { bool result = false; using (UNODBEntities db = new UNODBEntities()) { Player player = SearchPlayer(username); Console.WriteLine("Old verification token: " + player.verificationToken); player.verificationToken = newToken; Console.WriteLine("New verification token: " + player.verificationToken); db.SaveChanges(); result = true; } return(result); }
public bool SetPassword(Player player, string password) { DataManager dataManager = new DataManager(); string hashedPassword = dataManager.EncryptPassword(password); try { using (UNODBEntities db = new UNODBEntities()) { player.password = hashedPassword; db.SaveChanges(); } } catch (Exception exception) { throw exception; } return(true); }
public bool ModifyPlayer(Player player, Player newPlayer) { bool result = false; Player playerSearched = null; playerSearched = SearchPlayer(player.username); using (UNODBEntities db = new UNODBEntities()) { playerSearched.username = newPlayer.username; playerSearched.password = newPlayer.password; playerSearched.verificationToken = newPlayer.verificationToken; playerSearched.name = newPlayer.name; playerSearched.lastnames = newPlayer.lastnames; playerSearched.avatarImage = newPlayer.avatarImage; db.SaveChanges(); result = true; } return(result); }