Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a2f700af9e
Fetching contributors…

Cannot retrieve contributors at this time

file 96 lines (79 sloc) 3.095 kb
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/*
* Copyright 2010 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package bootstrap.liftweb

import _root_.net.liftweb.util._
import _root_.net.liftweb.http._
import _root_.net.liftweb.http.provider.HTTPRequest
import _root_.net.liftweb.sitemap._
import _root_.net.liftweb.sitemap.Loc._
import Helpers._
import _root_.net.liftweb.mapper.{DB, ConnectionManager, Schemifier, DefaultConnectionIdentifier, ConnectionIdentifier,StandardDBVendor}
import _root_.java.sql.{Connection, DriverManager}
import _root_.fbc.example.model._
import _root_.javax.servlet.http.{HttpServletRequest}
import _root_.net.liftweb.common._

import net.liftweb.ext_api.facebook.FacebookConnect

/**
* A class that's instantiated early and run. It allows the application
* to modify lift's environment
*/
class Boot {
  def boot {
    if (!DB.jndiJdbcConnAvailable_?)
      DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)

    // where to search snippet
    LiftRules.addToPackages("fbc.example")
    Schemifier.schemify(true, Schemifier.infoF _, User)

    // Build SiteMap
    val entries = Menu(Loc("Home", List("index"), "Home")) :: User.sitemap
    LiftRules.setSiteMap(SiteMap(entries:_*))

    /*
* Show the spinny image when an Ajax call starts
*/
    LiftRules.ajaxStart =
      Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)

    /*
* Make the spinny image go away when it ends
*/
    LiftRules.ajaxEnd =
      Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)

    LiftRules.early.append(makeUtf8)
    
    LiftRules.loggedInTest = Full(() => User.loggedIn_?)

    S.addAround(DB.buildLoanWrapper)
    
    //this is optional. Provides SSO for users already logged in to facebook.com
    LiftRules.earlyInStateful.append {
      case req if !User.loggedIn_? =>
        for {
          c <- FacebookConnect.client
          user <- User.findByFbId(c.session.uid)
        } User.logUserIn(user)
      case Failure(_,_,_) | Empty =>
    }
    
    //this is really important for fb connect
    LiftRules.useXhtmlMimeType = false
    
    LiftRules.liftRequest.append {
      case Req("xd_receiver" :: Nil, _, _) => false
    }
  }

  /**
* Force the request to be UTF-8
*/
  private def makeUtf8(req: HTTPRequest): Unit = {req.setCharacterEncoding("UTF-8")}

}

object DBVendor extends StandardDBVendor("org.h2.Driver",
                                        "jdbc:h2:mem:lift;DB_CLOSE_DELAY=-1",
                                        Empty,
                                        Empty)
Something went wrong with that request. Please try again.