Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "loginscreen.h"
- #include "ui_loginscreen.h"
- #include "globalclass.h"
- #include <QMessageBox>
- loginScreen::loginScreen(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::loginScreen)
- {
- ui->setupUi(this);
- GlobalClass globalCon;
- //set up for the date and time labels
- QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(setupTime()));
- timer->start(1000);
- ui->showTimeLabel->setText(globalCon.dateTime());
- //Check for database
- if(globalCon.openDB()){
- ui->loginStatusBar->setText("[+] Application is ready, please login!");
- globalCon.closeDB();
- }else{
- ui->loginStatusBar->setText("[!] Application unable to connect to the database!");
- return;
- }
- }
- loginScreen::~loginScreen()
- {
- delete ui;
- }
- void loginScreen::setupTime()
- {
- GlobalClass conn;
- ui->showTimeLabel->setText(conn.dateTime());
- }
- void loginScreen::on_loginBTN_clicked()
- {
- GlobalClass conToDB;
- qDebug() << "Login clicked";
- QString Username, Password;
- Username = ui->usernameIN->text();
- Password = ui->passwordIN->text();
- if(!conToDB.openDB())
- {
- qDebug() << "ERROR:: connecting to DB!";
- ui->loginStatusBar->setText("[!] ERROR: Connect to the database to login!");
- return;
- }
- ui->loginStatusBar->setText("[+] Connected to the database to login!");
- qDebug() << "Prepare login query";
- QSqlQuery qry;
- qry.prepare("SELECT Username, Password, Role FROM StaffUsers WHERE Username=:Username AND Password=:Password");
- qry.bindValue(":Username", Username);
- qry.bindValue(":Password", Password);
- qDebug() << qry.executedQuery();
- if(qry.exec())
- {
- //if the log in is valid perform qry.next
- qDebug() << "qry next";
- if(qry.next())
- {
- ui->loginStatusBar->setText("[+] Valid Login");
- QString msg = "Username = " + qry.value(0).toString() + " \n" +
- "Password = " + qry.value(1).toString() + " \n" +
- "Role = " +qry.value(2).toString();
- QMessageBox::warning(this, "Login was successsful", msg); // later add what type of user
- // Add link to Admin or user or guest account window
- conToDB.closeDB();
- qDebug() << "Database closed mainwindow.cpp mainwindow::loginclicked valid user window closed admin open";
- QString ckRole = qry.value(2).toString();
- if(ckRole == "admin"){
- adminDialog = new Administration();
- adminDialog->show();
- this->hide();
- }else if(ckRole == "staff"){
- this->close();
- staffControl = new StaffAccess;
- staffControl->show();
- }else if(ckRole == "guest"){
- qDebug() << "Still in development";
- }else{
- if(qry.next()){
- QMessageBox::warning(this, "Your login has failed please seek a manager!", msg);
- qDebug() << "ERROR:: INVALID SIGNIN";
- }
- }
- // if the login is not valid perform this action
- }else{
- conToDB.closeDB();
- qDebug() << "INVALID";
- ui->loginStatusBar->setText("[-] Invalid User details!");
- //Add error to Logging 0109 dateTime + Username + Password + CompName + Invalid Login
- }
- }
- }
Add Comment
Please, Sign In to add comment