aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/authentication/controllers/user.ts28
-rw-r--r--src/server/index.ts35
-rw-r--r--views/login.pug21
3 files changed, 73 insertions, 11 deletions
diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts
index c75eaab3c..feb5ba4aa 100644
--- a/src/server/authentication/controllers/user.ts
+++ b/src/server/authentication/controllers/user.ts
@@ -14,6 +14,8 @@ import * as pug from 'pug';
*/
export let getSignup = (req: Request, res: Response) => {
if (req.user) {
+ let user = req.user;
+ console.log(user);
return res.redirect("/");
}
res.render("signup.pug", {
@@ -41,15 +43,22 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => {
return res.redirect("/signup");
}
+ const email = req.body.email;
+ const password = req.body.password;
+
const user = new User({
- email: req.body.email,
- password: req.body.password
+ email,
+ password
});
- User.findOne({ email: req.body.email }, (err, existingUser) => {
+ const please_work = "cool@gmail.com"
+
+ User.findOne({ email }, (err, existingUser) => {
if (err) { return next(err); }
if (existingUser) {
- console.log("GAAAAHHHHHHH!");
+ if (existingUser) {
+ existingUser.update({ $set: { email : please_work } }, (err, res) => {});
+ }
req.flash("errors", "Account with that email address already exists.");
return res.redirect("/signup");
}
@@ -59,11 +68,11 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => {
if (err) {
return next(err);
}
- console.log("WE IN!");
res.redirect("/");
});
});
});
+
};
@@ -75,10 +84,9 @@ export let getLogin = (req: Request, res: Response) => {
if (req.user) {
return res.redirect("/");
}
- res.send("<p>dear lord please render</p>");
- // res.render("account/login", {
- // title: "Login"
- // });
+ res.render("login.pug", {
+ title: "Log In"
+ });
};
/**
@@ -106,7 +114,7 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
req.logIn(user, (err) => {
if (err) { return next(err); }
req.flash("success", "Success! You are logged in.");
- res.redirect("/");
+ res.redirect("/home");
});
})(req, res, next);
}; \ No newline at end of file
diff --git a/src/server/index.ts b/src/server/index.ts
index 3b8659d0e..3f7f73b39 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -69,17 +69,32 @@ app.use((req, res, next) => {
});
app.get("/signup", getSignup);
+// app.post('/signup', passport.authenticate('local-signup', {
+// successRedirect : '/profile', // redirect to the secure profile section
+// failureRedirect : '/signup', // redirect back to the signup page if there is an error
+// failureFlash : true // allow flash messages
+// }));
app.post("/signup", postSignup);
app.get("/login", getLogin);
app.post("/login", postLogin);
+
+
let FieldStore: ObservableMap<FIELD_ID, Field> = new ObservableMap();
// define a route handler for the default home page
-app.get("/", (req, res) => {
+app.get("/home", (req, res) => {
+ if (!req.user) {
+ res.redirect("/login");
+ return;
+ }
res.sendFile(path.join(__dirname, '../../deploy/index.html'));
});
+app.get("/", (req, res) => {
+ res.redirect("/login");
+});
+
app.get("/hello", (req, res) => {
res.send("<p>Hello</p>");
})
@@ -89,6 +104,24 @@ app.get("/delete", (req, res) => {
res.redirect("/");
});
+app.get('/logout', function(req, res){
+ req.logout();
+ const sess = req.session;
+ if (sess) {
+ sess.destroy((err) => {
+ if (err) {
+ console.log("ERRRRRRROOOOOOOOORRRRRRRR IN LOG OUT");
+ console.log(err);
+ return;
+ }
+ // return res.send({ authenticated: req.isAuthenticated() });
+ });
+ res.redirect('/login');
+ } else {
+ res.redirect('/');
+ }
+});
+
app.use(wdm(compiler, {
publicPath: config.output.publicPath
}))
diff --git a/views/login.pug b/views/login.pug
new file mode 100644
index 000000000..1ec799745
--- /dev/null
+++ b/views/login.pug
@@ -0,0 +1,21 @@
+
+extends ./layout
+
+block content
+ .page-header
+ h3 Can you log in? Let's find out...
+ form.form-horizontal(id='login-form', method='POST')
+ input(type='hidden', name='_csrf', value=_csrf)
+ .form-group
+ label.col-sm-3.control-label(for='email') Email
+ .col-sm-7
+ input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, required)
+ .form-group
+ label.col-sm-3.control-label(for='password') Password
+ .col-sm-7
+ input.form-control(type='password', name='password', id='password', placeholder='Password', required)
+ .form-group
+ .col-sm-offset-3.col-sm-7
+ button.btn.btn-success(type='submit')
+ i.fa.fa-user-plus
+ | Login \ No newline at end of file