Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. const router = express.Router();
  2.  
  3. router.post('/', function (req, res) {
  4. var data = req.body;
  5. var password = bCrypt.hashSync(data.password);
  6.  
  7. UserDetails.findOne({
  8. username: data.email
  9. }, function (err, user) {
  10. if (user) {
  11. console.log(user.username + ' already exist');
  12. res.send({
  13. 'status': false,
  14. 'message': 'email already exist'
  15. });
  16. } else {
  17.  
  18. var newUser = new UserDetails({
  19. email: data.email,
  20. password: password,
  21. fullName: data.fullName,
  22. mobile: data.mobile,
  23. siteAddress: data.siteAddress
  24. });
  25.  
  26. newUser.save(function (err) {
  27. if (!err) {
  28.  
  29. var newSubDomainName = data.siteAddress;
  30. console.log("newSubDomainName: " + newSubDomainName);
  31.  
  32. // var newSubDomainName = "sd4";
  33. var subDomainCommand = util.format('./setup.sh \"%s\"', newSubDomainName);
  34.  
  35. console.log("Creating new user web server cluster" + newSubDomainName);
  36. console.log("subDomainCommand: " + subDomainCommand);
  37. exec(subDomainCommand, function (error, stdout, stderr) {
  38. console.log("Outpput:\n" + stdout);
  39. console.log("sending success to client...");
  40. res.send({
  41. 'status': true,
  42. 'message': 'successfully registered'
  43. });
  44. });
  45.  
  46. } else {
  47. res.send({
  48. 'status': false,
  49. 'message': 'internal error. try again'
  50. });
  51. }
  52. });
  53.  
  54. }
  55. });
  56. });
  57.  
  58. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement