mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
web login works, with access settings for certain modules [#538]
This commit is contained in:
parent
78b9bf2525
commit
652a9ef7a3
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": [ "report", "users", "web" ],
|
"dependencies": [ "report", "users", "web" ],
|
||||||
"dbType": "redis"
|
"dbType": "redis",
|
||||||
|
"requireWebLogin": true,
|
||||||
|
"webAccess": "power_users"
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,16 @@ var webInterface = function(dbot) {
|
|||||||
this.app.use(this.app.router);
|
this.app.use(this.app.router);
|
||||||
|
|
||||||
passport.serializeUser(function(user, done) {
|
passport.serializeUser(function(user, done) {
|
||||||
done(null, user);
|
console.log('serialising ' + user);
|
||||||
|
done(null, user.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
passport.deserializeUser(function(obj, done) {
|
passport.deserializeUser(function(id, done) {
|
||||||
done(null, obj);
|
dbot.api.users.getUser(id, function(user) {
|
||||||
|
console.log(id);
|
||||||
|
console.log(user);
|
||||||
|
done(null, user);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
passport.use(new LocalStrategy(function(username, password, callback) {
|
passport.use(new LocalStrategy(function(username, password, callback) {
|
||||||
@ -68,6 +73,10 @@ var webInterface = function(dbot) {
|
|||||||
var shim = Object.create(resp);
|
var shim = Object.create(resp);
|
||||||
shim.render = (function(view, one, two) {
|
shim.render = (function(view, one, two) {
|
||||||
// Render with express.js
|
// Render with express.js
|
||||||
|
_.extend(one, {
|
||||||
|
'name': dbot.config.name,
|
||||||
|
'user': req.user
|
||||||
|
});
|
||||||
resp.render(this.module + '/' + view, one, two);
|
resp.render(this.module + '/' + view, one, two);
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
shim.render_core = resp.render;
|
shim.render_core = resp.render;
|
||||||
@ -92,6 +101,7 @@ var webInterface = function(dbot) {
|
|||||||
this.app.get('/', function(req, res) {
|
this.app.get('/', function(req, res) {
|
||||||
res.render('index', {
|
res.render('index', {
|
||||||
'name': dbot.config.name,
|
'name': dbot.config.name,
|
||||||
|
'user': req.user,
|
||||||
'routes': indexModules
|
'routes': indexModules
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -107,10 +117,14 @@ var webInterface = function(dbot) {
|
|||||||
'failureRedirect': '/login',
|
'failureRedirect': '/login',
|
||||||
'failureFlash': true
|
'failureFlash': true
|
||||||
}), function(req, res) {
|
}), function(req, res) {
|
||||||
res.render('login', {
|
if(req.body.redirect) {
|
||||||
'user': req.user,
|
res.redirect(req.body.redirect);
|
||||||
'message': 'Successfully logged in!'
|
} else {
|
||||||
});
|
res.render('login', {
|
||||||
|
'user': req.user,
|
||||||
|
'message': 'Successfully logged in!'
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.app.get('/logout', function(req, res) {
|
this.app.get('/logout', function(req, res) {
|
||||||
@ -167,7 +181,8 @@ var webInterface = function(dbot) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res.render('login', {
|
res.render('login', {
|
||||||
'message': 'You need to log in to access this module.'
|
'message': 'You need to log in to access this module.',
|
||||||
|
'redirect': module
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -230,8 +230,10 @@ div.imgwrap > img {
|
|||||||
margin-right:10px;
|
margin-right:10px;
|
||||||
margin-left:10px;
|
margin-left:10px;
|
||||||
}
|
}
|
||||||
#footer a {
|
#bread {
|
||||||
float:right;
|
float:right;
|
||||||
|
margin-left: 2px;
|
||||||
|
margin-right: 2px;
|
||||||
padding-left:2px;
|
padding-left:2px;
|
||||||
padding-right:2px;
|
padding-right:2px;
|
||||||
background-color:#f5f5f5;
|
background-color:#f5f5f5;
|
||||||
|
@ -16,7 +16,12 @@ html(lang='en')
|
|||||||
div.container#main
|
div.container#main
|
||||||
block content
|
block content
|
||||||
div#footer
|
div#footer
|
||||||
a#project(href='/project') About
|
p#project
|
||||||
|
a#bread(href='/project') About
|
||||||
|
if user
|
||||||
|
span#bread Logged in as #{user.primaryNick}
|
||||||
|
else
|
||||||
|
a#bread(href='/login') Login
|
||||||
|
|
||||||
script(type="text/javascript", src="/bootstrap/js/bootstrap.min.js")
|
script(type="text/javascript", src="/bootstrap/js/bootstrap.min.js")
|
||||||
script(type="text/javascript", src="/d3/d3.v3.min.js")
|
script(type="text/javascript", src="/d3/d3.v3.min.js")
|
||||||
|
@ -8,6 +8,7 @@ block content
|
|||||||
p #{message}
|
p #{message}
|
||||||
div#login
|
div#login
|
||||||
form(action='/login', method='post')
|
form(action='/login', method='post')
|
||||||
|
input(type="hidden", name="redirect", value=redirect)
|
||||||
p
|
p
|
||||||
key Username
|
key Username
|
||||||
input(type="text", name="username")
|
input(type="text", name="username")
|
||||||
|
Loading…
Reference in New Issue
Block a user