Browse files

:K, Fix bugs...

  • Loading branch information...
1 parent 23921a4 commit 35e7e10c6f3e338c9b2f4728d565f5cd952920d1 @nycholas committed Oct 16, 2010
View
75 src/core/changepassword.cpp
@@ -31,43 +31,118 @@
ChangePassword::ChangePassword(QDialog *parent) :
QDialog(parent) {
+ qDebug() << "In ChangePassword::ChangePassword()";
setupUi(this);
+ statusTimer = new QTimer(this);
createActions();
updateWidgets();
}
ChangePassword::~ChangePassword(void) {
+ qDebug() << "In ChangePassword::~ChangePassword()";
}
void ChangePassword::changeMyPasswordAction(void) {
+ qDebug() << "In ChangePassword::changeMyPasswordAction()";
+ QSettings settings("Cenobites Technology", "Overkill");
+ settings.sync();
+ QString username = settings.value("session/username").toString();
+ QString oldPassword =
+ QCryptographicHash::hash(oldPasswordLineEdit->text().toAscii(),
+ QCryptographicHash::Sha1).toHex();
+ QString newPassword =
+ QCryptographicHash::hash(newPasswordLineEdit->text().toAscii(),
+ QCryptographicHash::Sha1).toHex();
+ QString password =
+ QCryptographicHash::hash(passwordLineEdit->text().toAscii(),
+ QCryptographicHash::Sha1).toHex();
+
+ if (!UserModel::checkPassword(username, oldPassword)) {
+ infoStatus("Old password not equals current password");
+ return;
+ } else if (newPassword != password) {
+ infoStatus("New Password not equals password");
+ return;
+ }
+
+ if (!UserModel::changePassword(username, oldPassword, newPassword)) {
+ errorStatus(qApp->tr("Failure trying to register the record."));
+ } else {
+ okStatus(qApp->tr("Changed password successfully."));
+ close();
+ }
}
void ChangePassword::cancelAction(void) {
+ qDebug() << "In ChangePassword::cancelAction()";
close();
}
void ChangePassword::createActions(void) {
+ qDebug() << "In ChangePassword::createActions()";
+ connect(statusTimer, SIGNAL(timeout()), this, SLOT(timerStatusAction()));
+
connect(changeMyPasswordPushButton, SIGNAL(released()), this,
SLOT(changeMyPasswordAction()));
connect(cancelPushButton, SIGNAL(released()), this, SLOT(cancelAction()));
}
void ChangePassword::updateWidgets(void) {
+ qDebug() << "In ChangePassword::updateWidgets()";
updateForms();
}
void ChangePassword::updateForms(void) {
+ qDebug() << "In ChangePassword::updateForms()";
clear();
focusDefault();
changeMyPasswordPushButton->setDefault(true);
}
void ChangePassword::clear(void) {
+ qDebug() << "In ChangePassword::clear()";
oldPasswordLineEdit->clear();
newPasswordLineEdit->clear();
passwordLineEdit->clear();
}
void ChangePassword::focusDefault(void) {
+ qDebug() << "In ChangePassword::focusDefault()";
oldPasswordLineEdit->setFocus();
}
+
+void ChangePassword::timerStatus(void) {
+ statusTimer->start(3000);
+}
+
+void ChangePassword::okStatus(const QString &msg) {
+ statusLabel->setText(msg);
+ statusLabel->setStyleSheet("color: green; background-color: white;"
+ "margin: 2px; padding: 3px; border: 1px solid green;");
+ statusLabel->show();
+ timerStatus();
+}
+
+void ChangePassword::infoStatus(const QString &msg) {
+ statusLabel->setText(msg);
+ statusLabel->setStyleSheet("color: blue; background-color: white;"
+ "margin: 2px; padding: 3px; border: 1px solid blue;");
+ statusLabel->show();
+ timerStatus();
+}
+
+void ChangePassword::alertStatus(const QString &msg) {
+ statusLabel->setText(msg);
+ statusLabel->setStyleSheet("color: yellow; background-color: white;"
+ "margin: 2px; padding: 3px; border: 1px solid yellow;");
+ statusLabel->show();
+ timerStatus();
+}
+
+void ChangePassword::errorStatus(const QString &msg) {
+ statusLabel->setText(msg);
+ statusLabel->setStyleSheet("color: red; background-color: white;"
+ "margin: 2px; padding: 3px; border: 1px solid red;");
+ statusLabel->show();
+ timerStatus();
+}
View
14 src/core/changepassword.h
@@ -30,9 +30,13 @@
#ifndef CHANGEPASSWORD_H
#define CHANGEPASSWORD_H
-#include <QtCore/QDebug>
+#include <QDebug>
+#include <QTimer>
+#include <QSettings>
+#include <QCryptographicHash>
#include "ui_changepassword.h"
+#include "core/models/usermodel.h"
class ChangePassword: public QDialog, private Ui::ChangePassword {
Q_OBJECT
@@ -49,6 +53,14 @@ private slots:
void clear(void);
void focusDefault(void);
+ void timerStatus(void);
+ void okStatus(const QString &msg);
+ void infoStatus(const QString &msg);
+ void alertStatus(const QString &msg);
+ void errorStatus(const QString &msg);
+
+ QTimer *statusTimer;
+
public:
ChangePassword(QDialog *parent = 0);
~ChangePassword();
View
9 src/core/login.cpp
@@ -73,7 +73,7 @@ void Login::accept(void) {
QSettings settings("Cenobites Technology", "Overkill");
settings.beginGroup("session");
settings.setValue("isAuthentic", false);
- settings.setValue("usename", qApp->tr("Annonymous"));
+ settings.setValue("username", qApp->tr("Annonymous"));
settings.endGroup();
settings.sync();
/*
@@ -103,6 +103,7 @@ bool Login::addUserDefault(void) {
void Login::readSettings(void) {
qDebug() << "In Login::readSettings()";
QSettings settings("Cenobites Technology", "Overkill");
+ settings.sync();
settings.beginGroup("login");
resize(settings.value("size", QSize(387, 250)).toSize());
move(settings.value("pos", QPoint(200, 200)).toPoint());
@@ -116,6 +117,12 @@ void Login::writeSettings(void) {
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
+ settings.sync();
+
+ settings.beginGroup("session");
+ settings.setValue("isAuthentic", false);
+ settings.endGroup();
+ settings.sync();
}
void Login::cancelAction(void) {
View
8 src/core/mainwindow.cpp
@@ -47,7 +47,7 @@ MainWindow::~MainWindow() {
void MainWindow::closeEvent(QCloseEvent *event) {
qDebug() << "In MainWindow::closeEvent()";
- //writeSettings();
+ writeSettings();
event->accept();
}
@@ -72,17 +72,21 @@ void MainWindow::changePassword(void) {
void MainWindow::logout(void) {
qDebug() << "In MainWindow::logout()";
+ //hide();
QSettings settings("Cenobites Technology", "Overkill");
+ settings.sync();
settings.setValue("session/isAuthentic", false);
if (LoginObj().exec() == QDialog::Rejected) {
close();
return;
}
+ //show();
}
void MainWindow::readSettings(void) {
qDebug() << "In MainWindow::readSettings()";
QSettings settings("Cenobites Technology", "Overkill");
+ settings.sync();
settings.beginGroup("mainwindow");
resize(settings.value("size", QSize(800, 600)).toSize());
move(settings.value("pos", QPoint(200, 200)).toPoint());
@@ -96,6 +100,7 @@ void MainWindow::writeSettings(void) {
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
+ settings.sync();
}
void MainWindow::createActions(void) {
@@ -122,6 +127,7 @@ void MainWindow::createActions(void) {
void MainWindow::updateWidgets(void) {
qDebug() << "In MainWindow::updateWidgets()";
QSettings settings("Cenobites Technology", "Overkill");
+ settings.sync();
QString username = settings.value("session/username").toString();
welcomeLabel->setText(
QString(qApp->tr("Welcome, <b>%1</b>.")).arg(username));
View
22 src/core/models/usermodel.cpp
@@ -93,6 +93,28 @@ bool UserModel::checkPassword(QString username, QString password) {
return true;
}
+bool UserModel::changePassword(int id, QString password) {
+ QSqlQuery query;
+ query.prepare("UPDATE auth_user "
+ "SET password=:password "
+ "WHERE id=:id");
+ query.bindValue(":id", id);
+ query.bindValue(":password", password);
+ return query.exec();
+}
+
+bool UserModel::changePassword(QString username, QString password,
+ QString newPassword) {
+ QSqlQuery query;
+ query.prepare("UPDATE auth_user "
+ "SET password=:newPassword "
+ "WHERE username=:username and password=:password");
+ query.bindValue(":username", username);
+ query.bindValue(":password", password);
+ query.bindValue(":newPassword", newPassword);
+ return query.exec();
+}
+
/*void UserModel::selectAll(QList<UserModel> *list) {
QSqlQuery query;
query.prepare("SELECT * FROM auth_user");
View
3 src/core/models/usermodel.h
@@ -70,6 +70,9 @@ Q_OBJECT
void setLimit(int limit);
static bool checkPassword(QString username, QString password);
+ static bool changePassword(int id, QString password);
+ static bool changePassword(QString username, QString password,
+ QString newPassword);
//static void selectAll(QList<UserModel> *list);
static void selectById(int id, UserModel *userModel);
View
11 src/core/xxxsearch.cpp
@@ -31,21 +31,25 @@
XxxSearch::XxxSearch(XxxModel *model, QDialog *parent) :
QDialog(parent) {
+ qDebug() << "In XxxSearch::XxxSearch()";
setupUi(this);
xXxModel = model;
createActions();
updateWidgets();
}
XxxSearch::~XxxSearch(void) {
+ qDebug() << "In XxxSearch::~XxxSearch()";
}
void XxxSearch::closeEvent(QCloseEvent *event) {
+ qDebug() << "In XxxSearch::closeEvent()";
emit formSearchClose();
event->accept();
}
void XxxSearch::searchAction(void) {
+ qDebug() << "In XxxSearch::searchAction()";
QString name = nameLineEdit->text();
QString description = descriptionLineEdit->text();
int isActive = isActivedCheckBox->isChecked() ? 1 : 0;
@@ -68,6 +72,7 @@ void XxxSearch::searchAction(void) {
}
void XxxSearch::cancelAction(void) {
+ qDebug() << "In XxxSearch::cancelAction()";
xXxModel->setF("");
xXxModel->setBegin(0);
emit
@@ -76,27 +81,32 @@ void XxxSearch::cancelAction(void) {
}
void XxxSearch::closeAction(void) {
+ qDebug() << "In XxxSearch::closeAction()";
emit formSearchClose();
hide();
}
void XxxSearch::createActions(void) {
+ qDebug() << "In XxxSearch::createActions()";
connect(searchPushButton, SIGNAL(released()), this, SLOT(searchAction()));
connect(cancelPushButton, SIGNAL(released()), this, SLOT(cancelAction()));
connect(closePushButton, SIGNAL(released()), this, SLOT(closeAction()));
}
void XxxSearch::updateWidgets(void) {
+ qDebug() << "In XxxSearch::updateWidgets()";
updateForms();
}
void XxxSearch::updateForms(void) {
+ qDebug() << "In XxxSearch::updateForms()";
clear();
focusDefault();
searchPushButton->setDefault(true);
}
void XxxSearch::clear(void) {
+ qDebug() << "In XxxSearch::clear()";
nameLineEdit->clear();
descriptionLineEdit->clear();
isActivedCheckBox->setChecked(true);
@@ -105,5 +115,6 @@ void XxxSearch::clear(void) {
}
void XxxSearch::focusDefault(void) {
+ qDebug() << "In XxxSearch::focusDefault()";
nameLineEdit->setFocus();
}
View
1 src/modules/admin/actform.cpp
@@ -33,7 +33,6 @@ ActForm::ActForm(ActModel *model, QDialog *parent) :
QDialog(parent) {
setupUi(this);
actModel = model;
- qDebug() << "ID:" << actModel->getId();
statusTimer = new QTimer(this);
createActions();
updateWidgets();
View
2 src/modules/admin/models/actmodel.cpp
@@ -145,7 +145,7 @@ bool ActModel::insert(void) {
QSqlQuery query;
query.prepare("INSERT INTO admin_register_act "
"(name, description, value, date_joined, is_active) "
- "VALUES (:name, :description, value, :date_joined, :is_active)");
+ "VALUES (:name, :description, :value, :date_joined, :is_active)");
query.bindValue(":name", _name);
query.bindValue(":description", _description);
query.bindValue(":value", _value);

0 comments on commit 35e7e10

Please sign in to comment.