-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmoderator.cpp
178 lines (156 loc) · 5.49 KB
/
moderator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef moderator_cpp
#define moderator_cpp
// all includes
#include<bits/stdc++.h>
using namespace std;
#include "utilities.cpp"
#include "deliveryboy.cpp"
#include "customer.cpp"
#include "terminal.cpp"
// an abstract class with all its data members and functions static
class Moderator
{
public:
static char password[51];
static char const email[51]; // not allowing it to be changed by anyone
static bool login(string password)
{
// password matching
if(strcmp(password.c_str(),Moderator::password)==0)
return true;
return false;
}
static vector<string> get_customer_mails()
//retrieving customer emails to send holiday mail
{
vector<string> emails;
fstream file1("database/customer_data/emails.txt",ios::in);
string mail;
while(file1>>mail)
emails.push_back(mail);
file1.close();
return emails;
}
static vector<string> get_shopkeeper_mails()
//retrieving shopkeeper emails to send holiday mail
{
vector<string> emails;
fstream file2("database/shopkeeper_data/emails.txt", ios::in);
string mail;
while (file2>>mail)
emails.push_back(mail);
file2.close();
return emails;
}
static void mail_holiday(string date,string occassion) //mail for holiday
{
vector<string> cemails=get_customer_mails();
vector<string> smails=get_shopkeeper_mails();
for(auto str:cemails)
{
string payload = "python3 holiday_mail.py " + str + " Customer "+date+" \""+occassion+"\"";
system(payload.c_str());
}
for(auto str2:smails)
{
string payload = "python3 holiday_mail.py " + str2 + " Shopkeeper "+date+" \""+occassion+"\"";
system(payload.c_str());
}
}
static void mail_vacation(string date1,string date2,string occassion) //mail for vacation
{
vector<string> cemails=get_customer_mails();
vector<string> smails=get_shopkeeper_mails();
for(auto str:cemails)
{
string payload = "python3 vacation_mail.py " + str + " Customer "+date1+" "+date2+" \""+occassion+"\"";
system(payload.c_str());
}
for(auto str2:smails)
{
string payload = "python3 vacation_mail.py " + str2 + " Shopkeeper "+date1+" "+date2+" \""+occassion+"\"";
system(payload.c_str());
}
}
static int assign_delivery_boy() //assigning delivery boy to deliver package
{
srand(time(0));
int r= rand() % (5); //generating random number from 0 to 4
return r;
}
static void update_password() //change password
{ string old_pass,new_pass1,new_pass_final,empty_string;
cout<<"> Enter old password: "<<endl;
char waste;
scanf("%c",&waste);
old_pass=Terminal::input_password();
if(strcmp(old_pass.c_str(),Moderator::password)==0)
{
cout<<"> Enter new password:"<<endl;
new_pass1=Terminal::get_password(); //checking validity of password
if(new_pass1.empty())
{
cout<<"> Invalid password!"<<endl;
Utilities::logging_out(10);
exit(0);
}
cout<<"> Re-enter new password:"<<endl;
new_pass_final=Terminal::get_password(); //checking validity of password
if(strcmp(new_pass_final.c_str(),new_pass1.c_str())==0)
{
strcpy(Moderator::password,new_pass_final.c_str());
ofstream file("database/.modu");
file<<Moderator::password;
file.close();
}
else
{
cout<<"> Passwords do not match!";
Utilities::logging_out(10);
exit(0);
}
}
else
{
Utilities::logging_out(10);
exit(0);
}
}
static Customer get_customer(string email)
{
Customer temp;
temp.name[0]='\0';
email="database/customer_data/"+email+".ooad";
fstream file(email.c_str());
if(!file)
{
Utilities::my_exception error("> No such user found in database\n");
throw error;
}
file.read((char *)&temp,sizeof(Customer));
file.close();
return temp;
}
static void customer_write(Customer temp,string email)
{
string path="database/customer_data/"+email+".ooad";
ofstream file(path.c_str());
file.write((char*)&temp,sizeof(Customer));
file.close();
}
static void set_credit_0(string email,unsigned long long int amount_to_decrease)
{
Customer temp=get_customer(email);
cout<<"> Credit Balance changed from "<<temp.credit_balance<<" to ";
if(temp.credit_balance<amount_to_decrease)
temp.credit_balance=0;
else
temp.credit_balance=temp.credit_balance-amount_to_decrease;
cout<<temp.credit_balance<<"\n";
customer_write(temp,email);
}
virtual void create_abstract()=0; //to make it an abstract class
};
char Moderator::password[51]="Moderator#cc2019@iitj";
char const Moderator::email[51]="moderator#cc";
#endif