Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongo = require("mongodb").MongoClient;
  2. var mongoErr = false;
  3. var ips = [];
  4. var app = require("express")();
  5. app.get("/register", function(req, res){
  6.     res.sendFile(__dirname + "/register.html");
  7. });
  8. var bodyParser = require('body-parser');
  9. app.use(bodyParser.urlencoded({extended: false}));
  10. app.use(bodyParser.json());
  11. app.post("/register", function(req, res){
  12.     if (req.body.nickname && req.body.password && req.body.confpassword && req.body.avatarurl && (ips.indexOf(req.connection.remoteAddress) == -1)) {
  13.         if ((req.body.nickname.length > 3) && (req.body.nickname.length < 16)) {
  14.             if ((req.body.password.length > 4) && (req.body.password.length < 86)) {
  15.                 if (req.body.confpassword == req.body.password) {
  16.                     if (req.body.avatarurl.slice(0, 7) == "http://") {
  17.                         if (!mongoErr) {
  18.                             function genTok(len, symbols) {
  19.                                 if (len != 0) {
  20.                                     return symbols[Math.round(Math.random() * symbols.length - 1)] + genTok(len - 1, symbols);
  21.                                 } else {
  22.                                     return "";
  23.                                 }
  24.                             }
  25.                             mongo.connect("mongodb://localhost:27017/bechat", function(err, db){
  26.                                 if (!err) {
  27.                                     db.collection("users").insertOne({
  28.                                     nickname: req.body.nickname,
  29.                                     password: req.body.password,
  30.                                     avatarurl: req.body.avatarurl,
  31.                                     token: genTok(50, "qwertyuiopasdfghjklzxcvbnm1234567890")
  32.                                 });
  33.                                 ips.push(req.connection.remoteAddress);
  34.                                 res.redirect("/register#success");
  35.                                 } else {
  36.                                     res.redirect("/register#fail");
  37.                                 }
  38.                             });
  39.                         }
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.     } else {
  45.         res.redirect("/register#fail");
  46.     }
  47. });
  48. app.get("/style.css", function(req, res){
  49.     res.sendFile(__dirname + "/style.css");
  50. });
  51. app.listen(3030);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement