Пример #1
0
 public void ChangePassButton()
 {
     Users.ChangePassword(NewPassword.text); // change password of current user
     WrongPassPan.SetActive(false);
     TryagainImage.SetActive(false);
     LoginSound.Play();
     SceneManager.LoadScene("MainMenu");
 }
Пример #2
0
    public void Login()
    {
        LoginSound.Play();
        if (Users.ContainsUser(usernameField.text))                    // if the user is in the users list
        {
            User AttemptUserLogin = Users.GetUser(usernameField.text); // create a temporary user tester

            if (AttemptUserLogin.status == "blocked")                  // if this attempted user is blocked from the system
            {
                TryagainImage.SetActive(true);
                ErrorPan.SetActive(true);
                InvalidTextPrompt.text = "User is blocked from signing in.";
                TryagainButton.text    = "Okay";
            }

            if (AttemptUserLogin.password == passwordField.text && AttemptUserLogin.status != "blocked") // if the password works and they are not blocked
            {
                Users.CurrentUser          = Users.GetUser(usernameField.text);                          // attmpted user is valid and is set to current user
                Users.currentUserStartTime = Time.time;                                                  // the user has successfully logged in and save the time it was succsessful

                if (Users.CurrentUser.status == "new")                                                   // if the current user is new and has not made a password
                {
                    Users.CurrentUser.status = "normal";
                    TryagainImage.SetActive(true);
                    ChangePasswordPan.SetActive(true);
                }

                else // everything worked out perfectly
                {
                    SceneManager.LoadScene("MainMenu");
                }
            }

            else // the password did not work but the user exists
            {
                if (usernameField.text != "admin") // you cannot ban the admin
                {
                    int remainingAttempts = addFailedLogin(usernameField.text); // remaining attempts for user to try to login

                    if (remainingAttempts == 0)                                 // if they are all out of attempts
                    {
                        TryagainImage.SetActive(true);
                        ErrorPan.SetActive(true);
                        InvalidTextPrompt.text = "Too many invalid login attempts, your account is now blocked!";
                        TryagainButton.text    = "Okay";
                        Users.BlockUser(AttemptUserLogin.username);
                    }

                    else if (remainingAttempts == -1) // they try to log in evem though they are out of attempts
                    {
                        TryagainImage.SetActive(true);
                        ErrorPan.SetActive(true);
                        InvalidTextPrompt.text = "Sorry you have been blocked, talk to the admin to unblock you.";
                        TryagainButton.text    = "Okay";
                    }

                    else // you still have attempts
                    {
                        TryagainImage.SetActive(true);
                        ErrorPan.SetActive(true);
                        InvalidTextPrompt.text = "That is an invalid password. This account will be blocked after " + remainingAttempts + " more invalid password(s)!";
                    }
                }

                else // the password was not correct
                {
                    TryagainImage.SetActive(true);
                    ErrorPan.SetActive(true);
                    InvalidTextPrompt.text = "This is an invalid password.";
                }
            }
        }

        else // the user in not in the user list
        {
            TryagainImage.SetActive(true);
            ErrorPan.SetActive(true);
            InvalidTextPrompt.text = "This user does not exist.";
        }
    }