Ejemplo n.º 1
0
    private void Login(string username)
    {
        isFirst = false;
        ParseUser.LogInAsync(username, username).ContinueWith(loginTask =>
        {
            if (loginTask.IsFaulted || loginTask.IsCanceled)
            {
                // The login failed.
                Debug.Log("ID not found, creating new ID");
                SignUp(username);
            }
            else
            {
                // Login was successful.
                ParseUser user = loginTask.Result;

                Debug.Log("Successfully logged in as user " + user.Username);

                scale_A = user.Get <float>("scale_A");
                scale_B = user.Get <float>("scale_B");
                scale_X = user.Get <float>("scale_X");
                scale_Y = user.Get <float>("scale_Y");
                lastV   = user.Get <float>("lastV");
            }
        });
    }
Ejemplo n.º 2
0
        public void CargarDatos()
        {
            ParseFile   file = user.Get <ParseFile>("photo");
            Uri         ur   = file.Url;
            BitmapImage img  = new BitmapImage(ur);

            imageControl.Source = img;
            name.Text           = user.Get <string>("name");
            mail.Text           = user.Email;
            int item = 0;

            switch (user.Get <string>("sex"))
            {
            case "Hombre":
                item = 1;
                break;

            case "Mujer":
                item = 0;
                break;
            }
            sex.SelectedIndex = item;
            char[]   delimeter = { '/', ' ', ':' };
            string[] fechaCom  = user.Get <string>("b_date").Split(delimeter);

            string fec = fechaCom[1] + "/" + fechaCom[0] + "/" + fechaCom[2];

            birth_date.Date = DateTime.Parse(fec);
            txt_user.Text   = user.Username;
        }
