Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // npm install express
  2. // npm install body-parser
  3.  
  4.  
  5. var express = require('express');
  6. var bodyParser = require('body-parser')
  7. var app = express();
  8.  
  9. app.use(bodyParser.urlencoded({ extended: false }));
  10.  
  11. app.post('/login', function (req, res) {
  12. if (!req.body.username || !req.body.password) {
  13. res.end( JSON.stringify({"status": "error", "message": "Parameter missed"}) );
  14. }
  15. if (req.body.username == 'admin' || req.body.password == 'password') {
  16. res.end( JSON.stringify({"status": "success", "token": Math.round(Math.random() * 99999)}) );
  17. } else {
  18. res.end( JSON.stringify({"status": "error", "message": "Access denied"}) );
  19. }
  20. })
  21.  
  22. app.listen(8081);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement