示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        public int PlayerAlreadyExist(string username, string email)
        {
            const int PLAYER_DOESNT_EXIST = 1, REPEATED_EMAIL = 2, REPEATED_USERNAME = 3, PLAYER_REPEATED = 4;
            int       result = PLAYER_DOESNT_EXIST;
            Player    player = null;

            try
            {
                using (UNODBEntities db = new UNODBEntities())
                {
                    player = db.Players.SingleOrDefault(a => a.email == email || a.username == username);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            if (player.email == email && player.username == username)
            {
                result = PLAYER_REPEATED;
            }
            else if (player.username == username)
            {
                result = REPEATED_USERNAME;
            }
            else if (player.email == email)
            {
                result = REPEATED_EMAIL;
            }

            return(result);
        }
示例#4
0
        /*
         * 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);
        }
示例#5
0
        public void GetAllPlayers()
        {
            List <Player> players = null;

            try
            {
                using (UNODBEntities db = new UNODBEntities())
                {
                    players = db.Players.ToList();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            PlayerCallback.GetPlayersResponse(players);
        }
示例#6
0
        public Player SearchPlayer(string username)
        {
            Player playerSearched = null;

            try
            {
                using (UNODBEntities db = new UNODBEntities())
                {
                    playerSearched = db.Players.SingleOrDefault(a => a.username == username);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(playerSearched);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }