Skip to content

Commit

Permalink
Now user can create account
Browse files Browse the repository at this point in the history
  • Loading branch information
elszczepano committed Oct 2, 2018
1 parent aa6466c commit b84707f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ dotenv.config({path: '.env'});
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import authRouter from './routes/authRouter';
import indexRouter from './routes/indexRouter';
import usersRouter from './routes/usersRouter';
import matchesRouter from './routes/matchesRouter';
import messagesRouter from './routes/messagesRouter';
import pendingMatchesRouter from './routes/pendingMatchesRouter';
import usersRouter from './routes/usersRouter';

//Setup Express.js
const app = express();
Expand All @@ -22,6 +23,7 @@ app.use(bodyParser.urlencoded({extended: true}));

//Setup routing
app.use('/', indexRouter);
app.use('/auth', authRouter);
app.use('/matches', matchesRouter);
app.use('/messages', messagesRouter);
app.use('/pending-matches', pendingMatchesRouter);
Expand Down
14 changes: 14 additions & 0 deletions src/controllers/authController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import User from '../models/User';

export default {
async register(req, res, next) {
const {name, email, phone, gender, birthDate, purpose, password} = req.body;
const user = new User({name, email, password, phone, gender, birthDate, purpose});
await User.register(user, password);

res.status(201).json({
success: true,
message: "User registered succesfully"
});
}
}
8 changes: 8 additions & 0 deletions src/routes/authRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Router } from "express";
import authController from "../controllers/authController";

const api = Router();

api.post('/register', authController.register);

module.exports = api;

0 comments on commit b84707f

Please sign in to comment.