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 | // 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) ... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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" ) |
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 | 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) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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) ... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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) ... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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 |
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 97 98 99 100 101 102 | 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