@@ -44,32 +44,34 @@ const Exists = async (id) => {
4444 return false ;
4545}
4646
47- // router.get("/register",
48- // async (req, res, next) => {
49- // if (req.session.passport && (await Exists(req.session.passport.user))) next();
50- // else res.sendFile(path.join(__dirname, "../pages/form.html"));
51- // },
52- // async (req, res, next) => {
53- // if (await Registered(req.session.passport.user)) res.redirect("/dashboard");
54- // else next();
55- // },
56- // (req, res, next) => {
57- // res.sendFile(path.join(__dirname, "../pages/form.html"));
58- // }
59- // );
47+ router . get ( "/register" ,
48+ async ( req , res , next ) => {
49+ if ( req . session . passport && ( await Exists ( req . session . passport . user ) ) ) next ( ) ;
50+ else res . sendFile ( path . join ( __dirname , "../pages/form.html" ) ) ;
51+ } ,
52+ async ( req , res , next ) => {
53+ if ( await Registered ( req . session . passport . user ) ) res . redirect ( "/dashboard" ) ;
54+ else next ( ) ;
55+ } ,
56+ ( req , res , next ) => {
57+ res . sendFile ( path . join ( __dirname , "../pages/form.html" ) ) ;
58+ }
59+ ) ;
6060
61- // router.post("/register",
62- // async (req, res) => {
63- // if(validateData(req.body)){
64- // const resp = await UserHandler.addUser(req.body);
65- // res.send(JSON.stringify(resp));
66- // }
67- // else{
68- // const resp = {message: "Invalid Data"};
69- // res.send(JSON.stringify(resp));
70- // }
71- // }
72- // );
61+ router . post ( "/register" ,
62+ async ( req , res ) => {
63+ if ( validateData ( req . body ) ) {
64+ console . log ( req . body ) ;
65+
66+ const resp = await UserHandler . addUser ( req . body ) ;
67+ res . send ( JSON . stringify ( resp ) ) ;
68+ }
69+ else {
70+ const resp = { message : "Invalid Data" } ;
71+ res . send ( JSON . stringify ( resp ) ) ;
72+ }
73+ }
74+ ) ;
7375
7476router . get ( "/login" ,
7577 async ( req , res , next ) => {
0 commit comments