I'm working on a plugin for a website.  Essentially a user of the external
website (we'll call it Shopify), can click on a link to add my service to
their webstore.  So Shopify uses a URL like:
http://localhost:8080/shopify/addStore?timestamp=1260635800&shop=kemmer-hahn-and-kunde1221.myshopify.com&signature=e68e54623fd662db8262ccae5a4255c9&t=d1c685b222bada796438214e79516fc1
This provides me with everything I need to get access to the Shopify (and
now, my) customer.  However, they have not yet registered with my site yet.
So I have code that handles the case where they are already logged in, and
where they just need to login.  When I try to register them, the code
doesn't work.  The User.loginRedirect seems to get lost somewhere.  This
tells me that I don't understand something.  Like is there an easier way?
:)  And more importantly what am I missing?

Here's the Boot:
 LiftRules.dispatch.append {
      case Req("shopify" :: "install" :: "addStore" :: Nil, _,_ ) =>
        ShopifyUI.addStore _
    }

And then this is the addStore implementation:
object ShopifyUI {
  def addStore(): Box[net.liftweb.http.LiftResponse] = {

    object shopInfoVar extends SessionVar[Box[ShopInfo]](Empty)

    var shopInfo: ShopInfo = ShopInfo.createInstance

    param("timestamp") match {
      case Full(x) => shopInfo.timestamp.set(new Date(x.toLong))
      case _ => error("timestamp", "Shopify did not send a timestamp.")
    }

    param("shop") match {
      case Full(x) => shopInfo.shopName.set(List.fromString(x, '.').first)
      case _ => error("shop", "Shopify did not send a shop url.")
    }

    param("signature") match {
      case Full(x) => shopInfo.signature.set(x)
      case _ => error("signature", "Shopify did not send a signature.")
    }

    param("t") match {
      case Full(x) => {
        shopInfo.authenticationToken.set(x)
        shopInfo.shopPassword.set(ShopifyService.createPasswordForStore(x))
      }
      case _ => error("t", "Shopify did not send an authentication token
(the 't' param)")
    }
    if( ! errors.isEmpty && !shopInfoVar.is.isEmpty) {
      clearCurrentNotices
      shopInfo = shopInfoVar.is.open_!
    }
    if (User.loggedIn_?) {
      shopInfo.owner.set(User.currentUser.open_!.id)
      shopInfo.save
    } else {
      shopInfoVar(Full(shopInfo))
      User.loginRedirect(Full("/shopify/install/addStore"))
    }
    Full(RedirectResponse("/shopinfo/list"))
  }


}


-- 
James A Barrows

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to