pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
Boot.scala
(3263B)
1 package bootstrap.liftweb
2
3 import scala.xml.{Null, UnprefixedAttribute}
4 import javax.mail.internet.MimeMessage
5 import net.liftweb._
6 import common._
7 import http._
8 import util._
9 import util.Helpers._
10 import inc.pyc.config._
11 import GoogleAnalytics.dsl._
12 import inc.pyc.lib._
13 import inc.pyc.rest._
14 import inc.pyc.model.{SystemUser, User}
15 import net.liftmodules.extras.{Gravatar, LiftExtras}
16 import net.liftmodules.mongoauth.MongoAuth
17 import inc.pyc.rest.IdVerificationUpload
18
19 /**
20 * A class that's instantiated early and run. It allows the application
21 * to modify lift's environment
22 */
23 class Boot extends Loggable {
24 def boot {
25 logger.info("Run Mode: "+Props.mode.toString)
26
27 // init mongodb
28 MongoConfig.init()
29
30 // init auth-mongo
31 MongoAuth.authUserMeta.default.set(User)
32 MongoAuth.loginTokenAfterUrl.default.set(Site.password.url)
33 MongoAuth.siteName.default.set("PYC")
34 MongoAuth.systemEmail.default.set(SystemUser.user.email.get)
35 MongoAuth.systemUsername.default.set(SystemUser.user.fname.get)
36
37 // For S.loggedIn_? and TestCond.loggedIn/Out builtin snippet
38 LiftRules.loggedInTest = Full(() => User.isLoggedIn)
39
40 // set comet timeout to 1000s -- ELB timeout is 1020s/17m
41 // https://forums.aws.amazon.com/message.jspa?messageID=553422#553422
42 LiftRules.cometRequestTimeout = Full(1000)
43
44 // checks for ExtSession cookie
45 LiftRules.earlyInStateful.append(User.testForExtSession)
46
47 // config an email sender
48 SmtpMailer.init
49
50 // where to search snippet
51 LiftRules.addToPackages("inc.pyc")
52
53 // set the default htmlProperties
54 LiftRules.htmlProperties.default.set((r: Req) => new Html5Properties(r.userAgent))
55
56 // Build SiteMap
57 LiftRules.setSiteMap(Site.siteMap)
58
59 // Error handler
60 ErrorHandler.init
61
62 // 404 handler
63 LiftRules.uriNotFound.prepend(NamedPF("404handler") {
64 case (req, failure) =>
65 NotFoundAsTemplate(ParsePath(List("404"), "html", false, false))
66 })
67
68 // Force the request to be UTF-8
69 LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
70
71 // set name to generate correct minified js and css files
72 LiftExtras.artifactName.default.set("pyc-0.0.1")
73
74 // don't include the liftAjax.js code. It's served statically.
75 LiftRules.autoIncludeAjaxCalc.default.set(() => (session: LiftSession) => false)
76
77 // Mailer
78 Mailer.devModeSend.default.set((m: MimeMessage) => logger.info("Dev mode message:\n" + prettyPrintMime(m)))
79 Mailer.testModeSend.default.set((m: MimeMessage) => logger.info("Test mode message:\n" + prettyPrintMime(m)))
80
81 // Google Analytics
82 GoogleAnalytics.angularInit {
83 only when S.param("noga").isEmpty
84 }()
85
86 // Website sitemap
87 Sitemap.init()
88
89 // ID Verification API
90 IdVerificationUpload.init()
91
92 // Rest service for ATM's
93 AtmRest.init()
94 }
95
96 private def prettyPrintMime(m: MimeMessage): String = {
97 val buf = new StringBuilder
98 val hdrs = m.getAllHeaderLines
99 while (hdrs.hasMoreElements)
100 buf ++= hdrs.nextElement.toString + "\n"
101
102 val out =
103 """
104 |%s
105 |====================================
106 |%s
107 """.format(buf.toString, m.getContent.toString).stripMargin
108
109 out
110 }
111 }