示例#1
0
        private FollwitApi(string username, string hashedPassword, string apiUrl, IFollwitProxy proxy)
        {
            User = new FitUser();
            User.Name = username;
            User.HashedPassword = hashedPassword;

            ApiUrl = apiUrl;
            Proxy = proxy;
        }
示例#2
0
        private void LoginNewUserPanel_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible) {
                SetStatus();

                usernameTextBox.Focus();
                usernameTextBox.Text = "";
                emailTextBox.Text = "";
                passwordTextBox.Text = "";
                verifyPasswordTextBox.Text = "";
                privateCheckBox.Checked = false;

                ValidatedUser = null;
                api = null;

                if (ParentForm != null) {
                    this.ParentForm.AcceptButton = createAccountOkButton;
                    this.ParentForm.CancelButton = backButton;
                    backButton.DialogResult = DialogResult.None;
                }
            }
            else {
                if (ParentForm != null) {
                    this.ParentForm.AcceptButton = null;
                    this.ParentForm.CancelButton = null;
                }
            }
        }
示例#3
0
        private void CreateUser()
        {
            // set the status label to inform the user of whats happening
            statusLabel.ForeColor = defaultLabelColor;
            statusLabel.Text = "Creating new account...";
            statusLabel.Visible = true;

            // disable the log in button so the user doesnt double tap it
            createAccountOkButton.Enabled = false;

            ThreadStart actions = delegate {
                try {
                    string username = usernameTextBox.Text;
                    string password = passwordTextBox.Text;

                    bool success = FollwitApi.CreateUser(username, password, emailTextBox.Text, "en", privateCheckBox.Checked, ApiUrl);

                    if (success) {
                        api = FollwitApi.Login(username, FollwitApi.HashPassword(password), ApiUrl);
                        ValidatedUser = api.User;
                    }
                    else {
                        api = null;
                        ValidatedUser = null;
                    }
                }
                catch (Exception ex) {
                    UnexpectedError(ex);
                    return;
                }

                CreateUserDone();
            };

            Thread verifyLoginThread = new Thread(actions);
            verifyLoginThread.Name = "Authentication Thread";
            verifyLoginThread.IsBackground = true;
            verifyLoginThread.Start();
        }
示例#4
0
        // handle actions triggered by the new user panel
        void newUserPanel_ActionSelected(LoginNewUserPanel.Action action)
        {
            newUserPanel.Visible = false;

            switch (action) {
                case LoginNewUserPanel.Action.BACK:
                    welcomePanel.Visible = true;
                    break;
                case LoginNewUserPanel.Action.VALIDATED:
                    successPanel.Visible = true;
                    ValidatedUser = newUserPanel.ValidatedUser;
                    break;
            }
        }
        private void LoginExistingUserPanel_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible) {
                ClearStatus();

                usernameTextBox.Focus();
                usernameTextBox.Text = "";
                passwordTextBox.Text = "";

                ValidatedUser = null;
                api = null;

                if (ParentForm != null) {
                    this.ParentForm.AcceptButton = signInOkButton;
                    this.ParentForm.CancelButton = backButton;
                    backButton.DialogResult = DialogResult.None;
                }
            }
            else {
                if (ParentForm != null) {
                    this.ParentForm.AcceptButton = null;
                    this.ParentForm.CancelButton = null;
                }
            }
        }
        private void LoginDone()
        {
            if (InvokeRequired) {
                Invoke(new InvokeDelegate(LoginDone));
                return;
            }

            if (api == null) {
                statusLabel.ForeColor = Color.Red;
                statusLabel.Text = "Invalid username or password.";
                statusLabel.Visible = true;

                signInOkButton.Text = "Sign In";
                signInOkButton.Enabled = true;
                verified = false;
            }
            else {
                statusLabel.ForeColor = Color.Green;
                statusLabel.Text = "Account successfully validated!";
                statusLabel.Visible = true;

                signInOkButton.Text = "OK";
                signInOkButton.Enabled = true;
                verified = true;

                ValidatedUser = api.User;
                if (ActionSelected != null) ActionSelected(Action.VALIDATED);
            }
        }