示例#1
0
    public void LogIn()
    {
        string email    = GameObject.Find("EmailInputField").GetComponent <InputField>().text;
        string password = GameObject.Find("PasswordInputField").GetComponent <InputField>().text;

        password = ComputeSha256Hash(password);

        // Attempt to find a valid login by searching for the email address
        GetUserData((callback) => {
            if (callback == null)
            {
                if (logInAttempts <= 3)
                {
                    ++logInAttempts;
                    LogIn();
                }
                else
                {
                    // Incorrect email error
                    ErrorBuffer().text  = "Incorrect Credentials";
                    ErrorBuffer().color = Color.red;

                    Invoke("ClearText", 2f);
                }
            }
            else
            {
                foreach (var teacher in callback)
                {
                    PropertyInfo[] info = teacher.GetType().GetProperties();
                    if (email == info[(int)TeacherProperties.Email].GetValue(teacher, null).ToString() && password == info[(int)TeacherProperties.Password].GetValue(teacher, null).ToString())
                    {
                        // Correct login detected, set the current teacher
                        Teacher.currentTeacher = (Teacher)teacher;
                        GameObject.Find("PasswordInputField").GetComponent <InputField>().text = "";
                        if (panelHandler != null)
                        {
                            panelHandler.LoggedIn();
                        }
                    }
                    else
                    {
                        // Incorrect password error
                        ErrorBuffer().text  = "Incorrect Credentials";
                        ErrorBuffer().color = Color.red;

                        Invoke("ClearText", 2f);
                    }
                }
            }
        }, teacherEmail: email);
    }