-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogin.swift
More file actions
39 lines (30 loc) · 901 Bytes
/
login.swift
File metadata and controls
39 lines (30 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// login.swift
// APIDocumentationServer
//
// Created by Jonathan Guthrie on 2017-05-09.
//
//
import PerfectHTTP
import PerfectSession
import PerfectCrypto
import PerfectSessionPostgreSQL
import PerfectLocalAuthentication
extension LocalAuthWebHandlers {
public static func main(data: [String:Any]) throws -> RequestHandler {
return {
request, response in
var context: [String : Any] = ["title": "Perfect API Documentation Server"]
if let i = request.session?.userid, !i.isEmpty { context["authenticated"] = true }
context["csrfToken"] = request.session?.data["csrf"] as? String ?? ""
// add app config vars
for i in WebHandlers.appExtras(request) {
context[i.0] = i.1
}
// gather list of groups and api docs to display
let groups = APIGroup.list()
context["groups"] = groups
response.render(template: "views/login", context: context)
}
}
}