Exemple #1
0
        private static bool SetSession(UserDataFetcher UDF)
        {
            /* Session. unix in file.
             * we will hash it.
             * send it to server.
             * __________________
             * check procedure:
             * if hash matches -> proceed
             * does not match -> invalid session
             */
            if (!InputValidator.ValidateId(UDF.GetId()))
            {
                return(error.SetErrorAndReturnFalse(ErrorCode.USER_NOT_FOUND));
            }
            //-----timestamp
            long unix = DataFetcher.GetServerTimeStamp();

            UserDataPusher.PushSessionFileLoggedIn(unix);
            string hashedUnix = timestampHasher.Hash(unix.ToString(), DataFetcher.GetDeviceIdentifier());

            UserDataPusher.UpdateUserSession(UDF, unix, hashedUnix);
            //System.Windows.Forms.MessageBox.Show($"hashedUnix: {hashedUnix} ({hashedUnix.Length})");

            return(true);

            /*
             * if (UDF.GetCurrentUserTimeStamp().IsTimeStampOlderThan(7 * 24)) //^extension
             *  //user has not been logged in for a whole week
             *  return true;
             * return true;
             */
        }
Exemple #2
0
 private static bool SetIsLoggedIn(UserDataFetcher UDF, bool IKnowThatThisFunctionMustGoAfterSetCurrentUser = true)
 {
     if (!InputValidator.ValidateId(UDF.GetId()))
     {
         return(error.SetErrorAndReturnFalse(ErrorCode.USER_NOT_FOUND));
     }
     if (CurrentUser.isLoggedIn)
     {
         UserDataPusher.PushSessionFileIsLoggedOut(false);
         return(true);
     }
     return(false);
 }
Exemple #3
0
 private static bool IsUserDataValid(UserDataFetcher UDF, out string lastUser)
 {
     lastUser = UserDataFetcher.GetLastUsedUsername();
     //first validate it, because user is scum
     if (!InputValidator.ValidateUsername(lastUser))
     {
         return(error.SetErrorAndReturnFalse(ErrorCode.INVALID_USERNAME)); //#throw new exception, session file corrupted
     }
     //get id. it might be email or username
     UDF.GetIdByUsernameOrEmail(lastUser, saveId: true);
     if (!InputValidator.ValidateId(UDF.GetId()))
     {
         return(error.SetErrorAndReturnFalse(ErrorCode.USER_NOT_FOUND));
     }
     return(true);
 }
Exemple #4
0
        }//logIn

        private static void SetCurrentUser(string username, UserDataFetcher UDF)
        {
            List <User>   users     = DataFetcher.GetUsersAsList();
            int           id        = UDF.GetId();
            List <string> interests = new List <string>();

            DataFetcher.GetInterestsOfCurrentUserAsList(interests, id);
            //if logged in with username
            if (InputValidator.ValidateUsername(username))
            {
                findUser();
            }
            else
            {
                System.Net.Mail.MailAddress email;
                string Email = username;
                //if logged in with email
                if (InputValidator.ValidateEmail(Email, out email))
                {
                    findUser();
                }
            }

            //find user in db with same id and set CurrentUser's fields
            void findUser()
            {
                for (var i = 0; i < users.Count; i++)
                {
                    if (id == users[i].id)
                    {
                        CurrentUser.SetUserInfo(users[i].name, users[i].id, users[i].karma, users[i].rating, users[i].profileInfo, interests);
                        break;
                    }
                }
            }
        }