Browse Source

Being able to delete an account.

Kiru 9 months ago
parent
commit
615296f752
7 changed files with 91 additions and 41 deletions
  1. 6
    0
      controllers/authController.js
  2. 38
    39
      database/db.js
  3. 1
    0
      lolisafe.js
  4. 1
    0
      pages/dashboard.html
  5. 11
    2
      pages/faq.html
  6. 33
    0
      public/js/dashboard.js
  7. 1
    0
      routes/api.js

+ 6
- 0
controllers/authController.js View File

@@ -88,4 +88,10 @@ authController.changePassword = async (req, res, next) => {
88 88
 	});
89 89
 };
90 90
 
91
+authController.delete = async (req, res, next) => {
92
+	const user = await utils.authorize(req, res);
93
+
94
+	await db.table('users').where('id', user.id).update({ enabled: 0 });
95
+	return res.json({ success: true });
96
+};
91 97
 module.exports = authController;

+ 38
- 39
database/db.js View File

@@ -1,53 +1,52 @@
1
-let init = function(db){
2
-
1
+let init = function(db) {
3 2
 	// Create the tables we need to store galleries and files
4
-	db.schema.createTableIfNotExists('albums', function (table) {
5
-		table.increments()
6
-		table.integer('userid')
7
-		table.string('name')
8
-		table.string('identifier')
9
-		table.integer('enabled')
10
-		table.integer('timestamp')
3
+	db.schema.createTableIfNotExists('albums', table => {
4
+		table.increments();
5
+		table.integer('userid');
6
+		table.string('name');
7
+		table.string('identifier');
8
+		table.integer('enabled');
9
+		table.integer('timestamp');
11 10
 		table.integer('editedAt');
12 11
 		table.integer('zipGeneratedAt');
13
-	}).then(() => {})
12
+	}).then(() => {});
14 13
 
15
-	db.schema.createTableIfNotExists('files', function (table) {
16
-		table.increments()
17
-		table.integer('userid')
18
-		table.string('name')
19
-		table.string('original')
20
-		table.string('type')
21
-		table.string('size')
22
-		table.string('hash')
23
-		table.string('ip')
24
-		table.integer('albumid')
25
-		table.integer('timestamp')
26
-	}).then(() => {})
14
+	db.schema.createTableIfNotExists('files', table => {
15
+		table.increments();
16
+		table.integer('userid');
17
+		table.string('name');
18
+		table.string('original');
19
+		table.string('type');
20
+		table.string('size');
21
+		table.string('hash');
22
+		table.string('ip');
23
+		table.integer('albumid');
24
+		table.integer('timestamp');
25
+	}).then(() => {});
27 26
 
28
-	db.schema.createTableIfNotExists('users', function (table) {
29
-		table.increments()
30
-		table.string('username')
31
-		table.string('password')
32
-		table.string('token')
33
-		table.integer('enabled')
34
-		table.integer('timestamp')
27
+	db.schema.createTableIfNotExists('users', table => {
28
+		table.increments();
29
+		table.string('username');
30
+		table.string('password');
31
+		table.string('token');
32
+		table.integer('enabled');
33
+		table.integer('timestamp');
35 34
 	}).then(() => {
36
-		db.table('users').where({username: 'root'}).then((user) => {
37
-			if(user.length > 0) return
35
+		db.table('users').where({ username: 'root' }).then(user => {
36
+			if (user.length > 0) return;
38 37
 
39
-			require('bcrypt').hash('root', 10, function(err, hash) {
40
-				if(err) console.error('Error generating password hash for root')
38
+			require('bcrypt').hash('root', 10, (err, hash) => {
39
+				if (err) console.error('Error generating password hash for root');
41 40
 
42 41
 				db.table('users').insert({
43 42
 					username: 'root',
44 43
 					password: hash,
45 44
 					token: require('randomstring').generate(64),
46 45
 					timestamp: Math.floor(Date.now() / 1000)
47
-				}).then(() => {})
48
-			})
49
-		})
50
-	})
51
-}
46
+				}).then(() => {});
47
+			});
48
+		});
49
+	});
50
+};
52 51
 
53
-module.exports = init
52
+module.exports = init;

