Beispiel #1
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            loginProgress.IsActive = true;
            try
            {
                aThreadWaiting = true;
                string userName = TenDNTextBox.Text.Trim();
                if (userName.Length < 1)
                {
                    TenDNTextBox.Focus(FocusState.Keyboard);
                    throw new Exception("Tên đăng nhập quá ngắn. Vui lòng kiểm tra lại.");
                }

                string password = MatKhauTextBox.Password.Trim();
                if (password.Length < 1)
                {
                    MatKhauTextBox.Focus(FocusState.Keyboard);
                    throw new Exception("Mật khẩu quá ngắn. Vui lòng kiểm tra lại.");
                }
                var result = await TaiKhoanNguoiDung.login(userName, password);

                if (result)
                {
                    isExit         = true;
                    aThreadWaiting = false;
                    this.Hide();
                }
                else
                {
                    isExit = false;
                    TenDNTextBox.Focus(FocusState.Pointer);
                    throw new Exception("Đăng nhập thất bại. Thông tin đăng nhập không chính xác.");
                }
            }
            catch (Exception ex)
            {
                textBlockError.Text = ex.Message;
                textBlockError.UpdateLayout();
            }
            loginProgress.IsActive = false;
        }
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            resetProgress.IsActive = true;
            try
            {
                string tenDangNhap = TenDangNhapTextBox.Text.Trim();
                if (tenDangNhap.Length < 1)
                {
                    TenDangNhapTextBox.Focus(FocusState.Keyboard);
                    textBlockError.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                    throw new Exception("Tên đăng nhập quá ngắn.Vui lòng kiểm tra lại.");
                }
                string email   = MailTextBox.Text.Trim();
                bool   isEmail = Regex.IsMatch(email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                if (email.Length < 1 || !isEmail)
                {
                    MailTextBox.Focus(FocusState.Keyboard);
                    textBlockError.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                    throw new Exception("Định dạng email không hợp lệ.Vui lòng kiểm tra lại.");
                }
                var result = await TaiKhoanNguoiDung.resetMatKhau(tenDangNhap, email);

                if (result)
                {
                    textBlockError.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    throw new Exception("Thông tin mật khẩu mới đã được cập đặt lại và gửi đến email đăng ký. Vui lòng kiểm tra email để nhận mật khẩu đăng nhập mới.");
                }
                else
                {
                    textBlockError.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                    throw new Exception("Thông tin tên đăng nhập và email đăng ký không hợp lệ. Vui lòng kiểm tra lại.");
                }
            }
            catch (Exception ex)
            {
                textBlockError.Text = ex.Message;
                textBlockError.UpdateLayout();
            }
            resetProgress.IsActive = false;
        }