summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-11 11:17:55 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-11 11:17:55 +0100
commitce73133c4e982db99f218bf930d82eb991ce81e3 (patch)
treecb15654419b8e912296ac9cea6deef068099910a /bucky
parentb6992903b7fe2a0aad9e6e47b0c14122b448b11c (diff)
profile
Diffstat (limited to 'bucky')
-rw-r--r--bucky/app/bucky.js18
-rw-r--r--bucky/app/router.js20
-rw-r--r--bucky/util/auth.js7
-rw-r--r--bucky/util/util.js7
4 files changed, 45 insertions, 7 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index e7455ad..ab30e85 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -324,6 +324,24 @@ var bucky = module.exports = {
})
},
+ /* PROFILE */
+
+ ensureUser: function (req, res, next){
+ var username = util.sanitizeName(req.params.username)
+ if (! username) {
+ return res.sendStatus(404)
+ }
+ db.getUserByUsername(username).then(function(user){
+ if (user) {
+ res.user = util.sanitizeUser(user)
+ next()
+ }
+ else {
+ res.sendStatus(404)
+ }
+ })
+ },
+
/* MAIL */
ensureMailboxes: function (req, res, next){
diff --git a/bucky/app/router.js b/bucky/app/router.js
index ac176bc..1dfb0bd 100644
--- a/bucky/app/router.js
+++ b/bucky/app/router.js
@@ -47,6 +47,19 @@ module.exports = function(app){
res.render("pages/editcomment", {title: "Edit comment"})
})
+ app.get("/profile",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/profile", {title: "profile: " + util.sanitize(req.user.get('username'))})
+ }
+ )
+ app.get("/profile/:username",
+ middleware.ensureAuthenticated,
+ function(req, res){
+ res.render("pages/profile", {title: "profile: " + util.sanitize(req.params.username)})
+ }
+ )
+
app.get("/api/index",
bucky.ensureLastlog,
middleware.ensureAuthenticated,
@@ -63,6 +76,13 @@ module.exports = function(app){
})
})
+ app.get("/api/user/:username",
+ middleware.ensureAuthenticated,
+ bucky.ensureUser,
+ function(req, res) {
+ res.json(res.user)
+ }
+ )
app.get("/api/keyword/:keyword",
bucky.ensureLastlog,
middleware.ensureAuthenticated,
diff --git a/bucky/util/auth.js b/bucky/util/auth.js
index 41cd155..32d77e8 100644
--- a/bucky/util/auth.js
+++ b/bucky/util/auth.js
@@ -82,13 +82,6 @@ var auth = module.exports = {
})
},
- sanitizeUser: function (req_user) {
- // sanitize user object
- var user = JSON.parse(JSON.stringify(req_user))
- delete user.password
- return user
- },
-
checkin: function (req, res) {
var user = auth.sanitizeUser(req.user)
res.json(user)
diff --git a/bucky/util/util.js b/bucky/util/util.js
index d4b6b8a..9e0f5a4 100644
--- a/bucky/util/util.js
+++ b/bucky/util/util.js
@@ -3,4 +3,11 @@ var util = module.exports = {}
util.sanitizeName = function (s){ return (s || "").replace(new RegExp("[^-_a-zA-Z0-9]", 'g'), "") }
util.sanitize = function (s){ return (s || "").replace(/<>&/g, "") }
+util.sanitizeUser = function (req_user) {
+ // sanitize user object
+ var user = JSON.parse(JSON.stringify(req_user))
+ delete user.password
+ return user
+}
+
util.now = function(){ return Math.floor( (+ new Date()) / 1000 ) }