-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.cpp
154 lines (123 loc) · 2.45 KB
/
blog.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
//#include <iostream>
//#include <string>
#include <bits/stdc++.h>
using namespace std;
#define LOGIN 1
#define SIGNUP 2
#define VISITOR 3
#define EXIT 4
#define NICKNAME_SIZE_LIMIT 20
#define PASSWORD_SIZE 5
#define PASSWORD_REPETICION_LIMIT 1
class User{
string nickname;
string password;
string email;
bool anonymous;
User(string u_nickname, string u_password, string u_email){
nickname = u_nickname;
password = u_password;
email = u_email;
}
bool valid_nickname(string u_nickname){
if(u_nickname.size() > NICKNAME_SIZE_LIMIT){
return false;
}
for(auto c : u_nickname){
if(!alfa(c)){
return false;
}
}
return true;
}
bool valid_password(string u_password){
if(u_password.size() != PASSWORD_SIZE){
return false;
}
for(auto c : u_password){
int cnt = 0;
for(auto h : u_password){
if(c == h){
cnt++;
}
}
if(cnt > PASSWORD_REPETICION_LIMIT){
return false;
}
}
return true;
}
//TODO: do this in an efficient way
//TODO: test later with a lot of cases
bool valid_email(string u_email){
return true;
}
};
//TODO: add comment structure
class Post{
string author;
string post;
vector<int> grades; //keep all grades given to a single post to later calculate it
Post(string u_author, string u_post){
author = u_author;
post = u_post;
}
//TODO: find a way to count how many way a person already comment, a person can only comment 5 times
void add_comment(){}
//TODO: learn how does this work. A person can give grades more than 1 time?
//TODO: verify problems with this implementation
//TODO: verify if the grade send if between 1 and 5
void add_grade(int grade){
grades.insert(grade);
}
int final_grade(){
int grade = 0;
for(auto i : grades){
grade += i;
}
return grade / grades.size();
}
}
//TODO: print this message red
void error_message(bool error){
if(error){
printf("invalid option");
}
}
void login(){
bool error = false;
while(true){
char op;
render_start_page();
error_message(error);
get_input(op);
if(op == LOGIN){
render_login_page();
}
else if(op == SIGNUP){
render_signup_page();
}
else if(op == VISITOR){
User current_user = User.anonymous_user();
render_initial_page(current_user);
}
else if(op == EXIT){
break;
}
else{
error == true;
}
}
}
void set_db(){
if(db_exist()){
read_db();
}
else{
create_db();
}
}
int main(){
set_db(); // le os arquivos
login();
}