Created
January 26, 2016 16:03
-
-
Save mrjazz/71d31f4d9b14e97ee9e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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