From 442384ebbcc8ca8dc5e4f0eca906c412fafbc3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 27 Jun 2010 21:40:33 +0200 Subject: [PATCH] Missing files --- view/PasswordDialog.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ view/PasswordDialog.h | 31 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 view/PasswordDialog.cpp create mode 100644 view/PasswordDialog.h diff --git a/view/PasswordDialog.cpp b/view/PasswordDialog.cpp new file mode 100644 index 0000000..c6a1977 --- /dev/null +++ b/view/PasswordDialog.cpp @@ -0,0 +1,72 @@ +#include "PasswordDialog.h" + +enum {BUTTON_OK_ID=1, BUTTON_CANCEL_ID, OLD_PASSWORD_ID, NEW_PASSWORD_ID, CONFIRM_PASSWORD_ID}; + +BEGIN_EVENT_TABLE(PasswordDialog, wxDialog) +EVT_BUTTON(BUTTON_OK_ID, PasswordDialog::OnOK) +EVT_BUTTON(BUTTON_CANCEL_ID, PasswordDialog::OnCancel) +END_EVENT_TABLE() + +PasswordDialog::PasswordDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Change password")), _kiss(kiss), _wxUI(parent) +{ + wxGridBagSizer *gridBagSizer; + wxStaticText* label; + + gridBagSizer = new wxGridBagSizer(5, 3); + + label = new wxStaticText(this, -1, _("Old password ")); + gridBagSizer->Add(label, wxGBPosition(0, 0)); + _oldPassword = new wxTextCtrl(this, OLD_PASSWORD_ID); + gridBagSizer->Add(_oldPassword, wxGBPosition(0, 1)); + + label = new wxStaticText(this, -1, _("New password ")); + gridBagSizer->Add(label, wxGBPosition(1, 0)); + _newPassword = new wxTextCtrl(this, NEW_PASSWORD_ID); + gridBagSizer->Add(_newPassword, wxGBPosition(1, 1)); + + label = new wxStaticText(this, -1, _("Confirm password ")); + gridBagSizer->Add(label, wxGBPosition(2, 0)); + _confirmPassword = new wxTextCtrl(this, CONFIRM_PASSWORD_ID); + gridBagSizer->Add(_confirmPassword, wxGBPosition(2, 1)); + + _oldPassword->SetWindowStyle(wxTE_PASSWORD); + _newPassword->SetWindowStyle(wxTE_PASSWORD); + _confirmPassword->SetWindowStyle(wxTE_PASSWORD); + + wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK")); + wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel")); + gridBagSizer->Add(ok, wxGBPosition(4, 1)); + gridBagSizer->Add(cancel, wxGBPosition(4, 2)); + + SetSizer(gridBagSizer); + + Layout(); + Center(); +} + +void PasswordDialog::OnOK(wxCommandEvent& event) +{ + User* user = _kiss->GetUser(); + + if (!_kiss->IsValidUser(user->_name, _oldPassword->GetLineText(0))) + { + wxMessageBox(_("Invalid old password"), _("Error"), wxICON_ERROR | wxOK); + return; + } + + if (_newPassword->GetLineText(0) != _confirmPassword->GetLineText(0)) + { + wxMessageBox(_("Please retype new password"), _("Error"), wxICON_ERROR | wxOK); + return; + } + + _kiss->ChangePassword(_newPassword->GetLineText(0)); + + wxMessageBox(_("Password changed"), _("KissCount"), wxICON_INFORMATION | wxOK); + Close(); +} + +void PasswordDialog::OnCancel(wxCommandEvent& event) +{ + Close(); +} diff --git a/view/PasswordDialog.h b/view/PasswordDialog.h new file mode 100644 index 0000000..0f68244 --- /dev/null +++ b/view/PasswordDialog.h @@ -0,0 +1,31 @@ +#ifndef PASSWORDDIALOG_H +#define PASSWORDDIALOG_H + +#include + +#include +#include +#include +#include +#include "wxUI.h" +#include + +class wxUI; +class KissCount; + +class PasswordDialog : public wxDialog +{ +public: + PasswordDialog(KissCount* kiss, wxUI *parent); + + void OnOK(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + +private: + KissCount* _kiss; + wxUI* _wxUI; + wxTextCtrl* _oldPassword, *_newPassword, *_confirmPassword; + +DECLARE_EVENT_TABLE() +}; +#endif