void MainWindow::createCenter() { userLoginButton = new QPushButton("userLogin",this); userLoginButton->setStatusTip(tr("login if your are the user")); registerButton = new QPushButton("Register",this); registerButton->setStatusTip(tr("register a new user!")); searchButton = new QPushButton(tr("search book"),this); searchButton->setStatusTip(tr("search books")); managerButton = new QPushButton(tr("manager"),this); managerButton->setStatusTip(tr("login as a manager")); exitButton = new QPushButton(tr("Exit"),this); exitButton->setStatusTip(tr("exit the applications")); MainWindowButton = new QPushButton("mainwindow",this); MainWindowButton->setVisible(false); MainWindowButton->setStatusTip(tr("return the welcome window")); QWidget *welcome = new QWidget(this); QLabel *img = new QLabel(welcome); img->setStyleSheet("border-image:url(:/imgs/1.jpg)"); img->setStatusTip(tr("Welcome to the library")); toplayout = new QHBoxLayout; toplayout->addWidget(registerButton); toplayout->addWidget(userLoginButton); toplayout->addWidget(searchButton); toplayout->addWidget(managerButton); toplayout->addWidget(exitButton); welcomelayout = new QVBoxLayout(welcome); welcomelayout->addWidget(img); welcomelayout->addLayout(toplayout); welcome->setLayout(welcomelayout); rig = new Register(this,mainmanager); manawidget = new ManagerWindow(this,mainmanager); user* tmpusr = NULL; searchwin = new SearchWindow(this,mainmanager,tmpusr,false,false); swidget = new QStackedWidget; swidget->addWidget(welcome); swidget->addWidget(rig); swidget->addWidget(manawidget); swidget->addWidget(searchwin); connect(registerButton,SIGNAL(clicked()),SLOT(regis())); connect(userLoginButton,SIGNAL(clicked()),SLOT(ulogin())); connect(MainWindowButton,SIGNAL(clicked()),SLOT(rmain())); connect(managerButton,SIGNAL(clicked()),SLOT(managerlog())); connect(searchButton,SIGNAL(clicked()),SLOT(search())); connect(rig,SIGNAL(isexit()),this,SLOT(rmain())); QWidget *mainwidget = new QWidget(this); buttomlayout = new QHBoxLayout; vlayout = new QVBoxLayout; buttomlayout->addStretch(); buttomlayout->addWidget(MainWindowButton); vlayout->addWidget(swidget); vlayout->addLayout(buttomlayout); mainwidget->setLayout(vlayout); connect(exitButton,SIGNAL(clicked()),this,SLOT(whenexit())); setCentralWidget(mainwidget); }
int settings::slogin() { if( is_logged ) return 0; QString prev_user = value("previous_user", "").toString(); login ulogin(main_win_parent, prev_user); QString hash, tmp_dir, user, pass; int u_num, ret; user_info try_user; // login while not logged while ( !is_logged ) { ret = ulogin.exec(); if( ret == QDialog::Accepted ) { ulogin.get_user_pass(user, pass); hash = get_hash(user, pass); u_num = get_user_by_name( user ); if( u_num == -1 ) { // no such user QMessageBox::information(main_win_parent, QString("Login"), QString("Involid username or password.\nTry again.")); continue; } try_user = (*users_info)[u_num]; if( get_hash(user, pass) != try_user.hash) { // login failed QMessageBox::information(main_win_parent, QString("Login"), QString("Involid username or password.\nTry again..")); continue; } // login success // check avalible of data dir tmp_dir = value("users/"+user+"/dir", "").toString(); if( check_data_dir( tmp_dir ) ) { remove("users/"+user); load_users(); QMessageBox::information(main_win_parent, QString("Login"), QString("Involid data dir in your account.\nTry again.")); continue; } user_dir.setPath( tmp_dir ); is_logged = 1; username = user; setValue("previous_user", user); return 0; } else { // not accepted -> exit ret = QMessageBox::question(main_win_parent, QString("Login"), QString("You discard login, application will be closed.\nQuit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if( ret == QMessageBox::Yes ) exit(0); } } return 10; }
int _su(int argc, char ** argv) { char * username = NULL; char * password = NULL; printf("Login: "******"Password: "******"Successfully logged in as %s\n", username); } else { printf("Bad credentials, try again...\n"); } } free(username); free(password); }
int main() { //main function int ch, b, x; char c; while(1){ system("clear"); home(); scanf("%d",&ch); if(ch == 4) break; switch(ch) { case 1: x = elogin(); if(x == 0){ printf("\tWarning!! Incorrect Password or Username\n\n"); printf("press c to continue "); getchar(); scanf("%c", &c); break; } b = 1; maintry(b); break; case 2: ulogin(); break; case 3: create(); break; case 4: exit(0); ; break; default: printf("\nwrong choice"); break; } } }
void main( ) { //main function system("clear"); start: home( ); int ch; scanf("%d", &ch); switch(ch) { case 1: ulogin( ); system("clear"); break; case 2:create( ); system("clear"); break; case 3: elogin( ); system("clear"); break; case 4:release( ); break; case 5:exit(0); default:printf("\nwrong choice"); goto start; } goto start; }