protected override void OnClick(EventArgs e) { Store.CurrentUser = null; ContainerForm.AddForm(new SignInForm(), false); base.OnClick(e); }
private void lnkVisitor_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { ContainerForm.AddForm(new VisitorForm()); Close(); }
private void lnkSignUp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { ContainerForm.AddForm(new SignUpForm(), false); Close(); }
private async void btnSignIn_Click(object sender, EventArgs e) { var username = txtUsername.Text; var password = txtPassword.Text; if (username.IsNullOrEmpty()) { txtUsername.UnderlineColor = Themes.CurrentTheme switch { Theme.Light => Themes.Colors.Light.Error.ToColor(), Theme.Dark => Themes.Colors.Dark.Error.ToColor(), _ => Themes.Colors.Light.Error.ToColor() } } ; if (password.IsNullOrEmpty()) { txtPassword.UnderlineColor = Themes.CurrentTheme switch { Theme.Light => Themes.Colors.Light.Error.ToColor(), Theme.Dark => Themes.Colors.Dark.Error.ToColor(), _ => Themes.Colors.Light.Error.ToColor() } } ; if (username.IsNullOrEmpty() || password.IsNullOrEmpty()) { return; } try { Cursor = Cursors.WaitCursor; var where = new Dictionary <string, string>() { { "Username", username } }; //var user = UserRepository.Find(where, true); var user = await UserRepository.FindAsync(where, true); if (user == null || !(await Hash.CompareAsync(password, user.Password))) { MessageBox.Show(Resource_Localization.ErrorIncorrectCredentials); return; } Store.CurrentUser = user; BaseForm yetkiForm = user.Role switch { Role.Admin => new AdminForm(), Role.Staff => new StaffForm(), Role.User => new UserForm(), Role.Visitor => new VisitorForm(), _ => new VisitorForm() }; ContainerForm.AddForm(yetkiForm); Close(); } catch (Exception exception) { Debug.WriteLine(exception.Message); MessageBox.Show(Resource_Localization.ErrorUnknown); } finally { Cursor = Cursors.Default; } }
private async void btnSignUp_Click(object sender, EventArgs e) { var username = txtUsername.Text; var email = txtEmail.Text; var password = txtPassword.Text; var firstName = txtFirstName.Text; var lastName = txtLastName.Text; var phone = txtPhone.Text; var address = txtAddress.Text; if (username.IsNullOrEmpty()) { txtUsername.UnderlineColor = Themes.CurrentTheme switch { Theme.Light => Themes.Colors.Light.Error.ToColor(), Theme.Dark => Themes.Colors.Dark.Error.ToColor(), _ => Themes.Colors.Light.Error.ToColor() } } ; if (email.IsNullOrEmpty()) { txtEmail.UnderlineColor = Themes.CurrentTheme switch { Theme.Light => Themes.Colors.Light.Error.ToColor(), Theme.Dark => Themes.Colors.Dark.Error.ToColor(), _ => Themes.Colors.Light.Error.ToColor() } } ; if (password.IsNullOrEmpty()) { txtPassword.UnderlineColor = Themes.CurrentTheme switch { Theme.Light => Themes.Colors.Light.Error.ToColor(), Theme.Dark => Themes.Colors.Dark.Error.ToColor(), _ => Themes.Colors.Light.Error.ToColor() } } ; if (username.IsNullOrEmpty() || email.IsNullOrEmpty() || password.IsNullOrEmpty()) { return; } try { Cursor = Cursors.WaitCursor; var user = new UserEntity { Username = username, Email = email, Password = password, FirstName = firstName, LastName = lastName, Phone = phone, Address = address, Role = Role.User }; await UserRepository.CreateAsync(user); ContainerForm.AddForm(new SignInForm(), false); Close(); } catch (SqlException exception) when(exception.Number == 2601) { Debug.WriteLine(exception.Message); // TODO: write localized error messages MessageBox.Show(exception.Message, "SQL exception (TODO: Localize)"); } catch (Exception exception) { Debug.WriteLine(exception.Message); MessageBox.Show(Resource_Localization.ErrorUnknown); } finally { Cursor = Cursors.Default; } }