-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
226 lines (77 loc) · 4.53 KB
/
README
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
226
# Reserve Room
========
This is a Simple API Based Web Application to reserve meeting rooms.
# Features
--------
- Api Based
- Using Regex
- MVC
- JWT Token
# How to start using it
------------
Simply just use following command:
TZ=UTC node server.js
# Project Skeleton
------------
we have several directories and files. let's talk about them:
1- Config : has all static information for project like database settings and jwt token secret
2- Middleware : check token and signup before controller
3- Controllers : control inputs and confirm them for reserve and check login informations
4- Models : has Models (User and Resreve) objects with their own fields (Sequelize ORM Objects)
5- Views : has all templates and their dependencies (style.css and converter.js). we use these templates late in routing part (Rendering)
6- Routes : Reserve and auth Routes
# Config
------------
auth.config.js -> this file contain JWT Token Secret key and we used this file in auth.Jwt.js and auth.controller.js
reserve.config.js -> this file contain reserve settings. Resreve Period (time_period) and Maximum Resreve day distance from today (day_period)
db.config.js -> this file contain all information about our mysql database system (login credits and timezone and pool settings) -> for more information please visite the file
# Middleware
------------
authJwt.js -> this file has two methods :
1 - isValidToken (Return True or False) -> check if given token is valid or not
2 - verifyToken (Return Status and Set User ID based on TOKEN)
verifySignup.js -> this file has two methods and one function :
1- check function as it seems, check if given username or email are already taken or not (Return True or False)
2- usernameOrEmailExists (For API Results) -> use check function and send json message to the use-agent
3- usernameOrEmailExistsFront (For Front Results) -> use check function and redirect user to proper route
TODO : Check email and username validation inputs
index.js -> merge verifySignup and authJwt into one module
# Controllers (After Middleware)
------------
auth.controller.js -> this file contain three methods:
1 - signup (for api) : create user with given information and return proper json message
2 - signupFront (for front) : create user with given information and redirect user to proper route
reserve.controller.js -> this file contain two methods and one function:
1 - changeTimezone(Date Object , "TIME ZONE NAME") -> Convert given DateObject to a new DateObject with new timezone
2 - reserve -> reserve given date and check validation
3 - getReserves -> get all reserves after today (including today)
# Models
------------
user.model.js -> this file contain User Object (ORM Object)
reserve.model.js -> this file contain Reserve Object (ORM Object)
index.js -> merge these files into one
# Views
------------
index.ejs -> template for index page
login.ejs -> template for login page
signup.ejs -> template for signup page
reserve.ejs -> template for Reserve Page :
We used ajax to get and post reserves (Frontend):
for this we have used Jquery Ajax function and pass token from headers
footer.ejs & headers.ejs -> contain all html and css and javascript frontend dependencies
Convertjs -> script to convert current date to jalali calender (not used yet)
style.css -> some styles for html pages
# Routes
------------
auth.routes.js -> in this file we handle routes that relates to auth process
"/api/auth/signup" (POST METHOD) -> signup in api endpoint. first check if username or email exists or not and then use controller.signup method
"/api/auth/signin" (POST METHOD) -> signin user in api endpoint. using controller.signin for doing that
"/loginRoute" (POST METHOD) -> signin user in frontend. using controller.signinFront for doing that
"/signupRoute" (POST METHOD) -> signup in frontend. first check if username or email exists or not and then use controller.signup method
reserve.routes.js -> in this file we handle routes that relates to reserve process
"/api/reserve" (POST METHOD) -> reserve given time after token verify. use controller.reserve
"/api/reserves" (GET METHOD) -> get all reserves after today (including) (after token verify). using controller.getReserves
# Server.js
------------
we use ejs template engine. for more information: https://ejs.co/#docs
in every front path before routing we check if user is loggedin or not (using tokenValidModule.isValidToken)