diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-14 18:54:22 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-14 18:54:22 +0200 |
| commit | e79bdedb819415792eea49de7483885046d2a368 (patch) | |
| tree | 9931fa389c1459347593155dd09a7c2cf3ecc009 /bucky/util/adminz.js | |
| parent | afd20e776ba207be9c4a00d29cb61dd3ea760eef (diff) | |
change password form working
Diffstat (limited to 'bucky/util/adminz.js')
| -rw-r--r-- | bucky/util/adminz.js | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/bucky/util/adminz.js b/bucky/util/adminz.js index 0092dc2..7224785 100644 --- a/bucky/util/adminz.js +++ b/bucky/util/adminz.js @@ -1,4 +1,3 @@ - var fs = require('fs') var db = require('../db') var util = require('./util') @@ -6,6 +5,8 @@ var upload = require('./upload') var fortune = require('../db/fortune') var middleware = require('./middleware') var privacy = require('../app/privacy') +var bucky = require('../app/bucky') +var auth = require('./auth') var adminz = module.exports = { @@ -13,28 +14,63 @@ var adminz = module.exports = { }, title: function(){ - return (Math.random() < 0.8 ? [ - fortune('admin-adj'), - fortune('admin-noun1'), - ] : [ + let title = [ + fortune('admin-name'), fortune('admin-adj'), fortune('admin-noun1'), - "and", - fortune('admin-noun2'), - ]).join(" ") + ] + if (Math.random() < 0.2) { + title = title.concat([ + "and", + fortune('admin-noun2') + ]) + } + return title.join(" ") + }, + + ensureUsernames: function (req, res, next){ + db.getUsernames().then(function(usernames){ + res.usernames = usernames + next() + }) }, route: function(app){ app.get("/adminz", + middleware.ensureAuthenticated, privacy.checkIsAdmin, function(req, res){ res.render("pages/adminz", { title: adminz.title() }) }) - // app.put("/api/checkin", - // middleware.ensureAuthenticated, - // ) + app.get("/api/admin", + middleware.ensureAuthenticated, + privacy.checkIsAdmin, + adminz.ensureUsernames, + bucky.ensureLastlog, + bucky.bumpLastSeen, + bucky.checkMail, + function(req, res){ + res.json({ + status: 'ok', + lastlog: res.lastlog, + usernames: res.usernames, + mail: res.mail, + }) + } + ) + app.put("/api/admin/password/", + middleware.ensureAuthenticated, + privacy.checkIsAdmin, + bucky.ensureUserFromBody, + auth.changePasswordDangerously, + function(req, res){ + res.json({ + status: 'ok', + }) + } + ) }, } |
