From e74b5e6a57f72b59b0f1e1eb08f6ea469ebed493 Mon Sep 17 00:00:00 2001
From: Lucas Gabriel Lima <lgl15@inf.ufpr.br>
Date: Tue, 20 Sep 2016 10:19:25 -0300
Subject: [PATCH] add signup route to api

---
 src/libs/routes/api.js    |  3 +++
 src/libs/routes/signup.js | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 src/libs/routes/signup.js

diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js
index 35e1d0f5..e7487fa8 100644
--- a/src/libs/routes/api.js
+++ b/src/libs/routes/api.js
@@ -12,6 +12,8 @@ const city = require('./city');
 
 const school = require('./school');
 
+const signup = require('./signup')
+
 api.get('/', (req, res) => {
     res.json({ msg: 'SimCAQ API is running' });
 });
@@ -22,5 +24,6 @@ api.use('/api/v1/state', state);
 api.use('/api/v1/region', region);
 api.use('/api/v1/city', city);
 api.use('/api/v1/school', school);
+api.use('/api/v1/signup', signup);
 
 module.exports = api;
diff --git a/src/libs/routes/signup.js b/src/libs/routes/signup.js
new file mode 100644
index 00000000..d5fa3ab2
--- /dev/null
+++ b/src/libs/routes/signup.js
@@ -0,0 +1,24 @@
+const express = require('express');
+
+const signupApp = express();
+
+const libs = `${process.cwd()}/libs`;
+
+
+signupApp.post('/signup', function(req, res) {
+  if (!req.body.email || !req.body.password) {
+    res.json({success: false, msg: 'Please pass email and password.'});
+  } else {
+    var newUser = new User({
+      email: req.body.email,
+      password: req.body.password
+    });
+    // save the user
+    newUser.save(function(err) {
+      if (err) {
+        return res.json({success: false, msg: 'Email already in use.'});
+      }
+      res.json({success: true, msg: 'Successful created new user.'});
+    });
+  }
+});
-- 
GitLab