-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Forster
committed
Mar 11, 2022
1 parent
a20e4db
commit 035ea7d
Showing
18 changed files
with
175 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
var HomeController = { | ||
Index: function(req, res) { | ||
res.render('home/index', { title: 'Acebook' }); | ||
} | ||
const HomeController = { | ||
Index: (req, res) => { | ||
res.render("home/index", { title: "Acebook" }); | ||
}, | ||
}; | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
var Post = require('../models/post'); | ||
const Post = require("../models/post"); | ||
|
||
var PostsController = { | ||
Index: function(req, res) { | ||
Post.find(function(err, posts) { | ||
if (err) { throw err; } | ||
const PostsController = { | ||
Index: (req, res) => { | ||
Post.find((err, posts) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
res.render('posts/index', { posts: posts }); | ||
res.render("posts/index", { posts: posts }); | ||
}); | ||
}, | ||
New: function(req, res) { | ||
res.render('posts/new', {}); | ||
New: (req, res) => { | ||
res.render("posts/new", {}); | ||
}, | ||
Create: function(req, res) { | ||
var post = new Post(req.body); | ||
post.save(function(err) { | ||
if (err) { throw err; } | ||
Create: (req, res) => { | ||
const post = new Post(req.body); | ||
post.save((err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
res.status(201).redirect('/posts'); | ||
res.status(201).redirect("/posts"); | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = PostsController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
var User = require('../models/user'); | ||
const User = require("../models/user"); | ||
|
||
var SessionsController = { | ||
New: function(req, res) { | ||
res.render('sessions/new', {}); | ||
const SessionsController = { | ||
New: (req, res) => { | ||
res.render("sessions/new", {}); | ||
}, | ||
|
||
Create: function(req, res) { | ||
console.log('trying to log in') | ||
var email = req.body.email; | ||
var password = req.body.password; | ||
Create: (req, res) => { | ||
console.log("trying to log in"); | ||
const email = req.body.email; | ||
const password = req.body.password; | ||
|
||
User.findOne({email: email}).then( | ||
(user) => { | ||
if(!user) { | ||
res.redirect('/sessions/new'); | ||
} else if(user.password != password) { | ||
res.redirect('/sessions/new'); | ||
} else { | ||
req.session.user = user; | ||
res.redirect('/posts'); | ||
} | ||
User.findOne({ email: email }).then((user) => { | ||
if (!user) { | ||
res.redirect("/sessions/new"); | ||
} else if (user.password != password) { | ||
res.redirect("/sessions/new"); | ||
} else { | ||
req.session.user = user; | ||
res.redirect("/posts"); | ||
} | ||
) | ||
}); | ||
}, | ||
|
||
Destroy: function(req, res) { | ||
console.log('logging out') | ||
if (req.session.user && req.cookies.user_sid) { | ||
res.clearCookie('user_sid'); | ||
Destroy: (req, res) => { | ||
console.log("logging out"); | ||
if (req.session.user && req.cookies.user_sid) { | ||
res.clearCookie("user_sid"); | ||
} | ||
res.redirect('/sessions/new'); | ||
} | ||
res.redirect("/sessions/new"); | ||
}, | ||
}; | ||
|
||
module.exports = SessionsController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
var User = require('../models/user'); | ||
const User = require("../models/user"); | ||
|
||
var UsersController = { | ||
New: function(req, res) { | ||
res.render('users/new', {}); | ||
const UsersController = { | ||
New: (req, res) => { | ||
res.render("users/new", {}); | ||
}, | ||
|
||
Create: function(req, res) { | ||
var user = new User(req.body); | ||
user.save(function(err) { | ||
if (err) { throw err; } | ||
res.status(201).redirect('/posts'); | ||
Create: (req, res) => { | ||
const user = new User(req.body); | ||
user.save((err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
res.status(201).redirect("/posts"); | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = UsersController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"baseUrl": "http://localhost:3000" | ||
"baseUrl": "http://localhost:3030" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
describe('Home page', function() { | ||
it('has a title', function() { | ||
cy.visit('/'); | ||
cy.get('.title').should('contain', 'Acebook'); | ||
describe("Home page", () => { | ||
it("has a title", () => { | ||
cy.visit("/"); | ||
cy.get(".title").should("contain", "Acebook"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
describe('Authentication', function() { | ||
it('A user signs in and is redirected to /posts', function() { | ||
describe("Authentication", () => { | ||
it("A user signs in and is redirected to /posts", () => { | ||
// sign up | ||
cy.visit('/users/new') | ||
cy.get('#email').type('[email protected]') | ||
cy.get('#password').type('password') | ||
cy.get('#submit').click() | ||
cy.visit("/users/new"); | ||
cy.get("#email").type("[email protected]"); | ||
cy.get("#password").type("password"); | ||
cy.get("#submit").click(); | ||
|
||
// sign in | ||
cy.visit('/sessions/new') | ||
cy.get('#email').type('[email protected]') | ||
cy.get('#password').type('password') | ||
cy.get('#submit').click() | ||
cy.visit("/sessions/new"); | ||
cy.get("#email").type("[email protected]"); | ||
cy.get("#password").type("password"); | ||
cy.get("#submit").click(); | ||
|
||
cy.url().should('include', '/posts') | ||
cy.contains('a', 'New post') | ||
cy.url().should("include", "/posts"); | ||
cy.contains("a", "New post"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
describe('Registration', function() { | ||
it('A user signs up and is redirected to sign in', function() { | ||
describe("Registration", () => { | ||
it("A user signs up and is redirected to sign in", () => { | ||
// sign up | ||
cy.visit('/users/new') | ||
cy.get('#email').type('[email protected]') | ||
cy.get('#password').type('password') | ||
cy.get('#submit').click() | ||
cy.visit("/users/new"); | ||
cy.get("#email").type("[email protected]"); | ||
cy.get("#password").type("password"); | ||
cy.get("#submit").click(); | ||
|
||
cy.url().should('include', '/sessions/new') | ||
cy.url().should("include", "/sessions/new"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
describe('Timeline', function() { | ||
it('can submit posts, when signed in, and view them', function() { | ||
describe("Timeline", () => { | ||
it("can submit posts, when signed in, and view them", () => { | ||
// sign up | ||
cy.visit('/users/new') | ||
cy.get('#email').type('[email protected]') | ||
cy.get('#password').type('password') | ||
cy.get('#submit').click() | ||
cy.visit("/users/new"); | ||
cy.get("#email").type("[email protected]"); | ||
cy.get("#password").type("password"); | ||
cy.get("#submit").click(); | ||
|
||
// sign in | ||
cy.visit('/sessions/new') | ||
cy.get('#email').type('[email protected]') | ||
cy.get('#password').type('password') | ||
cy.get('#submit').click() | ||
cy.visit("/sessions/new"); | ||
cy.get("#email").type("[email protected]"); | ||
cy.get("#password").type("password"); | ||
cy.get("#submit").click(); | ||
|
||
// submit a post | ||
cy.visit('/posts'); | ||
cy.contains('New post').click(); | ||
cy.visit("/posts"); | ||
cy.contains("New post").click(); | ||
|
||
cy.get('#new-post-form').find('[type="text"]').type('Hello, world!'); | ||
cy.get('#new-post-form').submit(); | ||
cy.get("#new-post-form").find('[type="text"]').type("Hello, world!"); | ||
cy.get("#new-post-form").submit(); | ||
|
||
cy.get('.posts').should('contain', 'Hello, world!'); | ||
cy.get(".posts").should("contain", "Hello, world!"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
var mongoose = require('mongoose'); | ||
const mongoose = require("mongoose"); | ||
|
||
var PostSchema = new mongoose.Schema({ | ||
const PostSchema = new mongoose.Schema({ | ||
message: String, | ||
}); | ||
|
||
var Post = mongoose.model('Post', PostSchema); | ||
const Post = mongoose.model("Post", PostSchema); | ||
|
||
module.exports = Post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
var mongoose = require('mongoose'); | ||
const mongoose = require("mongoose"); | ||
|
||
var UserSchema = new mongoose.Schema({ | ||
const UserSchema = new mongoose.Schema({ | ||
email: String, | ||
password: String, | ||
}); | ||
|
||
var User = mongoose.model('User', UserSchema); | ||
const User = mongoose.model("User", UserSchema); | ||
|
||
module.exports = User; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
var HomeController = require('../controllers/home'); | ||
const HomeController = require("../controllers/home"); | ||
|
||
router.get('/', HomeController.Index); | ||
router.get("/", HomeController.Index); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
var PostsController = require('../controllers/posts') | ||
const PostsController = require("../controllers/posts"); | ||
|
||
router.get('/', PostsController.Index); | ||
router.post('/', PostsController.Create); | ||
router.get('/new', PostsController.New); | ||
router.get("/", PostsController.Index); | ||
router.post("/", PostsController.Create); | ||
router.get("/new", PostsController.New); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
var SessionsController = require('../controllers/sessions'); | ||
const SessionsController = require("../controllers/sessions"); | ||
|
||
router.get('/new', SessionsController.New); | ||
router.post('/', SessionsController.Create); | ||
router.delete('/', SessionsController.Destroy); | ||
router.get("/new", SessionsController.New); | ||
router.post("/", SessionsController.Create); | ||
router.delete("/", SessionsController.Destroy); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
var UsersController = require('../controllers/users'); | ||
const UsersController = require("../controllers/users"); | ||
|
||
router.get('/new', UsersController.New); | ||
router.post('/', UsersController.Create); | ||
router.get("/new", UsersController.New); | ||
router.post("/", UsersController.Create); | ||
|
||
module.exports = router; |
Oops, something went wrong.