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

Vapor 2 #12

Merged
merged 89 commits into from May 24, 2017
Merged

Vapor 2 #12

Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
5c1b242
Use Vapor 2 packages and comment out old imports
0xTim Apr 17, 2017
dfdab5b
Convert most of the Model stuff over to Vapor 2
0xTim Apr 17, 2017
9c0a1d9
Fix most of the makeNode errors
0xTim Apr 20, 2017
4200143
Update Swift badge on README
0xTim Apr 24, 2017
4f9d6c7
Fix the Provider
0xTim Apr 24, 2017
ebd0631
Update getting the user from the request
0xTim Apr 24, 2017
675be08
Sort out Authentication
0xTim Apr 24, 2017
6c7d9a0
Convert most of the Relationships stuff
0xTim Apr 24, 2017
af48967
Fix sibling relation between BlogTag and BlogPost
0xTim Apr 24, 2017
c8c536f
Model fixes
0xTim Apr 25, 2017
9538394
Use BCrypt for passwords and some model fixes
0xTim Apr 25, 2017
8ea741a
Bring back validation
0xTim May 1, 2017
decd083
Some tidy ups and fixing the modifications
0xTim May 1, 2017
d40c29a
Use in-built pagination
0xTim May 1, 2017
5bc6017
Get most of the tests compiling
0xTim May 1, 2017
5593045
Try and get the tests working
0xTim May 1, 2017
d176868
Fix post count tag test
0xTim May 1, 2017
598957d
Fix BlogAdminController tests
0xTim May 1, 2017
d965cb6
Migrations don't appear to work. Use correct column ID for the relation
0xTim May 3, 2017
5ba91c4
Prepare the pivot correctly
0xTim May 3, 2017
0a411b7
Update framework to latest Vapor changes
0xTim May 3, 2017
39d2863
Fix more tests for parent-child relations
0xTim May 3, 2017
ceef36e
Force author to be passed in when creating a post as we now need to s…
0xTim May 3, 2017
8c83dca
Fix test where username wasn't unique
0xTim May 3, 2017
ac66f27
Prepare the database for tests in one place
0xTim May 3, 2017
e12990b
Make the migrations SQLite compatible and use them in tests
0xTim May 3, 2017
ee1e906
Fix context check in BlogPost
0xTim May 3, 2017
ba70bb4
Blog Controller tests now all working again
0xTim May 3, 2017
a86321d
Bring back the commented out tests
0xTim May 3, 2017
6ef73df
All tests that don't rely on a paginator are now working
0xTim May 3, 2017
3d43b8f
Updates for latest Vapor 2 beta
0xTim May 3, 2017
71455aa
Tests are now passing for Vapor 2!
0xTim May 3, 2017
1e6cfc5
Modernising makeNode and tidy ups
0xTim May 3, 2017
9393c2b
Update CI script for Vapor 2
0xTim May 3, 2017
2b62412
Make authentication work
0xTim May 4, 2017
9065e22
Add some type safety around setting the password (it is now Bytes typ…
0xTim May 4, 2017
ca5ff19
Fix test from Vapor 2 update
0xTim May 4, 2017
7c78d9a
Fix logging in to the blog
0xTim May 4, 2017
ddc8700
Admin user must reset their password on first login again
0xTim May 4, 2017
4a9f603
Fix log out
0xTim May 4, 2017
7bec662
Unauthenticate already calls unpersist
0xTim May 4, 2017
ea12d9e
Fix last edited date not being saved correctly
0xTim May 4, 2017
95ef064
Make Travis emails a bit less spammy
0xTim May 4, 2017
99088ce
Finally inlined the logic to differentiate between none, one and mult…
0xTim May 4, 2017
223d614
Redirect to post once created
0xTim May 4, 2017
1240cd1
We don't need code coverage for the tests...
0xTim May 4, 2017
0676f87
BCryptHasher automatically conforms to PasswordVerifier now
0xTim May 8, 2017
348f6f4
Start bringing the paginator tag back
0xTim May 9, 2017
a2970ce
Get paginator work building again
0xTim May 9, 2017
8730ef0
First signs of a working paginator
0xTim May 9, 2017
7a612fb
Fix pagination when only one page
0xTim May 10, 2017
fdf6122
First stab at paginator. Uses crude method for creating the links as …
0xTim May 10, 2017
4ff9978
Start moving to new Routing way
0xTim May 11, 2017
e927cd0
Update for new Routing
0xTim May 12, 2017
46ec618
Remove casting and give the compiler a hand
0xTim May 12, 2017
9c5abc1
Make posts per page for paginator use the configuration passed again
0xTim May 12, 2017
a5f4d80
Having a bit of a tidy up
0xTim May 12, 2017
4fc5cb7
No longer need a Console implementation for tests
0xTim May 12, 2017
82a5c9a
Rename persist middleware in case of conflicts
0xTim May 12, 2017
d9bdd08
Update README about adding the middleware
0xTim May 12, 2017
4b5adbb
Use next() instead of get() to pull out parameters
0xTim May 12, 2017
f2d71bb
Merge branch 'vapor2' of personalid:brokenhandsio/SteamPress into vapor2
0xTim May 12, 2017
62d951d
Add information about SessionsMiddleware to README
0xTim May 12, 2017
db89df5
Controllers shouldn't know about the Droplet's config. Adding a disqu…
0xTim May 12, 2017
fef6778
Revert the database as part of teardown for each test
0xTim May 12, 2017
506a08a
Move preparations into a separate file
0xTim May 14, 2017
48bc094
Tidy up the models
0xTim May 14, 2017
422eb10
Make column names less 'stringly typed'
0xTim May 14, 2017
1536039
Use a single BCryptHasher rather than creating a load of them in diff…
0xTim May 14, 2017
a96f723
Allow Bootstrap 3 or 4 for the paginator Tag
0xTim May 14, 2017
610eab2
Note change in parameter of URI
0xTim May 16, 2017
903694f
Better error for Parameterizable models
0xTim May 16, 2017
b1218bd
Tidy up old parameters
0xTim May 16, 2017
31ba66e
Use custom Sessions stuff in prepration for SessionsMiddleware change…
0xTim May 16, 2017
532c0a2
Update README with details about custom middleware
0xTim May 16, 2017
b1cef8d
Fix preparation order on MySQL
0xTim May 17, 2017
a4965ca
Add test for logging in
0xTim May 17, 2017
f6e1027
Add tests for checking for login on admin pages
0xTim May 17, 2017
782c969
Updates to latest Vapor code
0xTim May 17, 2017
8878664
Entity types can already conform to Parameterizable without any work
0xTim May 18, 2017
892715a
Update for latest Vapor changes and remember me should now work
0xTim May 18, 2017
789481a
Merge pull request #1 from brokenhandsio/vapor2
pruthvikar May 18, 2017
bb8f0db
using a struct with static let strings for cleaner field name access
pruthvikar May 17, 2017
2ab8f3e
Merge pull request #13 from pruthvikar/PropertiesStruct
0xTim May 18, 2017
d2a4650
Update README for Vapor 2
0xTim May 19, 2017
ef62970
Use latest releases and merged Forks
0xTim May 19, 2017
6599093
Fix login bug and work around the Redirect issue for now
0xTim May 19, 2017
0955712
Update tests for new redirect behaviour
0xTim May 22, 2017
a24710d
Fix typo in comment
0xTim May 24, 2017
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+171 −306
Diff settings

Always

Just for now

Controllers shouldn't know about the Droplet's config. Adding a disqu…

…s name and twitter handle to a page are the responsibility of the LeafViewFactory now and not Controllers
  • Loading branch information...
0xTim committed May 12, 2017
commit db89df50d7777e9ad2d64e32ee226e11c94eddac
@@ -417,7 +417,7 @@ struct BlogAdminController {
let user = try request.user()
let posts = try user.sortedPosts().paginate(for: request)

return try viewFactory.createProfileView(uri: request.uri, author: user, isMyProfile: true, paginatedPosts: posts, loggedInUser: user, disqusName: nil, siteTwitterHandle: nil)
return try viewFactory.createProfileView(uri: request.uri, author: user, isMyProfile: true, paginatedPosts: posts, loggedInUser: user)
}

// MARK: - Password handlers
@@ -16,17 +16,15 @@ struct BlogController {
fileprivate let postsPerPage: Int
fileprivate let enableAuthorsPages: Bool
fileprivate let enableTagsPages: Bool
fileprivate let config: Config

// MARK: - Initialiser
init(drop: Droplet, pathCreator: BlogPathCreator, viewFactory: ViewFactory, postsPerPage: Int, enableAuthorsPages: Bool, enableTagsPages: Bool, config: Config) {
init(drop: Droplet, pathCreator: BlogPathCreator, viewFactory: ViewFactory, postsPerPage: Int, enableAuthorsPages: Bool, enableTagsPages: Bool) {
self.drop = drop
self.pathCreator = pathCreator
self.viewFactory = viewFactory
self.postsPerPage = postsPerPage
self.enableAuthorsPages = enableAuthorsPages
self.enableTagsPages = enableTagsPages
self.config = config
}

// MARK: - Add routes
@@ -56,7 +54,7 @@ struct BlogController {
let authors = try BlogUser.all()
let paginatedBlogPosts = try BlogPost.makeQuery().filter("published", true).sort("created", .descending).paginate(for: request)

return try viewFactory.blogIndexView(uri: request.uri, paginatedPosts: paginatedBlogPosts, tags: tags, authors: authors, loggedInUser: getLoggedInUser(in: request), disqusName: getDisqusName(), siteTwitterHandle: getSiteTwitterHandle())
return try viewFactory.blogIndexView(uri: request.uri, paginatedPosts: paginatedBlogPosts, tags: tags, authors: authors, loggedInUser: getLoggedInUser(in: request))
}

func blogPostIndexRedirectHandler(request: Request) throws -> ResponseRepresentable {
@@ -73,7 +71,7 @@ struct BlogController {
throw Abort.badRequest
}

return try viewFactory.blogPostView(uri: request.uri, post: blogPost, author: author, user: getLoggedInUser(in: request), disqusName: getDisqusName(), siteTwitterHandle: getSiteTwitterHandle())
return try viewFactory.blogPostView(uri: request.uri, post: blogPost, author: author, user: getLoggedInUser(in: request))
}

func tagViewHandler(request: Request) throws -> ResponseRepresentable {
@@ -89,7 +87,7 @@ struct BlogController {

let paginatedBlogPosts = try tag.sortedPosts().paginate(for: request)

return try viewFactory.tagView(uri: request.uri, tag: tag, paginatedPosts: paginatedBlogPosts, user: getLoggedInUser(in: request), disqusName: getDisqusName(), siteTwitterHandle: getSiteTwitterHandle())
return try viewFactory.tagView(uri: request.uri, tag: tag, paginatedPosts: paginatedBlogPosts, user: getLoggedInUser(in: request))
}

func authorViewHandler(request: Request) throws -> ResponseRepresentable {
@@ -101,15 +99,15 @@ struct BlogController {

let posts = try author.sortedPosts().paginate(for: request)

return try viewFactory.createProfileView(uri: request.uri, author: author, isMyProfile: author.username == getLoggedInUser(in: request)?.username, paginatedPosts: posts, loggedInUser: getLoggedInUser(in: request), disqusName: getDisqusName(), siteTwitterHandle: getSiteTwitterHandle())
return try viewFactory.createProfileView(uri: request.uri, author: author, isMyProfile: author.username == getLoggedInUser(in: request)?.username, paginatedPosts: posts, loggedInUser: getLoggedInUser(in: request))
}

func allTagsViewHandler(request: Request) throws -> ResponseRepresentable {
return try viewFactory.allTagsView(uri: request.uri, allTags: BlogTag.all(), user: getLoggedInUser(in: request), siteTwitterHandle: getSiteTwitterHandle())
return try viewFactory.allTagsView(uri: request.uri, allTags: BlogTag.all(), user: getLoggedInUser(in: request))
}

func allAuthorsViewHandler(request: Request) throws -> ResponseRepresentable {
return try viewFactory.allAuthorsView(uri: request.uri, allAuthors: BlogUser.all(), user: getLoggedInUser(in: request), siteTwitterHandle: getSiteTwitterHandle())
return try viewFactory.allAuthorsView(uri: request.uri, allAuthors: BlogUser.all(), user: getLoggedInUser(in: request))
}

func tagApiHandler(request: Request) throws -> ResponseRepresentable {
@@ -126,13 +124,4 @@ struct BlogController {

return loggedInUser
}

private func getDisqusName() -> String? {
return config["disqus", "disqusName"]?.string
}

private func getSiteTwitterHandle() -> String? {
return config["twitter", "siteHandle"]?.string
}

}
@@ -38,10 +38,10 @@ public struct Provider: Vapor.Provider {

setup(drop)

let viewFactory = LeafViewFactory(viewRenderer: drop.view)
let viewFactory = LeafViewFactory(viewRenderer: drop.view, disqusName: drop.config["disqus", "disqusName"]?.string, siteTwitterHandle: drop.config["twitter", "siteHandle"]?.string)

// Set up the controllers
let blogController = BlogController(drop: drop, pathCreator: pathCreator, viewFactory: viewFactory, postsPerPage: postsPerPage, enableAuthorsPages: enableAuthorsPages, enableTagsPages: enableTagsPages, config: drop.config)
let blogController = BlogController(drop: drop, pathCreator: pathCreator, viewFactory: viewFactory, postsPerPage: postsPerPage, enableAuthorsPages: enableAuthorsPages, enableTagsPages: enableTagsPages)
let blogAdminController = BlogAdminController(drop: drop, pathCreator: pathCreator, viewFactory: viewFactory, postsPerPage: postsPerPage)

// Add the routes
@@ -9,6 +9,8 @@ import Fluent
struct LeafViewFactory: ViewFactory {

let viewRenderer: ViewRenderer
let disqusName: String?
let siteTwitterHandle: String?

// MARK: - Admin Controller Views
@@ -198,7 +200,7 @@ struct LeafViewFactory: ViewFactory {
return try viewRenderer.make("blog/admin/resetPassword", parameters)
}

func createProfileView(uri: URI, author: BlogUser, isMyProfile: Bool, paginatedPosts: Page<BlogPost>, loggedInUser: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View {
func createProfileView(uri: URI, author: BlogUser, isMyProfile: Bool, paginatedPosts: Page<BlogPost>, loggedInUser: BlogUser?) throws -> View {
var parameters: [String: Vapor.Node] = [:]
parameters["author"] = try author.makeNode(in: BlogUserContext.withPostCount)

@@ -213,12 +215,12 @@ struct LeafViewFactory: ViewFactory {
parameters["posts"] = try paginatedPosts.makeNode(for: uri, in: BlogPostContext.longSnippet)
}

return try createPublicView(template: "blog/profile", uri: uri, parameters: parameters, user: loggedInUser, disqusName: disqusName, siteTwitterHandle: siteTwitterHandle)
return try createPublicView(template: "blog/profile", uri: uri, parameters: parameters, user: loggedInUser)
}

// MARK: - Blog Controller Views
func blogIndexView(uri: URI, paginatedPosts: Page<BlogPost>, tags: [BlogTag], authors: [BlogUser], loggedInUser: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View {
func blogIndexView(uri: URI, paginatedPosts: Page<BlogPost>, tags: [BlogTag], authors: [BlogUser], loggedInUser: BlogUser?) throws -> View {

var parameters: [String: Vapor.Node] = [:]
parameters["blog_index_page"] = true.makeNode(in: nil)
@@ -235,10 +237,10 @@ struct LeafViewFactory: ViewFactory {
parameters["authors"] = try authors.makeNode(in: nil)
}

return try createPublicView(template: "blog/blog", uri: uri, parameters: parameters, user: loggedInUser, disqusName: disqusName, siteTwitterHandle: siteTwitterHandle)
return try createPublicView(template: "blog/blog", uri: uri, parameters: parameters, user: loggedInUser)
}

func blogPostView(uri: URI, post: BlogPost, author: BlogUser, user: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View {
func blogPostView(uri: URI, post: BlogPost, author: BlogUser, user: BlogUser?) throws -> View {

var parameters: [String: Vapor.Node] = [:]
parameters["post"] = try post.makeNode(in: BlogPostContext.all)
@@ -261,10 +263,10 @@ struct LeafViewFactory: ViewFactory {
} catch {}
}

return try createPublicView(template: "blog/blogpost", uri: uri, parameters: parameters, user: user, disqusName: disqusName, siteTwitterHandle: siteTwitterHandle)
return try createPublicView(template: "blog/blogpost", uri: uri, parameters: parameters, user: user)
}

func tagView(uri: URI, tag: BlogTag, paginatedPosts: Page<BlogPost>, user: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View {
func tagView(uri: URI, tag: BlogTag, paginatedPosts: Page<BlogPost>, user: BlogUser?) throws -> View {

var parameters: [String: NodeRepresentable] = [:]
parameters["tag"] = try tag.makeNode(in: BlogTagContext.withPostCount)
@@ -274,32 +276,32 @@ struct LeafViewFactory: ViewFactory {
parameters["posts"] = try paginatedPosts.makeNode(for: uri, in: BlogPostContext.longSnippet)
}

return try createPublicView(template: "blog/tag", uri: uri, parameters: parameters, user: user, disqusName: disqusName, siteTwitterHandle: siteTwitterHandle)
return try createPublicView(template: "blog/tag", uri: uri, parameters: parameters, user: user)
}

func allTagsView(uri: URI, allTags: [BlogTag], user: BlogUser?, siteTwitterHandle: String?) throws -> View {
func allTagsView(uri: URI, allTags: [BlogTag], user: BlogUser?) throws -> View {
var parameters: [String: NodeRepresentable] = [:]

if allTags.count > 0 {
let sortedTags = allTags.sorted { return (try? $0.sortedPosts().count() > $1.sortedPosts().count()) ?? false }
parameters["tags"] = try sortedTags.makeNode(in: BlogTagContext.withPostCount)
}

return try createPublicView(template: "blog/tags", uri: uri, parameters: parameters, user: user, siteTwitterHandle: siteTwitterHandle)
return try createPublicView(template: "blog/tags", uri: uri, parameters: parameters, user: user)
}

func allAuthorsView(uri: URI, allAuthors: [BlogUser], user: BlogUser?, siteTwitterHandle: String?) throws -> View {
func allAuthorsView(uri: URI, allAuthors: [BlogUser], user: BlogUser?) throws -> View {
var parameters: [String: NodeRepresentable] = [:]

if allAuthors.count > 0 {
let sortedAuthors = allAuthors.sorted { return (try? $0.sortedPosts().count() > $1.sortedPosts().count()) ?? false }
parameters["authors"] = try sortedAuthors.makeNode(in: BlogUserContext.withPostCount)
}

return try createPublicView(template: "blog/authors", uri: uri, parameters: parameters, user: user, siteTwitterHandle: siteTwitterHandle)
return try createPublicView(template: "blog/authors", uri: uri, parameters: parameters, user: user)
}

private func createPublicView(template: String, uri: URI, parameters: [String: NodeRepresentable], user: BlogUser? = nil, disqusName: String? = nil, siteTwitterHandle: String? = nil) throws -> View {
private func createPublicView(template: String, uri: URI, parameters: [String: NodeRepresentable], user: BlogUser? = nil) throws -> View {
var viewParameters = parameters

viewParameters["uri"] = uri.description.makeNode(in: nil)
@@ -11,12 +11,12 @@ protocol ViewFactory {
func createLoginView(loginWarning: Bool, errors: [String]?, username: String?, password: String?) throws -> View
func createBlogAdminView(errors: [String]?) throws -> View
func createResetPasswordView(errors: [String]?, passwordError: Bool?, confirmPasswordError: Bool?) throws -> View
func createProfileView(uri: URI, author: BlogUser, isMyProfile: Bool, paginatedPosts: Page<BlogPost>, loggedInUser: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View
func createProfileView(uri: URI, author: BlogUser, isMyProfile: Bool, paginatedPosts: Page<BlogPost>, loggedInUser: BlogUser?) throws -> View

// MARK: - Blog Controller
func blogIndexView(uri: URI, paginatedPosts: Page<BlogPost>, tags: [BlogTag], authors: [BlogUser], loggedInUser: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View
func blogPostView(uri: URI, post: BlogPost, author: BlogUser, user: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View
func tagView(uri: URI, tag: BlogTag, paginatedPosts: Page<BlogPost>, user: BlogUser?, disqusName: String?, siteTwitterHandle: String?) throws -> View
func allAuthorsView(uri: URI, allAuthors: [BlogUser], user: BlogUser?, siteTwitterHandle: String?) throws -> View
func allTagsView(uri: URI, allTags: [BlogTag], user: BlogUser?, siteTwitterHandle: String?) throws -> View
func blogIndexView(uri: URI, paginatedPosts: Page<BlogPost>, tags: [BlogTag], authors: [BlogUser], loggedInUser: BlogUser?) throws -> View
func blogPostView(uri: URI, post: BlogPost, author: BlogUser, user: BlogUser?) throws -> View
func tagView(uri: URI, tag: BlogTag, paginatedPosts: Page<BlogPost>, user: BlogUser?) throws -> View
func allAuthorsView(uri: URI, allAuthors: [BlogUser], user: BlogUser?) throws -> View
func allTagsView(uri: URI, allTags: [BlogTag], user: BlogUser?) throws -> View
}
@@ -22,7 +22,7 @@ class BlogAdminControllerTests: XCTestCase {
let enableAuthorsPages = drop.config["enableAuthorsPages"]?.bool ?? true
let enableTagsPages = drop.config["enableTagsPages"]?.bool ?? true

let blogController = BlogController(drop: drop, pathCreator: pathCreator, viewFactory: viewFactory, postsPerPage: 5, enableAuthorsPages: enableAuthorsPages, enableTagsPages: enableTagsPages, config: drop.config)
let blogController = BlogController(drop: drop, pathCreator: pathCreator, viewFactory: viewFactory, postsPerPage: 5, enableAuthorsPages: enableAuthorsPages, enableTagsPages: enableTagsPages)
blogController.addRoutes()

let database = Database(try MemoryDriver(()))
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.