Ejemplo n.º 3
0
        private async Task <bool> LogIn()
        {
            try
            {
                await ParseUser.LogInAsync(tbLoginEmail.Text.ToLower(), tbLoginPassword.Text);

                ParseUser      CurrentUser    = ParseUser.CurrentUser;
                PublicUserData publicUserData = await CurrentUser.Get <PublicUserData>("publicUserData").FetchAsync();

                // Email not verified
                if (!CurrentUser.Get <bool>("emailVerified"))
                {
                    Session["LoginError"] = "Please check your email to verify your account.";
                    return(false);
                }
                // Not tutor
                else if (!Constants.UserType.IsTutor(publicUserData.UserType))
                {
                    Session["LoginError"] = "Only tutors may use the website. If you are a student, then you can open CogniStudy through your mobile device.";
                    return(false);
                }
                // Didn't pass registration test
                else if (CurrentUser.Get <int>("registrationTestScore") < 7)
                {
                    Session["LoginError"] = "You failed to acheive a sufficient score on the registration test.";
                    return(false);
                }
                // Login was successful.
                else
                {
                    mPage.PublicUserData = publicUserData;
                    //await mPage.PublicUserData.FetchAsync();
                    //mPage.Tutor = mPage.PublicUserData.Tutor;
                    //await mPage.Tutor.FetchAsync();
                    //mPage.PrivateTutorData = mPage.Tutor.PrivateTutorData;
                    //await mPage.PrivateTutorData.FetchAsync();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                // The login failed. Check the error to see why.
                string s = ex.ToString();
                Console.WriteLine(s);

                if (ex.Message.Contains("invalid login parameters"))
                {
                    Session["LoginError"] = "Username and/or password is incorrect.";
                    return(false);
                }
                else
                {
                    Session["LoginError"] = "There was an unexpected problem with your login. Please try again.";
                    return(false);
                }
            }
        }
Ejemplo n.º 4
0
 void OnEnable()
 {
     user = ParseUser.CurrentUser;
     if (user == null)
     {
         GuiManager.Instance.ShowLoginPage();
         return;
     }
     if (userName == null || sNummer == null || faculty == null)
     {
         return;
     }
     userName.text = user.Username;
     sNummer.text  = user.Get <string>("sNummer");
     faculty.text  = user.Get <string>("faculty");
 }
        public async Task ExecuteLoadQuestionDetailCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                var question = await ParseAccess.GetQuestion(questionId);

                var state     = "Closed";
                var stateFlag = question.Get <int>("stateFlag");

                if (stateFlag == (int)RequestState.Active)
                {
                    state = "Active";
                }
                else if (stateFlag == (int)RequestState.InProgress)
                {
                    state = "In Progress";
                }

                var topicObjects = question.Get <IList <ParseObject> >("topics");
                var topics       = new List <string>();
                foreach (var topic in topicObjects)
                {
                    topics.Add(topic.Get <string>("topicText"));
                }

                var ownerObject = question.Get <ParseObject>("createdBy");

                var owner = new User
                {
                    ObjectId  = ownerObject.ObjectId,
                    FirstName = ownerObject.Get <string>("firstName"),
                    LastName  = ownerObject.Get <string>("lastName"),
                    Username  = ownerObject.Get <string>("username")
                };
                Question = new Question()
                {
                    Title     = question.Get <string>("title"),
                    Body      = question.Get <string>("body"),
                    ObjectId  = question.ObjectId,
                    Topics    = topics,
                    CreatedAt = question.CreatedAt.Value + RestService.TimeDiff,
                    Owner     = owner,
                    State     = state
                };

                Answers.Clear();
                var answers = await ParseAccess.LoadAnswers(question);

                foreach (var answer in answers)
                {
                    ParseUser userObject = answer.Get <ParseUser>("createdBy");
                    var       user       = new User
                    {
                        ObjectId  = userObject.ObjectId,
                        FirstName = userObject.Get <string>("firstName"),
                        LastName  = userObject.Get <string>("lastName"),
                        Username  = userObject.Get <string>("username")
                    };

                    DateTime now = RestService.GetServerTime();
                    var      a   = new Answer
                    {
                        Body      = answer.Get <string>("body"),
                        CreatedBy = user,
                        TimeAgo   = HelperFunctions.TimeAgo(answer.UpdatedAt.Value, now)
                    };
                    Answers.Add(a);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (bufferedLog.Count > 0)
        {
            while (bufferedLog.Count > 0)
            {
                AddLog(bufferedLog.Pop());
            }
        }

        if (objectsToEnable.Count > 0)
        {
            while (objectsToEnable.Count > 0)
            {
                GameObject objectToEnable = objectsToEnable.Pop();

                if (objectToEnable.GetComponent <LoginPanel>() != null)
                {
                    refreshLoginPanel();
                }

                else if (objectToEnable.GetComponent <Button>() != null)
                {
                    objectToEnable.GetComponent <Button>().interactable = true;
                }
            }
        }

        if (globalLeaderboardUsers != null)
        {
            string tempResult = "updated " + DateTime.Now.ToString() + "\n";
            int    position   = 1;

            foreach (ParseUser user in globalLeaderboardUsers)
            {
                int score = 0;

                if (user.ContainsKey("highscore"))
                {
                    score = user.Get <int>("highscore");
                }

                tempResult = tempResult + position + ". " +
                             user.Username.Substring(0, Mathf.Min(user.Username.Length, 10)) + "  |  " + score + "\n";
                position++;
            }

            leaderboard.StoreResult(true, tempResult);
            leaderboard.UpdateResult(true);
            globalLeaderboardUsers = null;
            resetLeaderboardMode();
        }

        if (friendsLeaderboardUsers != null)
        {
            string tempResult = "updated " + DateTime.Now.ToString() + "\n";
            int    position   = 1;

            int       playerScore = 0;
            ParseUser currentUser = ParseUser.CurrentUser;
            if (currentUser.ContainsKey("highscore"))
            {
                playerScore = currentUser.Get <int>("highscore");
            }

            bool playerAdded = false;

            foreach (ParseUser user in friendsLeaderboardUsers)
            {
                int score = 0;

                if (user.ContainsKey("highscore"))
                {
                    score = user.Get <int>("highscore");
                }

                if (!playerAdded)
                {
                    if (score <= playerScore)
                    {
                        tempResult = tempResult + position + "." +
                                     currentUser.Username.Substring(0, Mathf.Min(currentUser.Username.Length, 10))
                                     + "  |  " + playerScore + "\n";

                        position++;
                        playerAdded = true;
                    }
                }

                tempResult = tempResult + position + ". " +
                             user.Username.Substring(0, Mathf.Min(user.Username.Length, 10)) + "  |  " + score + "\n";
                position++;
            }

            if (!playerAdded)
            {
                tempResult = tempResult + position + "." +
                             currentUser.Username.Substring(0, Mathf.Min(currentUser.Username.Length, 10))
                             + "  |  " + playerScore + "\n";

                position++;
                playerAdded = true;
            }

            leaderboard.StoreResult(false, tempResult);
            friendsLeaderboardUsers = null;
        }

        if (parseUserUpdatePending)
        {
            StartUpdate();
            parseUserUpdatePending = false;
        }
    }
Ejemplo n.º 7
0
 private int CurrentBooms()
 {
     return(user.Get <int>("booms"));
 }
Ejemplo n.º 8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            NavigationController.NavigationBarHidden = true;

            DismissKeyboardOnBackgroundTap();
            RegisterForKeyboardNotifications();

            usernameText.BecomeFirstResponder();
            ShouldReturn(usernameText, passwordText);
            TextFieldKeyboardIteration(usernameText, passwordText);

            forgotPasswordButton.TouchUpInside += (o, e) =>
            {
                ClearFields(usernameText, passwordText);
                NavigationScreenController(forgotPasswordViewController);
            };

            int i = 0;

            loginButton.TouchUpInside += async(sender, evt) =>
            {
                i++;
                string username = usernameText.Text;
                string password = passwordText.Text;

                switch ((!username.Equals("") && !password.Equals("")) && (!(username.Length > 10) && !(username.Length < 5)))
                {
                case true:
                    ParseUser result = null;

                    try
                    {
                        loadingOverlay = new LoadingOverlay(UIScreen.MainScreen.Bounds);
                        View.Add(loadingOverlay);

                        result = await ParseUser.LogInAsync(TrimInput(usernameText.Text), TrimInput(passwordText.Text));
                    }
                    catch (ParseException ex)
                    {
                        Debug.WriteLine(ex.GetType());
                        loadingOverlay.Hide();
                        AlertPopUp("Login failed", "Username or password incorrect", "OK");

                        if (i == 3)
                        {
                            AlertPopUp("Login failed!!", "You failed to login 3 times we suggest \nyou either Register or retrieve lost password", "OK");
                            loginButton.Enabled = false;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        loadingOverlay.Hide();
                        AlertPopUp("Login failed!!", "Please check your internet connection", "OK");
                    }

                    try
                    {
                        string name            = result.Get <string>("Name");
                        string surname         = result.Get <string>("Surname");
                        bool   isAdmin         = result.Get <bool>("IsAdmin");
                        int    vouchers        = result.Get <int>("Vouchers");
                        string userChannelName = name + surname;

                        orderViewController.GetName     = name;
                        orderViewController.GetSurname  = surname;
                        orderViewController.CurrentUser = result;
                        orderViewController.GetVouchers = vouchers;

                        orderViewController.GetUserChannelName = userChannelName;
                        // create user channel
                        var installation = ParseInstallation.CurrentInstallation;
                        //Debug.WriteLine( installation.DeviceToken);

                        if (isAdmin)
                        {
                            installation.Channels = new string[] { "Admin" };
                        }
                        else
                        {
                            installation.Channels = new string[] { userChannelName.ToLower() };
                        }

                        await installation.SaveAsync();

                        loadingOverlay.Hide();

                        if (isAdmin)
                        {
                            NavigationScreenController(adminViewController);
                        }
                        else
                        {
                            NavigationScreenController(orderViewController);
                        }
                    }
                    catch (ParseException ex)
                    {
                        loadingOverlay.Hide();
                        Debug.WriteLine(ex.Message);
                        AlertPopUp("Error", "Can't login server error, try again in a while ", "Ok");
                    }
                    catch (NullReferenceException e)
                    {
                        Debug.WriteLine(e.Message);
                    }

                    break;

                case false:

                    if (username.Length == 0 || password.Length == 0)
                    {
                        AlertPopUp("Error", "Please fill in all your credentials", "OK");
                    }
                    else if ((username.Length > 10 || username.Length < 5))
                    {
                        AlertPopUp("Error", "Username or password is too long/short", "OK");
                    }

                    break;
                }

                ClearFields(usernameText, passwordText);
            };

            registerButton.TouchUpInside += (o, e) =>
            {
                NavigationScreenController(registerViewController);
                ClearFields(usernameText, passwordText);
            };
        }