Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signing up #446

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f5b29ec
added name, surname, DOB to sign up. tests passed and feature impleme…
annaobarzanowska Nov 15, 2022
2822257
Merge pull request #1 from BnjCam25/add-name-surname
mollygallagherwickham Nov 15, 2022
495e7d4
added to the integration tests to sign up
lcleigh Nov 15, 2022
e819fd7
Merge pull request #2 from BnjCam25/int-test-signup
mollygallagherwickham Nov 15, 2022
3a600c2
Added link to trello board
annaobarzanowska Nov 15, 2022
f7a8c9d
completed welcome message feature + test passing + redirect to posts …
lcleigh Nov 16, 2022
4b3e044
Merge branch 'welcome-user2' of https://github.com/BnjCam25/acebook-s…
annaobarzanowska Nov 16, 2022
b05ca53
personalised message on login
annaobarzanowska Nov 16, 2022
f902741
Merge pull request #3 from BnjCam25/second-ticket
BnjCam25 Nov 16, 2022
35764c8
Add timestamps, order posts by creation and specs
natashawilson96 Nov 16, 2022
a0f0ab8
added sign up and sign in links to homepage
annaobarzanowska Nov 16, 2022
3d85b44
Merge branch 'main' into Tash
annaobarzanowska Nov 17, 2022
122c158
Merge pull request #5 from BnjCam25/Tash
annaobarzanowska Nov 17, 2022
a387bd2
Merge pull request #4 from BnjCam25/sign-up-sign-in
BnjCam25 Nov 17, 2022
fd46c41
Done
BnjCam25 Nov 17, 2022
80461bc
Done
BnjCam25 Nov 17, 2022
120ea3f
update
BnjCam25 Nov 17, 2022
316c1ca
Merge pull request #7 from BnjCam25/same-email
BnjCam25 Nov 17, 2022
a1dca44
Fix tests which were broken
BnjCam25 Nov 17, 2022
a8ba401
Update index.js
BnjCam25 Nov 17, 2022
d20402c
Update index.js
BnjCam25 Nov 17, 2022
c0c1a67
Merge pull request #8 from BnjCam25/fix_tests
BnjCam25 Nov 17, 2022
e8b84e9
new users must enter all details in order to sign up
annaobarzanowska Nov 17, 2022
11d0128
Create CNAME
BnjCam25 Nov 17, 2022
a894361
Delete CNAME
BnjCam25 Nov 17, 2022
81d7583
adjusted signing up to force user to input all values and adjusted me…
annaobarzanowska Nov 17, 2022
11f29ad
name and date added to posts
mollagher Nov 17, 2022
fc26cb3
Update user_can_submit_posts_spec.js
mollygallagherwickham Nov 17, 2022
c593cef
Update user_can_submit_posts_spec.js
mollygallagherwickham Nov 17, 2022
e6613aa
Update home_page_spec.js
mollygallagherwickham Nov 17, 2022
4ef188a
Update user_can_see_welcome_message_when_logged_in.js
mollygallagherwickham Nov 17, 2022
cc8f61d
Update user_can_sign_in_spec.js
mollygallagherwickham Nov 17, 2022
3fcb58c
Update user_can_see_posts_count_on_post.js
mollygallagherwickham Nov 17, 2022
aa48375
Update user_can_sign_up_spec.js
mollygallagherwickham Nov 17, 2022
b1a506c
Merge branch 'main' into username-add
annaobarzanowska Nov 17, 2022
e9cc814
Merge pull request #9 from BnjCam25/username-add
annaobarzanowska Nov 17, 2022
a4cad3b
Merge branch 'main' into signing-up
annaobarzanowska Nov 17, 2022
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
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: 'standard',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
rules: {
}
}
27 changes: 0 additions & 27 deletions .eslintrc.json

This file was deleted.

6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"explorer.compactFolders": false,
"notebook.compactView": false,
"explorer.expandSingleFolderWorkspaces": true,
"npm.enableRunFromFolder": false
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It uses:

## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
[Team Sleep Trello](https://trello.com/b/YvAr6yCq/acebook-sleep)

## Quickstart

Expand Down
86 changes: 43 additions & 43 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
const createError = require("http-errors");
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const session = require("express-session");
const methodOverride = require("method-override");
const createError = require('http-errors')
const express = require('express')
const path = require('path')
const cookieParser = require('cookie-parser')
const logger = require('morgan')
const session = require('express-session')
const methodOverride = require('method-override')

const homeRouter = require("./routes/home");
const postsRouter = require("./routes/posts");
const sessionsRouter = require("./routes/sessions");
const usersRouter = require("./routes/users");
const homeRouter = require('./routes/home')
const postsRouter = require('./routes/posts')
const sessionsRouter = require('./routes/sessions')
const usersRouter = require('./routes/users')

const app = express();
const app = express()

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'hbs')

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(methodOverride("_method"));
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))
app.use(methodOverride('_method'))

app.use(
session({
key: "user_sid",
secret: "super_secret",
key: 'user_sid',
secret: 'super_secret',
resave: false,
saveUninitialized: false,
cookie: {
expires: 600000,
},
expires: 600000
}
})
);
)

// clear the cookies after user logs out
app.use((req, res, next) => {
if (req.cookies.user_sid && !req.session.user) {
res.clearCookie("user_sid");
res.clearCookie('user_sid')
}
next();
});
next()
})

