Browse Source

LogInSystem.cpp now compiles and executes properly

- Added all public functions documentation in README.md
- Fixed missing id in the original database.txt
- Fixed missing id in Person constructor
Fixing-travis-yml
BinHong Lee 7 years ago
parent
commit
088297984c
4 changed files with 61 additions and 43 deletions
  1. +24
    -20
      LogInSystem.cpp
  2. +2
    -1
      Person.cpp
  3. +31
    -18
      README.md
  4. +4
    -4
      database.txt

+ 24
- 20
LogInSystem.cpp View File

@@ -1,6 +1,6 @@
/*
* Written by : Bin Hong Lee
* Last edited : Dec 18, 2016
* Last edited : Dec 29, 2016
*
*/

@@ -8,20 +8,19 @@
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include "Person.hpp"
#include "Person.cpp"
using namespace std;

//Declaration of functions
Person getUser(string);
Person getUser(int);
void login();
bool login();
void loggedIn(Person);
Person registration();
Person editCredentials(Person);
void update(Person);
string chgUsername();
string chgPassword();
string chgPassword(Person);
string chgEmail();
string chgPhoneNo();

@@ -59,16 +58,18 @@ int main()
cout << "Exit - 0" << endl;

cin >> userOption;
bool loggedOut = 0;

switch (userOption)
{
case 1:
while (wrongPass < 3)
while (wrongPass < 3 && !loggedOut)
{
login();
loggedOut = login();
}
break;
case 2: loggedIn(registration()); break;
case 0: break;
default:
cout << "Invalid input. Please try again." << endl;
}
@@ -78,8 +79,8 @@ int main()

while (!users.empty())
{
fout << users.back().getName() << " " << users.back().getPassword() << " " << users.back().getEmail() << " " << users.back().getPhoneNo() << " " << users.back().getId() << endl;
users.pop_back();
fout << users.begin()->getName() << " " << users.begin()->getPassword() << " " << users.begin()->getEmail() << " " << users.begin()->getPhoneNo() << " " << users.begin()->getId() << endl;
users.erase(users.begin());
}

return 0;
@@ -111,7 +112,7 @@ Person getUser(int toSearchId)
throw invalid_argument("");
}

void login()
bool login()
{
Person currentUser;
string username;
@@ -120,8 +121,8 @@ void login()
if (wrongPass > 2)
{
//Print error message and exit
cout << "Too much failed login attempt. The program will now be terminated." << endl;
return;
cout << "Too many failed login attempt. The program will now be terminated." << endl;
return false;
}

try
@@ -139,21 +140,22 @@ void login()
}
catch (invalid_argument ag)
{
cout << "Invalid username or password. Please try again.";
cout << "Invalid username or password. Please try again." << endl;

wrongPass++;
return;
return false;
}

if (!currentUser.checkPassword(password))
{
cout << "Invalid username or password. Please try again.";
cout << "Invalid username or password. Please try again." << endl;

wrongPass++;
return;
return false;
}

loggedIn(currentUser);
return true;
}