+ 1
- 0
lolisafe.js View File

@@ -28,6 +28,7 @@ safe.enable('view cache');
28 28
 let limiter = new RateLimit({ windowMs: 5000, max: 2 });
29 29
 safe.use('/api/login/', limiter);
30 30
 safe.use('/api/register/', limiter);
31
+safe.use('/api/delete/', limiter);
31 32
 
32 33
 safe.use(bodyParser.urlencoded({ extended: true }));
33 34
 safe.use(bodyParser.json());

+ 1
- 0
pages/dashboard.html View File

@@ -85,6 +85,7 @@
85 85
 							<ul class="menu-list">
86 86
 								<li><a id="itemTokens" onclick="panel.changeToken()">Change your token</a></li>
87 87
 								<li><a id="itemPassword" onclick="panel.changePassword()">Change your password</a></li>
88
+								<li><a id="itemPassword" onclick="panel.deleteAccount()">Delete your account</a></li>
88 89
 								<li><a id="itemLogout"onclick="panel.logout()">Logout</a></li>
89 90
 							</ul>
90 91
 						</aside>

+ 11
- 2
pages/faq.html View File

@@ -99,8 +99,17 @@
99 99
 							Send us an email at <a href="mailto:contact@lolisareinthe.club">contact@lolisareinthe.club</a> and let's talk!
100 100
 						</div>
101 101
 					</article>
102
-					
103
-				</div>
102
+					<h2 class='subtitle'>Fews informations</h2>
103
+					<article class="message">
104
+						<div class="message-body">
105
+							<ul>
106
+								<li>Our data is hosted at OneProvider, in France. Content that's illegal in Germany, France or America (This includes loli/shota of ANY kind) are in its entirety prohibed.</li>
107
+								<li>Your information will not be used for advertising pruposes or be sold. We are not using any types of analytics.</li>
108
+								<li>Retain server logs containing the IP address of all requests to this server no more than 30 days.</li>
109
+								<li>Our site, products and services are all directed to people who are at least 13 years old.</li>
110
+							</ul>
111
+						</div>
112
+					</article>
104 113
 			</div>
105 114
 		</section>
106 115
 

+ 33
- 0
public/js/dashboard.js View File

@@ -257,6 +257,39 @@ panel.deleteFile = function(id){
257 257
 	);
258 258
 }
259 259
 
260
+panel.deleteAccount = function(){
261
+	swal({
262
+		title: "Are you sure?",
263
+		text: "You wont be able to recover your account!",
264
+		type: "warning",
265
+		showCancelButton: true,
266
+		confirmButtonColor: "#ff3860",
267
+		confirmButtonText: "Yes, delete it!",
268
+		closeOnConfirm: false
269
+	},
270
+		function(){
271
+
272
+			axios.post('/api/delete')
273
+			.then(function (response) {
274
+
275
+				if(response.data.success === false){
276
+					if(response.data.description === 'No token provided') return panel.verifyToken(panel.token);
277
+					else return swal("An error ocurred", response.data.description, "error");		
278
+				}
279
+
280
+				swal("Deleted!", "Your account has been deleted", "success");
281
+				panel.logout();
282
+
283
+			})
284
+			.catch(function (error) {
285
+				return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error");
286
+				console.log(error);
287
+			});
288
+
289
+		}
290
+	);
291
+}
292
+
260 293
 panel.getAlbums = function(){
261 294
 
262 295
 	axios.get('/api/albums').then(function (response) {

+ 1
- 0
routes/api.js View File

@@ -14,6 +14,7 @@ routes.get('/check', (req, res, next) => {
14 14
 
15 15
 routes.post('/login', (req, res, next) => authController.verify(req, res, next));
16 16
 routes.post('/register', (req, res, next) => authController.register(req, res, next));
17
+routes.post('/delete', (req, res, next) => authController.delete(req, res, next));
17 18
 routes.post('/password/change', (req, res, next) => authController.changePassword(req, res, next));
18 19
 routes.get('/uploads', (req, res, next) => uploadController.list(req, res, next));
19 20
 routes.get('/uploads/:page', (req, res, next) => uploadController.list(req, res, next));

Loading…
Cancel
Save