liftweb的用户注册实现-1.esme

lift的函数

UI = +(snippet,template)  

esme的用户注册

 

+

 

在Boot中, SiteMap 中定义 Menu ,将 template中的lift:signup关联到

 

Menu(Loc("sign_up", List("signup"), S.?("base_menu_signup"),
          Snippet("signup", User.signupForm _),
          Unless(User.loggedIn_? _, S.?("base_menu_sign_up_error")))) 

snippet

User中signupForm的定义如下:

 

 

def signupForm(xhtml: NodeSeq): NodeSeq = {
    /*
     * S.referer Returns the 'Referer' HTTP header attribute
     */
    val from = S.referer openOr "/"
    val user = User.create
    val auth = UserAuth.defaultAuthModule.createHolder()
    
    /*
     * S.invokedAs
     * Returns the 'type' S attribute. This corresponds to the current Snippet's name. For example, the snippet:
     * <lift:Hello.world />
     * Will return "Hello.world".
    */
    val snippetName = S.invokedAs

      
    def genForm(xhtml: NodeSeq): NodeSeq = {
      /*
       *bind (namespace: String, xml: NodeSeq, params: BindParam*): NodeSeq
       *Bind a set of values to parameters and attributes in a block of XML.
       */
      bind("signup", xhtml,
            /*
             * new SuperArrowAssoc (name: String)
             * def -%> (in: (NodeSeq) ⇒ NodeSeq): FuncBindParam
             */
           "nickname" -%> user.nickname.toForm, //def toForm : Box[Elem] Create an input field for the item
           "firstname" -%> user.firstName.toForm,
           "lastname" -%> user.lastName.toForm,
           "image_url" -%> user.imageUrl.toForm,
           "timezone" -%> user.timezone.toForm,
           "locale" -%> user.locale.toForm,
           "credentials" -> auth.toForm,
           /*
            * The SHtml object defines a suite of XHTML element generator methods
            *  to simplify the creation of markup, particularly with forms and AJAX
            *  
            * def submit (value: String, func: () ⇒ Any, attrs: ElemAttr*): Elem
            *  Generates a form submission button.
            */
           "submit" -%> SHtml.submit(S.?("base_user_ui_signup"), doSubmit _)
      ) ++ SHtml.hidden(() => { doSubmit})
    }
    
    def processEntryAdd() {
        logger.debug("processEntryAdd: " + firstName + ", " + lastName)
    }

    def doSubmit() {
      /*
       * S.mapSnippet
       * Associates a name with a snippet function 'func'. This can be used to 
       * change a snippet mapping on a per-request basis.
       */
      S.mapSnippet(snippetName, genForm) //why?
      user.validate ::: auth.validate match {
        case Nil =>
          user.save
          auth.save(user)
          User.logUserIn(user)
          S.notice(S.?("base_user_msg_welcome", user.niceName))
          S.redirectTo(from)

        case fe =>
          S.error(fe)
      }
    } 
    genForm(xhtml)
}
 

doSubmit是个有副作用的函数,把user 和 auth保存起来,让user登录进来

 

template

 

注册页面 signup.html:

 

<lift:signup form="post" id = "validateForm">
					<div id="form-signup">
							<signup:credentials/>	
							
							<div class="post-form-row">
								<label class="main"><lift:loc>ui_sign_up_nickname</lift:loc></label>
								<signup:nickname class="inputBox2"/>
							</div>	
							
							<div class="post-form-row">
								<label class="main"><lift:loc>ui_sign_up_firstname</lift:loc></label>
								 <signup:firstname class="inputBox2"/>
							</div>	
							
							<div class="post-form-row">
								<label class="main"> <lift:loc>ui_sign_up_lastname</lift:loc></label>
								<signup:lastname class="inputBox2"/>
							</div>	
							
							<div class="post-form-row">
								<label class="main"> <lift:loc>ui_sign_up_image_url</lift:loc></label>
								<signup:image_url class="inputBox2"/>
							</div>	
						
							
							<div class="post-form-row">
								<label class="main"> <lift:loc>ui_sign_up_timezone</lift:loc></label>
								<signup:timezone class="inputBox2"/>
							</div>	
							
							<div class="post-form-row">
								<label class="main"><lift:loc>ui_sign_up_locale</lift:loc></label>
								<signup:locale class="inputBox2"/>
							</div>
								
							<div class="post-form-row">
								<div class="submit-btn">
									<signup:submit type="image" src="images/btn-signup-big.gif" />
								</div>
							</div>	
							
					</div><!--form-signup-->
</lift:signup>

 

 

注意:

 


<signup:credentials/>

 

 

对应 :

 

"credentials" -> auth.toForm

 

auth的toForm定义如下:

 

 

def toForm: NodeSeq =
    TemplateFinder.findAnyTemplate("templates-hidden" :: "upw_signup_form" :: Nil).map(
      xhtml =>
      bind("signup", xhtml,
           "email" -%> SHtml.text(email, s => email = s.trim.toLowerCase),
           "pwd1" -%> SHtml.password(pwd1, s => pwd1 = s.trim),
           "pwd2" -%> SHtml.password(pwd2, s => pwd2 = s.trim))
    ) openOr NodeSeq.Empty

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CMPP (短消息协议) 是一种标准的短信中心和手机运营商之间的通信协议,常用于短信应用开发中。CMPP 2.0 是 CMPP 协议的一个版本,它规定了客户端(如手机应用或短信API)如何与短信中心交互以发送短信。 在CMPP 2.0客户端发送短信的基本步骤如下: 1. **初始化连接**: - 客户端需要连接到短信中心提供的IP地址和端口,并建立TCP连接。 - 双方通常会交换身份验证信息,例如用户名和密码,以验证客户端的身份。 2. **建立会话**: - 客户端发送一个请求,如SVC_USER或SVC_PASSTHROUGH,来创建一个服务会话,表明其功能需求。 3. **发送请求**: - 使用CMD_SEND短信命令,客户端准备一条短信的结构体,包含发送者、接收者、短信内容等信息。 - 在命令体中填充这些字段,并设置适当的标志,如短信类型(SMS_TYPE_NORMAL)。 4. **数据编码**: - 将短信内容转换为CMPP协议支持的编码格式,通常是7位ASCII或Unicode。 5. **发送命令**: - 客户端将命令打包成CMPP的消息体,并发送给短信中心。 6. **等待响应**: - 短信中心处理请求后,会返回一个响应,可能包含命令结果码和额外的信息。 7. **检查响应**: - 客户端解析响应,检查命令结果码是否成功(如ESME_ROK),确认短信是否已发送。 8. **关闭会话和连接**: - 如果发送成功,可以关闭会话并断开TCP连接,完成发送操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值