// Your template
<lift:OpenID.form>
<openId:renderForm/>
</lift:OpenID.form>
// Your snippet
class OpenID {
def renderForm(xhtml: NodeSeq) : NodeSeq = {
SimpleOpenIdVendor.loginForm
}
}
class Boot {
...
// This is needed in order to process the login and logout requests and also to process
// the response comming from OpenID provider
LiftRules.dispatch.append(SimpleOpenIdVendor.dispatchPF)
...
}
trait SimpleOpenIdVendor extends OpenIdVendor {
type UserType = Identifier
type ConsumerType = OpenIdConsumer[UserType]
def currentUser = OpenIdUser.is
def postLogin(id: Box[Identifier],res: VerificationResult): Unit = {
id match {
case Full(id) => S.notice("Welcome "+id)
case _ => S.error("Failed to authenticate")
}
OpenIdUser(id)
}
def logUserOut() {
OpenIdUser.remove
}
def displayUser(in: UserType): NodeSeq = Text("Welcome "+in)
def createAConsumer = new AnyRef with OpenIDConsumer[UserType]
}
object SimpleOpenIdVendor extends SimpleOpenIdVendor
import net.liftweb.amqp._
import com.rabbitmq.client._
val params = new ConnectionParameters
// All of the params, exchanges, and queues are all just example data.
params.setUsername("guest")
params.setPassword("guest")
params.setVirtualHost("/")
params.setRequestedHeartbeat(0)
val factory = new ConnectionFactory(params)
val amqp = new StringAMQPSender(factory, "localhost", 5672, "mult", "routeroute")
amqp.start
amqp ! AMQPMessage("hi")
import net.liftweb.amqp._
import com.rabbitmq.client._
/**
* Example Dispatcher that listens on an example queue and exchange. Use this
* as your guiding example for creating your own Dispatcher.
*
*/
class ExampleSerializedAMQPDispatcher[T](factory: ConnectionFactory, host: String, port: Int)
extends AMQPDispatcher[T](factory, host, port) {
override def configure(channel: Channel) {
// Get the ticket.
val ticket = channel.accessRequest("/data")
// Set up the exchange and queue
channel.exchangeDeclare(ticket, "mult", "direct")
channel.queueDeclare(ticket, "mult_queue")
channel.queueBind(ticket, "mult_queue", "mult", "routeroute")
// Use the short version of the basicConsume method for convenience.
channel.basicConsume(ticket, "mult_queue", false, new SerializedConsumer(channel, this))
}
}
/**
* Example class that accepts Strings coming in from the
* ExampleSerializedAMQPDispatcher.
*/
class ExampleStringAMQPListener {
val params = new ConnectionParameters
params.setUsername("guest")
params.setPassword("guest")
params.setVirtualHost("/")
params.setRequestedHeartbeat(0)
val factory = new ConnectionFactory(params)
// thor.local is a machine on your network with rabbitmq listening on port 5672
val amqp = new ExampleSerializedAMQPDispatcher[String](factory, "thor.local", 5672)
amqp.start
// Example Listener that just prints the String it receives.
class StringListener extends Actor {
def act = {
react {
case msg@AMQPMessage(contents: String) => println("received: " + msg); act
}
}
}
val stringListener = new StringListener()
stringListener.start
amqp ! AMQPAddListener(stringListener)
}
import net.liftweb.paypal._
object MyPayPalPDT extends PayPalPDT {
override def pdtPath = "paypal_complete"
def paypalAuthToken = Props.get("paypal.authToken") openOr "cannot find auth token from props file"
def pdtResponse: PartialFunction[(PayPalInfo, Req), LiftResponse] = {
case (info, req) => println("— in pdtResponse"); DoRedirectResponse("/account_admin/index");
}
}
// in Boot
def boot(){
...
LiftRules.statelessDispatchTable.append(MyPayPalPDT)
...
}
import net.liftweb.paypal._
object MyPayPalIPN extends PayPalIPN {
def actions = {
case (ClearedPayment, info, req) => // do your processing here
case (RefundedPayment, info, req) => // do refund processing
}
}
// in Boot
def boot(){
...
LiftRules.statelessDispatchTable.append(MyPayPalIPN)
...
}
import net.liftweb.ext_api.facebook._
FacebookRestApi.apiKey = <your API key>;
FacebookRestApi.secret = <your secret>;
// The api key is ontained from System.getProperty("com.facebook.api_key")
// The secreat is obtained from System.setProperty("com.facebook.secret", key)
// Invoke stateless calls
val respNode: Node = FacebookClient !? AuthCreateToken
val authToken = // extract authToken from respNode
// Obtain a stateful client based on the authToken
val faceBookClient = FacebookClient fromAuthToken(authToken)
faceBookClient !? GetFriendLists
import net.liftweb.xmpp._
/**
* An example Chat application that prints to stdout.
*
* @param username is the username to login to at Google Talk: format: something@gmail.com
* @param password is the password for the user account at Google Talk.
*/
class ConsoleChatActor(val username: String, val password: String) extends Actor {
def connf() = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com")
def login(conn: XMPPConnection) = conn.login(username, password)
val xmpp = new XMPPDispatcher(connf, login)
xmpp.start
val chats: Map[String, List[Message]] = new HashMap[String, List[Message]]
val rosterMap: HashMap[String, Presence] = new HashMap[String, Presence]
var roster: Roster = null
def act = loop
def loop {
react {
case Start => {
xmpp ! AddListener(this)
xmpp ! SetPresence(new Presence(Presence.Type.available))
loop
}
case NewChat(c) => {
chats += (c.getParticipant -> Nil)
loop
}
case RecvMsg(chat, msg) => {
println("RecvMsg from: " + msg.getFrom + ": " + msg.getBody);
loop
}
case NewRoster(r) => {
println("getting a new roster: " + r)
this.roster = r
val e: Array[Object] = r.getEntries.toArray.asInstanceOf[Array[Object]]
for (entry <- e) {
val user: String = entry.asInstanceOf[RosterEntry].getUser
rosterMap += (user -> r.getPresence(user))
}
loop
}
case RosterPresenceChanged(p) => {
val user = StringUtils.parseBareAddress(p.getFrom)
println("Roster Update: " + user + " " + p)
// It’s best practice to ask the roster for the presence. This is because
// multiple presences can exist for one user and the roster knows which one
// has priority.
rosterMap += (user -> roster.getPresence(user))
loop
}
case RosterEntriesDeleted(e) => {
println(e)
loop
}
case RosterEntriesUpdated(e) => {
println(e)
loop
}
case RosterEntriesAdded(e) => {
println(e)
loop
}
case a => println(a); loop
}
}
def createChat(to: String) {
xmpp ! CreateChat(to)
}
def sendMessage(to: String, msg: String) {
xmpp ! SendMsg(to, msg)
}
/**
* @returns an Iterable of all users who aren’t unavailable along with their Presence
*/
def availableUsers: Iterable[(String, Presence)] = {
rosterMap.filter((e) => e._2.getType() != Presence.Type.unavailable)
}
}
object ConsoleChatHelper {
/**
* @param u is the username
* @param p is the password
*/
def run(u: String, p: String) = {
val ex = new ConsoleChatActor(u, p)
ex.start
ex ! Start
ex
}
}
// To start the dispatcher just call:
ConsoleChatHelper.run(userName, password);
...
(C) 2012 Lift 2.0 EditionWritten by Derek Chen-Becker, Marius Danciu and Tyler Weir