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" ],
|
||||
"dbType": "redis"
|
||||
"dbType": "redis",
|
||||
"requireWebLogin": true,
|
||||
"webAccess": "power_users"
|
||||
}
|
||||
|
@ -24,11 +24,16 @@ var webInterface = function(dbot) {
|
||||
this.app.use(this.app.router);
|
||||
|
||||
passport.serializeUser(function(user, done) {
|
||||
done(null, user);
|
||||
console.log('serialising ' + user);
|
||||
done(null, user.id);
|
||||
});
|
||||
|
||||
passport.deserializeUser(function(obj, done) {
|
||||
done(null, obj);
|
||||
passport.deserializeUser(function(id, done) {
|
||||
dbot.api.users.getUser(id, function(user) {
|
||||
console.log(id);
|
||||
console.log(user);
|
||||
done(null, user);
|
||||
});
|
||||
});
|
||||
|
||||
passport.use(new LocalStrategy(function(username, password, callback) {
|
||||
@ -68,6 +73,10 @@ var webInterface = function(dbot) {
|
||||
var shim = Object.create(resp);
|
||||
shim.render = (function(view, one, two) {
|
||||
// Render with express.js
|
||||
_.extend(one, {
|
||||
'name': dbot.config.name,
|
||||
'user': req.user
|
||||
});
|
||||
resp.render(this.module + '/' + view, one, two);
|
||||
}).bind(this);
|
||||
shim.render_core = resp.render;
|
||||
@ -92,6 +101,7 @@ var webInterface = function(dbot) {
|
||||
this.app.get('/', function(req, res) {
|
||||
res.render('index', {
|
||||
'name': dbot.config.name,
|
||||
'user': req.user,
|
||||
'routes': indexModules
|
||||
});
|
||||
});
|
||||
@ -107,10 +117,14 @@ var webInterface = function(dbot) {
|
||||
'failureRedirect': '/login',
|
||||
'failureFlash': true
|
||||
}), function(req, res) {
|
||||
if(req.body.redirect) {
|
||||
res.redirect(req.body.redirect);
|
||||
} else {
|
||||
res.render('login', {
|
||||
'user': req.user,
|
||||
'message': 'Successfully logged in!'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.app.get('/logout', function(req, res) {
|
||||
@ -167,7 +181,8 @@ var webInterface = function(dbot) {
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
|
@ -230,8 +230,10 @@ div.imgwrap > img {
|
||||
margin-right:10px;
|
||||
margin-left:10px;
|
||||
}
|
||||
#footer a {
|
||||
#bread {
|
||||
float:right;
|
||||
margin-left: 2px;
|
||||
margin-right: 2px;
|
||||
padding-left:2px;
|
||||
padding-right:2px;
|
||||
background-color:#f5f5f5;
|
||||
|
@ -16,7 +16,12 @@ html(lang='en')
|
||||
div.container#main
|
||||
block content
|
||||
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="/d3/d3.v3.min.js")
|
||||
|
@ -8,6 +8,7 @@ block content
|
||||
p #{message}
|
||||
div#login
|
||||
form(action='/login', method='post')
|
||||
input(type="hidden", name="redirect", value=redirect)
|
||||
p
|
||||
key Username
|
||||
input(type="text", name="username")
|
||||
|
Loading…
Reference in New Issue
Block a user