<commit_before>//
//  Router.swift
//  ivsa
//
//  Created by <NAME> on 16/11/2016.
//
//

import Foundation
import Vapor
import HTTP
import Routing

final class AccountRouteCollection: RouteCollection {
    
    typealias Wrapped = HTTP.Responder
    
    private var authMiddleware: TokenAuthMiddleware
    
    init(authMiddleware: TokenAuthMiddleware) {
        self.authMiddleware = authMiddleware
    }
    
    func build<B: RouteBuilder>(_ builder: B) where B.Value == Wrapped {
        
        
        let authenticatedBuilder = builder.grouped(authMiddleware)
        
        authenticatedBuilder.post("register") { request in

            throw Abort.custom(status: .badRequest, message: "Sorry, but the registration  has been closed. For further inquiries please contact us on our fb page.")
            // now take the parameters from the request, and file a registration request
//            guard let registrationJSON = request.json?["registration_data"] else {
//                throw Abort.custom(status: .badRequest, message: "no json with `registration_data` found")
//            }
//            
//            let registrationData: RegistrationData = try registrationJSON.converted()
//            
//            var user = try request.user()
//            user.applicationStatus = .inReview
//            user.registrationDetails = registrationData
//            
//            try user.save()
//            
//            return user
        }
        
        authenticatedBuilder.post("connect", "facebook") { request in
            <commit_msg>open registration for the api for the apps<commit_after>//
//  Router.swift
//  ivsa
//
//  Created by <NAME> on 16/11/2016.
//
//

import Foundation
import Vapor
import HTTP
import Routing

final class AccountRouteCollection: RouteCollection {
    
    typealias Wrapped = HTTP.Responder
    
    private var authMiddleware: TokenAuthMiddleware
    
    init(authMiddleware: TokenAuthMiddleware) {
        self.authMiddleware = authMiddleware
    }
    
    func build<B: RouteBuilder>(_ builder: B) where B.Value == Wrapped {
        
        
        let authenticatedBuilder = builder.grouped(authMiddleware)
        
        authenticatedBuilder.post("register") { request in

            throw Abort.custom(status: .badRequest, message: "Sorry, but the registration  has been closed. For further inquiries please contact us on our fb page.")
            // now take the parameters from the request, and file a registration request
            guard let registrationJSON = request.json?["registration_data"] else {
                throw Abort.custom(status: .badRequest, message: "no json with `registration_data` found")
            }
            
            let registrationData: RegistrationData = try registrationJSON.converted()
            
            var user = try request.user()
            user.applicationStatus = .newApplicant
            user.registrationDetails = registrationData
            
            try user.save()
            
            return user
        }
        
        authenticatedBuilder.post("connect", "facebook") { request in
            
{'fraction_non_alphanumeric': 0.08240887480190175, 'fraction_numerical': 0.005071315372424723, 'mean_word_length': 2.0522243713733075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2875619', 'n_tokens_mistral': 797, 'n_tokens_neox': 768, 'n_words': 233}