Skip to content

Instantly share code, notes, and snippets.

@mrjazz
Created January 26, 2016 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrjazz/71d31f4d9b14e97ee9e8 to your computer and use it in GitHub Desktop.
Save mrjazz/71d31f4d9b14e97ee9e8 to your computer and use it in GitHub Desktop.
// npm install express
// npm install body-parser
var express = require('express');
var bodyParser = require('body-parser')
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/login', function (req, res) {
if (!req.body.username || !req.body.password) {
res.end( JSON.stringify({"status": "error", "message": "Parameter missed"}) );
}
if (req.body.username == 'admin' || req.body.password == 'password') {
res.end( JSON.stringify({"status": "success", "token": Math.round(Math.random() * 99999)}) );
} else {
res.end( JSON.stringify({"status": "error", "message": "Access denied"}) );
}
})
app.listen(8081);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment