Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db_build.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE users (
firstname TEXT NOT NULL,
lastname TEXT NOT NULL,
github TEXT NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could make the github entry UNIQUE as well

email TEXT NOT NULL,
email TEXT UNIQUE,
username TEXT UNIQUE,
password TEXT NOT NULL
);
Expand Down
4 changes: 3 additions & 1 deletion src/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ queries.registerUser = (payload, cb) => {
VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, username`;
const values = [payload.firstname, payload.lastname, payload.github, payload.email, payload.username, hash];
dbConn.query(sql, values, (err, data) => {
if (err) cb(err);
if (err) {
cb(err);
}
else {
const userinfo = data.rows[0];
cb(null, userinfo);
Expand Down
10 changes: 7 additions & 3 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ const registerSubmit = {
reply.view('register', { password: true });
} else {
queries.registerUser(req.payload, (err, userinfo) => {
if (err) console.log(err);
req.cookieAuth.set({username: userinfo.username, userid: userinfo.id});
reply.redirect('/');
if (err) {
console.log('register error');
reply.view('register', { alreadyReg: true })
} else {
req.cookieAuth.set({username: userinfo.username, userid: userinfo.id});
reply.redirect('/');
}
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions views/register.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
{{# if password}}
<p style="color:red">Passwords do not match</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 space indentation please :)

{{/if}}

{{# if alreadyReg}}
<p style="color:red">User already registered</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 space indentation please :)

{{/if}}