Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include "loginwindow.h"
  2. #include "ui_loginwindow.h"
  3. #include "definitions.cpp"
  4. #include "mainwindow.h"
  5.  
  6.  
  7.  
  8. LoginWindow::LoginWindow(QWidget *parent) :
  9. QMainWindow(parent),
  10. ui(new Ui::LoginWindow)
  11. {
  12. ui->setupUi(this);
  13.  
  14. usersBase = QSqlDatabase::addDatabase("QSQLITE");
  15. usersBase.setDatabaseName("userDataBase.db");
  16.  
  17. if(!usersBase.open())
  18. ui->dataLabel->setText("Failed to connect");
  19. else
  20. ui->dataLabel->setText("Connected to the data base");
  21.  
  22.  
  23.  
  24. }
  25.  
  26. LoginWindow::~LoginWindow()
  27. {
  28. delete ui;
  29. }
  30.  
  31. void LoginWindow::on_pushButton_clicked()
  32. {
  33.  
  34.  
  35. QString nick, password;
  36. nick = ui->loginLine->text();
  37. password = ui->passwordLine->text();
  38.  
  39. if(!usersBase.isOpen())
  40. {
  41. qDebug()<<"Failed to open the database";
  42. return;
  43. }
  44.  
  45. QSqlQuery qry;
  46.  
  47. if(qry.exec("select * from Users where Nick = '"+nick+"' and Password = '"+password+"'" ))
  48. {
  49. int count = 0;
  50. while(qry.next())
  51. {
  52. count++;
  53. }
  54. if(count == 1)
  55. {
  56. // string nick_str = nick.toStdString();
  57. close();
  58.  
  59. if((nick.toStdString()) == admin.nick)
  60. {
  61. MainWindow mainWindow;
  62. user = &admin;
  63. mainWindow.show();
  64. }
  65.  
  66. if((nick.toStdString()) == student.nick)
  67. {
  68. user = &student;
  69. }
  70.  
  71. if((nick.toStdString()) == professor.nick)
  72. {
  73. user = &professor;
  74. }
  75.  
  76. usersBase.close();
  77.  
  78. }
  79. if(count < 1)
  80. {
  81. ui->errorLabel->setText("Wrong login or password");
  82. }
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement