Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
33c19c74c4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
209 lines (169 sloc) 7.2 KB
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
#include <openssl/md5.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#include "libsqlite.hpp"
#include "InGameMenu.cpp"
int createTeam(int Player_ID, string teamName)
{
sqlite::sqlite db( "ball.sqlite" );
auto cur = db.get_statement();
cur->set_sql( "INSERT INTO MyTeam (Player_ID, TeamName) VALUES (?,?);" );
cur->prepare();
cur->bind( 1, Player_ID );
cur->bind( 2, teamName );
cur->step();
return 0;
}
// First menu, this will be showed when u start
char menuu()
{
char choice;
MainMenu:
do
{
cout << "*******************************\n";
cout << " 1 - Login."<< endl;
cout << " 2 - Register "<< endl;
cout << " 3 - Credits."<< endl;
cout << " 4 - Exit."<< endl;
cout << " Enter your choice and press return: ";
cin >> choice;
} // end of do while
while (choice >'5' || choice<'0' );
switch (choice)
{
case '1':
{
string username, password;
bool Blog = false;
// login part
logs:
cout << "ID: ";
cin >> username ;
cout << "Password: ";
cin >> password ;
cout << "Checking Data..." << endl ;
// cheking on the data base
try
{
sqlite::sqlite db( "ball.sqlite" );
auto cur = db.get_statement();
cur->set_sql( "SELECT Player_ID FROM Player "
"WHERE UserName = ? AND Password = ?;" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, password );
int result= cur->step();
int Player_ID = cur->get_int(0); // to get the playerID (unique identification on DB)
if (result == true){
cout<<"login Sucessful"<<endl;
MenuGame(Player_ID);
}
else{
cout<<"Username of password are wrong"<<endl;
} //end else case
}
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
}
break;
}
case '2':
{
string username, email, password, veriyPassword, teamName;
regist:
// login part
cout << "ID: ";
cin >> username ;
do{
cout << "Password: ";
cin >> password ;
cout << "Insert tha same password" << endl ;
cout << "Repeat Password: ";
cin >> veriyPassword ;
}
while(password != veriyPassword);
cout << "Email: ";
cin >> email ;
cout << "Team Name: ";
cin >> teamName ;
cout << "Processing Data" << endl ;
cout << ""<< endl;
//check if already with same user name
try
{
sqlite::sqlite db( "ball.sqlite" );
auto cur = db.get_statement();
cur->set_sql( "SELECT * FROM Player "
"WHERE UserName = ? OR Email = ?;" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, email );
int result= cur->step();
if (result == true)
{
cout<<"The username or email are already in use!"<<endl;
goto regist;
}//end of if case
else
{
//registin part
cur = db.get_statement();
cur->set_sql( "INSERT INTO Player (UserName, Email,Password) "
"VALUES (?, ?,?);" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, email );
cur->bind( 3, password );
cur->step();
cout<<"Registed Sucessful"<<endl;
cout<<endl<<endl;
// // to get the playerID (unique identification on DB)
cur = db.get_statement();
cur->set_sql( "SELECT Player_ID FROM Player "
"WHERE UserName = ? AND Password = ?;" );
cur->prepare();
cur->bind( 1, username );
cur->bind( 2, password );
int result= cur->step();
int Player_ID = cur->get_int(0);
//sqlite::sqlite3_close(db);
cout<<teamName<<endl;
cout<<Player_ID<<endl;
cur = NULL;
createTeam(Player_ID,teamName); // caling to create a team
// end of getting the ID
goto MainMenu;
}//end of else
}// end of try block
catch( sqlite::exception e )
{
cerr << e.what() << endl;
return 1;
} // if registatin fails
// if checking if the user already exists fails
break;
}
case '3':
cout << "Group E7"<< endl;
cout << "Gheorghe Craciun"<< endl;
break;
case '4':
cout << "End of Program."<< endl;
break;
default:
cout << "Not a Valid Choice."<< endl;
cout << "Choose again."<< endl;
goto MainMenu;
break;
}
return 0;
}// end of menu