<commit_before>//
// Created by <NAME> on 5/12/17.
//

import Auth
import Foundation
import HTTP
import Routing
import Vapor

private let error = Abort.custom(status: .forbidden, message: "Invalid credentials.")
private let protect = ProtectMiddleware(error: error)
private let pc = PostController()
private let uc = UserController()

func registerAPIs(droplet: Droplet) {
    droplet.grouped("api").grouped(protect).group("post") {postGroup in
        postGroup.post(handler: pc.create)
    }

    droplet.grouped("api").group("users") {userGroup in
        userGroup.grouped(protect).get(User.self, "posts") {req, user in
            return try pc.viewPosts(request: req, user: user)
        }

        userGroup.post("new", handler: uc.create)
        userGroup.post("login", handler: uc.login)
    }
}

func registerViews(droplet: Droplet) {
    droplet.group("post") {postGroup in
        postGroup.get("create") {req in
            return try droplet.view.make("post.html")
        }
    }

    droplet.group("users") {userGroup in
        userGroup.get("new") {req in
            return try droplet.view.make("users/new.html")
        }

        userGroup.get("login") {req in
            return try droplet.view.make("users/login.html")
        }
    }
}<commit_msg>make login required on the post page<commit_after>//
// Created by <NAME> on 5/12/17.
//

import Auth
import Foundation
import HTTP
import Routing
import Vapor

private let error = Abort.custom(status: .forbidden, message: "Invalid credentials.")
private let protect = ProtectMiddleware(error: error)
private let pc = PostController()
private let uc = UserController()

func registerAPIs(droplet: Droplet) {
    droplet.grouped("api").grouped(protect).group("post") {postGroup in
        postGroup.post(handler: pc.create)
    }

    droplet.grouped("api").group("users") {userGroup in
        userGroup.grouped(protect).get(User.self, "posts") {req, user in
            return try pc.viewPosts(request: req, user: user)
        }

        userGroup.post("new", handler: uc.create)
        userGroup.post("login", handler: uc.login)
    }
}

func registerViews(droplet: Droplet) {
    droplet.group("post") {postGroup in
        postGroup.grouped(protect).get("create") {req in
            return try droplet.view.make("post.html")
        }
    }

    droplet.group("users") {userGroup in
        userGroup.get("new") {req in
            return try droplet.view.make("users/new.html")
        }

        userGroup.get("login") {req in
            return try droplet.view.make("users/login.html")
        }
    }
}
{'fraction_non_alphanumeric': 0.13253477588871715, 'fraction_numerical': 0.0038639876352395673, 'mean_word_length': 2.8990963855421685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4872021', 'n_tokens_mistral': 815, 'n_tokens_neox': 778, 'n_words': 190}