Person registration()
@@ -242,7 +244,7 @@ void loggedIn(Person currentUser)
cout << "Phone No.: " << currentUser.getPhoneNo() << endl;
break;
case 2:
editCredentials(currentUser);
currentUser = editCredentials(currentUser);
break;
case 0:
return;
@@ -270,10 +272,11 @@ Person editCredentials(Person currentUser)
{
case 1:
currentUser.setName(chgUsername());
update(currentUser);
cout << "Username is updated." << endl;
break;
case 2:
currentUser.setPassword(chgPassword());
currentUser.setPassword(chgPassword(currentUser));
cout << "Password is updated." << endl;
break;
case 3:
@@ -297,8 +300,9 @@ void update(Person newInfo)
{
if (users.at(position).getId() == newInfo.getId())
{
Person oldInfo = users.at(position);
replace(users.begin(), users.end(), oldInfo, newInfo);
users.erase(users.begin() + position);
users.insert(users.begin() + position, newInfo);
cout << users.at(position).getName() << endl;
return;
}



+ 2
- 1
Person.cpp View File

@@ -14,12 +14,13 @@ Person::Person()
}

//Complete comstructor
Person::Person(string name, string password, string email, string phoneNo)
Person::Person(string name, string password, string email, string phoneNo, int id)
{
this->name = name;
this->password = password;
this->email = email;
this->phoneNo = phoneNo;
this->id = id;
}

//Getters and setters


+ 31
- 18
README.md View File

@@ -1,4 +1,3 @@
#### __* Currently not working as intended__
#### __* Work in progress__

# Bus Ticket Management System
@@ -9,26 +8,40 @@ The original version of this program (as seen in the initial commit) was a versi

Thank you for your time in reading this. I sure hope someone would find this useful in someway someday.

## LogInSystem.cpp

### Person getUser(string);
This function will take in a string parameter that will be used to searched for a matching username in the users vector.

### Person getUser(int);
This function will take in an int parameter that will be used to searched for a matching id in the users vector.
## Person.hpp / Person.cpp

### void login();
#### Constructors

### void loggedIn(Person);
This function takes in a Person parameter after the user has logged in as that identity. It provides the user options to display and modify the information of that specific identity in the database (vector).
| Parameters | Task |
|:-----------|:-----------------------------|
| `()` | Empty constructor. |
| `string newName`<br>`string newEmail`<br>`string newPhoneNo`<br>`string newPassword`<br>`int newId` | Constructor with all parameters to populate all data slots in the object. |

### Person registration();
This function request all the required information from the user to register for a new account and add them into the users vector.
#### Functions

### Person editCredentials(Person);
This function will take in a Person parameter and make edit to it according to the user's intention. It will then return the updated Person to the caller.
| Function | Task |
|:----------------------|:-------------------------|
| `void setName(string);` | Set `name` to the new given input. |
| `string getName();` | Return `name` to caller. |
| `void setEmail(string);` | Set `email` to the new given input. |
| `string getEmail();` | Return `email` to caller. |
| `void setPhoneNo(string);` | Set `phoneNo` to the new given input. |
| `string getPhoneNo();` | Return `phoneNo` to caller. |
| `void setPassword(string);` | Set `password` to the new given input. |
| `string getPassword();` | Return `password` to the caller. |
| `bool checkPassword(string);` | Return if the given string matches `password`. |
| `int getId();` | Return `id` to the caller. |

### void update(Person);
This function will take in a Person parameter that is to be updated into the users vector. It will search for the Person in the vector with matching ID and replace it.
## LogInSystem.cpp

## Person.hpp / Person.cpp
#### Functions

| Function | Task |
|:----------------------|:-------------------------|
| `Person getUser(string);` | Takes in a string parameter that will be used to searched for a matching username in the users vector. |
| `Person getUser(int);` | Takes in an int parameter that will be used to searched for a matching id in the users vector. |
| `void login();` | |
| `void loggedIn(Person);` | Takes in a Person parameter after the user has logged in as that identity. It provides the user options to display and modify the information of that specific identity in the database (vector). |
| `Person registration();` | Request all the required information from the user to register for a new account and add them into the users vector. |
| `Person editCredentials(Person);` | Takes in a Person parameter and make edit to it according to the user's intention. It will then return the updated Person to the caller. |
| `void update(Person);` | Take in a Person parameter that is to be updated into the users vector. It will search for the Person in the vector with matching ID and replace it. |

+ 4
- 4
database.txt View File

@@ -1,4 +1,4 @@
binhonglee bhlee03655 binhonglee@hotmail.com +13479618886
binhong binhong binhong@binhong.me +14802527013
who whut wtf_is_happening@binhong.me +999999999
testing password testing@binhong.me +601111111111
binhonglee bhlee03655 binhonglee@hotmail.com +13479618886 1
binhong binhong binhong@binhong.me +14802527013 2
who whut wtf_is_happening@binhong.me +999999999 3
testing password testing@binhong.me +601111111111 4

Loading…
Cancel
Save