-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.cpp
More file actions
225 lines (221 loc) · 4.68 KB
/
file.cpp
File metadata and controls
225 lines (221 loc) · 4.68 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include<bits/stdc++.h>
#include"movie.cpp"
#include"title.h"
using namespace std;
void create()
{
string username;
cout<<"Enter the username:"<<endl;
cin>>username;
username=username+".txt";
ifstream file(username);
if(file.is_open())
{
cout<<"username is alredy taken"<<endl;
file.close();
return ;
}
file.close();
ofstream newfile(username);
if(!(newfile.is_open()))
{
cout<<"error in creating account."<<endl;
cout<<"please mail issue on:modhavadiyadevan189@gmail.com"<<endl;
newfile.close();
return ;
}
cout<<"enter the password:";
string password;
cin>>password;
newfile<<password<<endl;
cout<<"account created successfully"<<endl;
newfile.close();
return ;
}
void updatepassword(string username)
{
ifstream file(username);
vector<string>v;
string line;
while (getline(file,line))
{
v.push_back(line);
}
string password;
cout<<"Enter the old password";
cin>>password;
if(password!=v[0])
{
cout<<"Wrong password"<<endl;
return;
}
cout<<"Enter the New Password:"<<endl;
cin>>password;
v[0]=password;
file.close();
ofstream mfile(username,ios::trunc);
for(auto it:v)
{
mfile<<it<<endl;
}
mfile.close();
cout<<"Password Changed Successfully";
}
struct lnode
{
string data;
int i;
struct lnode* next;
lnode(string data1,int i1)
{
data=data1;
i=i1;
next=nullptr;
}
};
void history(string username)
{
struct lnode* head=nullptr;
struct lnode* mover=head;
ifstream file(username);
string line;
int i=0;
while (getline(file,line))
{
if(i==0)
{
i++;
continue;
}
if(head==nullptr)
{
head=new lnode(line,i);
mover=head;
i++;
continue;
}
struct lnode* add=new lnode(line,i);
mover->next=add;
mover=add;
i++;
}
file.close();
title();
cout<<"Watch History:"<<endl;
mover=head;
while(mover!=nullptr)
{
cout<<mover->i<<")"<<mover->data<<endl;
mover=mover->next;
}
}
void delhistory(string username)
{
ifstream file(username);
string line;
while (getline(file,line))
{
break;
}
file.close();
ofstream mfile(username,ios::trunc);
mfile<<line<<endl;
mfile.close();
cout<<"History Clear Successfully"<<endl;
}
void delaccount(string username)
{
remove(username.c_str());
cout<<"Account Deleted Successfully"<<endl;
}
void account(string username)
{
while (true)
{
title();
cout<<"1)Change the password"<<endl;
cout<<"2)View The History"<<endl;
cout<<"3)Clear History"<<endl;
cout<<"4)Rmove Account"<<endl;
cout<<"5)Back"<<endl;
char c;
cin>>c;
switch (c)
{
case '1':
updatepassword(username);
break;
case '2':
history(username);
break;
case '3':
delhistory(username);
break;
case '4':
delaccount(username);
return ;
case '5':
return;
default:
cout<<"Please Select a Valid Option"<<endl;
break;
}
}
}
void login()
{
string username;
cout<<"Enter the username:";
cin>>username;
username=username+".txt";
ifstream file(username);
if(!(file.is_open()))
{
cout<<"username does not exist"<<endl;
cout<<"you can create new account"<<endl;
file.close();
return ;
}
string password;
cout<<"Enter the password:";
cin>>password;
string line;
while(getline(file,line))
{
if(line!=password)
{
cout<<"wrong password"<<endl;
cout<<"if you forgot password then please contact admin on:modhavadiyadevan189@gmail.com"<<endl;
file.close();
return ;
}
break;
}
file.close();
cout<<"LOGIN successfully"<<endl;
loginstitle(username);
while(true)
{
title();
cout<<"enter the choice:"<<endl;
cout<<"1)Enjoy movies & serials"<<endl;
cout<<"2)account managment"<<endl;
cout<<"3)Back"<<endl;
char c;
cin>>c;
switch (c)
{
case '1':
movie(username);
break;
case '2':
account(username);
break;
case '3':
return;
default:
cout<<"Please select a valid option";
break;
}
}
}