mirror of
https://github.com/jwinterm/node-tip-bot.git
synced 2026-10-20 06:08:35 +02:00
added work in progress webadmin
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
var express = require('express')
|
||||
, swig = require('swig');
|
||||
|
||||
module.exports.app = function(port, coin, settings, winston) {
|
||||
var app = express();
|
||||
|
||||
app.use(express.basicAuth(function(user, password) {
|
||||
var success = settings.users[user] == password;
|
||||
if(success)
|
||||
winston.info('%s logged into webadmin', user);
|
||||
else
|
||||
winston.warn('Failed webadmin login as %s', user);
|
||||
|
||||
return success;
|
||||
}));
|
||||
|
||||
var tpl = swig.compileFile(__dirname + '/views/index.html');
|
||||
app.get('/', function(req, res) {
|
||||
var accounts = [];
|
||||
coin.listAccounts(5, function(err, reply) {
|
||||
if(err) {
|
||||
winston.error('Tried to get account listing but failed.', err);
|
||||
res.send(500, 'Could not get account list');
|
||||
return;
|
||||
}
|
||||
for(var user in reply) {
|
||||
if(user !== "")
|
||||
accounts.push({nick: user, balance: reply[user]});
|
||||
};
|
||||
|
||||
accounts.sort(function(a, b) {
|
||||
return b.balance - a.balance
|
||||
});
|
||||
|
||||
var body = tpl({accounts: accounts});
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.setHeader('Content-Length', Buffer.byteLength(body));
|
||||
res.end(body);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Tip bot webadmin</title>
|
||||
|
||||
<link href="http://bootswatch.com/lumen/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-default" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">Tip bot webadmin</a>
|
||||
</div>
|
||||
<div class="collapse navbar-collapse">
|
||||
<form class="navbar-form navbar-right" role="search" action="/user" method="get">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Search user...">
|
||||
<div class="input-group-btn">
|
||||
<button type="submit" class="btn btn-default">
|
||||
<span class="glyphicon glyphicon glyphicon-search"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container">
|
||||
<div class="col-md-8 col-sm-12">
|
||||
<div class="page-header">
|
||||
<h1>Overview <small>Balances</small></h1>
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Nick</th>
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
{% for account in accounts %}
|
||||
<tr>
|
||||
<td>{{ loop.index }}</td>
|
||||
<td>{{ account.nick }}</td>
|
||||
<td>{{ account.balance }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-4 col-sm-12">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user