// middleware function to check for logged-in users
const sessionChecker = (req, res, next) => {
if (!req.session.user && !req.cookies.user_sid) {
res.redirect("/sessions/new");
res.redirect('/sessions/new')
} else {
next();
next()
}
};
}

// route setup
app.use("/", homeRouter);
app.use("/posts", sessionChecker, postsRouter);
app.use("/sessions", sessionsRouter);
app.use("/users", usersRouter);
app.use('/', homeRouter)
app.use('/posts', sessionChecker, postsRouter)
app.use('/sessions', sessionsRouter)
app.use('/users', usersRouter)

// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
});
next(createError(404))
})

// error handler
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
res.locals.message = err.message
res.locals.error = req.app.get('env') === 'development' ? err : {}

// render the error page
res.status(err.status || 500);
res.render("error");
});
res.status(err.status || 500)
res.render('error')
})

module.exports = app;
module.exports = app
15 changes: 11 additions & 4 deletions controllers/home.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// const Post = require('../models/post')

const HomeController = {
Index: (req, res) => {
res.render("home/index", { title: "Acebook" });
},
};
// if user has an open session, show "You're logged in", else show "You need to log in"
if (req.session.user) {
res.render('home/index', { title: 'Acebook', newUser: false, current_user: req.session.user.first_name })
} else {
res.render('home/index', { title: 'Acebook', newUser: true })
}
}
}

module.exports = HomeController;
module.exports = HomeController
46 changes: 29 additions & 17 deletions controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
const Post = require("../models/post");
const Post = require('../models/post')
const { replaceOne } = require('../models/user')
const User = require('../models/user')

const PostsController = {
Index: (req, res) => {
Post.find((err, posts) => {
Post.find().populate("user_id").exec((err, posts) => {
if (err) {
throw err;
throw err
}
posts.reverse();
res.render('posts/index', { posts, current_user: req.session.user.first_name })
})
},

res.render("posts/index", { posts: posts });
});
},
New: (req, res) => {
res.render("posts/new", {});
res.render('posts/new', { current_user: req.session.user.first_name })
},
Create: (req, res) => {
const post = new Post(req.body);
post.save((err) => {
if (err) {
throw err;
}

res.status(201).redirect("/posts");
Create: (req, res) => {
// this creates new post with requested body
var post = new Post({
message: req.body.message,
user_id: req.session.user
});
},
};
// if there's an error, returns error
if (post.message != "") {
post.save((err) => {
if (err) {
throw err;
}
res.status(201).redirect('/posts')
});
} else {
res.redirect('/posts/new')
}
}
}

module.exports = PostsController;
module.exports = PostsController
40 changes: 22 additions & 18 deletions controllers/sessions.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
const User = require("../models/user");
const User = require('../models/user')

const SessionsController = {
New: (req, res) => {
res.render("sessions/new", {});
if (req.session.user) {
res.redirect('/posts')
} else {
res.render('sessions/new', { newUser: true })
}
},

Create: (req, res) => {
console.log("trying to log in");
const email = req.body.email;
const password = req.body.password;
console.log('trying to log in')
const email = req.body.email
const password = req.body.password

User.findOne({ email: email }).then((user) => {
User.findOne({ email }).then((user) => {
if (!user) {
res.redirect("/sessions/new");
} else if (user.password != password) {
res.redirect("/sessions/new");
res.redirect('/sessions/new')
} else if (user.password !== password) {
res.redirect('/sessions/new')
} else {
req.session.user = user;
res.redirect("/posts");
req.session.user = user
res.redirect('/posts')
}
});
})
},

Destroy: (req, res) => {
console.log("logging out");
console.log('logging out')
if (req.session.user && req.cookies.user_sid) {
res.clearCookie("user_sid");
res.clearCookie('user_sid')
}
res.redirect("/sessions/new");
},
};
res.redirect('/sessions/new')
}
}

module.exports = SessionsController;
module.exports = SessionsController
31 changes: 20 additions & 11 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
const User = require("../models/user");
const User = require('../models/user')

const UsersController = {
New: (req, res) => {
res.render("users/new", {});
res.render('users/new', { newUser: true })
},

Create: (req, res) => {
const user = new User(req.body);
user.save((err) => {
if (err) {
throw err;
const user = new User(req.body)
const email = user.email

User.findOne({ email }).then((email) => {
if (!email) {
req.session.user = user
user.save((err) => {
if (err) {
throw err
}
res.status(201).redirect('/posts')
})
} else if (user.email !== email) {
res.redirect('/users/new')
}
res.status(201).redirect("/posts");
});
},
};
})
}
}

module.exports = UsersController;
module.exports = UsersController
24 changes: 18 additions & 6 deletions cypress/integration/home_page_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
describe("Home page", () => {
it("has a title", () => {
cy.visit("/");
cy.get(".title").should("contain", "Acebook");
});
});
describe('Home page', () => {
it('has a title', () => {
cy.visit('/')
cy.get('.title').should('contain', 'Acebook')
})
it('has a login link', () => {
cy.visit('/')
cy.get('#login-link').should('contain', 'Login here')
cy.get('#login-link').click()
cy.url().should('include', '/sessions/new')
})
it('has a sign up link', () => {
cy.visit('/')
cy.get('#signup-link').should('contain', 'Sign up here')
cy.get('#signup-link').click()
cy.url().should('include', '/users/new')
})
})
Loading