예제 #1
0
        private async void BtnLogin_Click(object sender, EventArgs e)
        {
            if (!Locker)
            {
                Locker = true;
                var username    = txtUser.InputText;
                var password    = txtPass.InputText;
                var confirmPass = txtConfirmPass.InputText;
                //validation checkup -- could use regex I know..
                if ((username.Contains("\"") || username.Contains("\'") || username.Contains("\\")) || (username.Count() > 16 || username.Count() < 4) || (password.Contains("\"") || password.Contains("\'") || password.Contains("\\")) || (password.Count() > 24 || password.Count() < 4) || (!string.Equals(password, confirmPass)) || (string.IsNullOrEmpty(txtUser.InputText) || (string.Equals(txtUser.InputText, txtUser.Hint)) && (string.IsNullOrEmpty(txtPass.InputText) || string.Equals(txtPass.InputText, txtPass.Hint))))
                {
                    if (username.Contains("\"") || username.Contains("\'") || username.Contains("\\"))
                    {
                        new CustomMessageBox().Show("Os caracteres [ \" , \\ ,  \' ] não são permitidos, por favor tente outro username.", "Username Invalido", Sg.AccentColor);
                    }
                    else if (username.Count() > 16 || username.Count() < 4)
                    {
                        new CustomMessageBox().Show("O username deve conter entre 4 e 16 caracteres", "Username Invalido", Sg.AccentColor);
                    }
                    else if (password.Contains("\"") || password.Contains("\'") || password.Contains("\\"))
                    {
                        new CustomMessageBox().Show("Os caracteres [ \" , \\ ,  \' ] não são permitidos, por favor tente outra senha.", "Senha Invalida", Sg.AccentColor);
                    }
                    else if (password.Count() > 24 || password.Count() < 4)
                    {
                        new CustomMessageBox().Show("A senha deve conter entre 4 e 24 caracteres", "Senha Invalida", Sg.AccentColor);
                    }
                    else if (!string.Equals(password, confirmPass))
                    {
                        new CustomMessageBox().Show("As duas senhas devem coincidir", "Senha Invalida", Sg.AccentColor);
                    }
                    else if ((string.IsNullOrEmpty(txtUser.InputText) || string.Equals(txtUser.InputText, txtUser.Hint)) && (string.IsNullOrEmpty(txtPass.InputText) || string.Equals(txtPass.InputText, txtPass.Hint)))
                    {
                        new CustomMessageBox().Show("Por favor digite algo válido", "Usuario e/ou Senha", Sg.AccentColor);
                    }
                }
                else // if hasn't throw any error.
                {
                    var alreadyHas = await Sg.HasUserAsync(username);

                    if (alreadyHas)
                    {
                        new CustomMessageBox().Show("Já exste um usuário cadastrado com esse username no banco.", "User já cadastrado", Sg.AccentColor);
                        Locker = false;
                    }
                    else
                    {
                        var user = new User {
                            Username = username, Password = password
                        };
                        await Sg.CreateUserAsync(user);

                        Locker = false;
                        new CustomMessageBox().Show("Usuário cadastrado com sucesso", "Sucesso", Sg.AccentColor);
                        this.Hide();
                        DialogResult = DialogResult.OK;
                    }
                }
            }
        }
예제 #2
0
        private async void Label2_Click(object sender, EventArgs e)
        {
            //Sg.LoginForm.Hide();
            //Sg.LoginForm.ShowInTaskbar = true;
            var form2 = new Signup {
                ShowInTaskbar = false
            };
            var result = form2.ShowDialog();

            if (result == DialogResult.OK)
            {
                Sg.LoginForm.Show();
                form2.Close();
                try
                {
                    txtUser.InputText           = Sg.User.Username;
                    txtPass.InputText           = Sg.User.Password;
                    txtPass.TextInput.ForeColor = Color.Black;
                    txtUser.TextInput.ForeColor = Color.Black;
                }
                catch { }
            }
            else
            {
                if (Sg.IsValidUser)
                {
                    Sg.User.IsOnline = false;
                    await Sg.UpdateUser();
                }
                Sg.LoginForm.Close();
            }
        }
예제 #3
0
 private async void Close_Click(object sender, EventArgs e)
 {
     if (Sg.IsValidUser)
     {
         Sg.User.IsOnline = false;
         await Sg.UpdateUser();
     }
     Sg.LoginForm.Close();
 }
예제 #4
0
        private async void BtnLogin_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty(txtUser.InputText) || string.Equals(txtUser.InputText, txtUser.Hint)) && (string.IsNullOrEmpty(txtPass.InputText) || string.Equals(txtPass.InputText, txtPass.Hint)))
            {
                new CustomMessageBox().Show("Por favor digite algo válido", "Usuario e/ou Senha", Sg.AccentColor);
            }
            else if (string.IsNullOrEmpty(txtUser.InputText) || string.Equals(txtUser.InputText, txtUser.Hint))
            {
                new CustomMessageBox().Show("Por favor digite algo válido", "Usuário Invalido", Sg.AccentColor);
            }
            else if (string.IsNullOrEmpty(txtPass.InputText) || string.Equals(txtPass.InputText, txtPass.Hint))
            {
                new CustomMessageBox().Show("Por favor digite algo válido", "Senha Invalida", Sg.AccentColor);
            }
            else
            {
                var user = await Sg.GetUserAsync(txtUser.InputText);

                if (user != null)
                {
                    if (string.Equals(user.Password, txtPass.InputText))
                    {
                        user.IsOnline = true;
                        Sg.User       = user;
                        //new Thread(() => { new CustomMessageBox().Show("Senha incorreta", "Erro de Login", Sg.AccentColor); }).te;
                        await Sg.UpdateUser();

                        await GM.Initiate();

                        var game   = new GameScreen();
                        var result = game.ShowDialog();
                        if (result == DialogResult.Cancel)
                        {
                            if (Sg.IsValidUser)
                            {
                                Sg.User.IsOnline = false;
                                await Sg.UpdateUser();

                                await Sg.Reference.Child("Gamedata").Child(GM.Game.Id).PutAsync(GM.Game);
                            }
                            Sg.LoginForm.Close();
                        }
                    }
                    else
                    {
                        new CustomMessageBox().Show("Senha incorreta", "Erro de Login", Sg.AccentColor);
                    }
                }
                else
                {
                    new CustomMessageBox().Show("Usuário Inexistente", "Erro de Login", Sg.AccentColor);
                }
            }
        }