您的位置:首页 > 其它

lift的初级使用

2015-12-20 00:00 204 查看
现在做了一个登陆界面,初步总结了一下前后台的关系

现在Boot里面配置login页面的siteMap

Menu("Login") / "login", login.html被放在了webapp下面

前台的login.html 似乎需要被类

<div id="loginpage" class="lift:surround?with=dsdd&at=content">的div包起来,最重要的是这个div的class,它让这个div下面的内容被lift:surround包了起来,with后面是一个页面,at的是一个id,但我的dsdd是随便写的,也可以起作用,但去掉with和at就不行,初步猜想,div下面的内容,引用的关于lift的东西,比如:

<form class="lift:LoginForm?form=post">,都是需要

<div id="loginpage" class="lift:surround?with=dsdd&at=content">才能成功起作用的,可能我的分析是错误的,但目前只能这么设想了,后台的loginForm,里面有登陆判断的流程:

object LoginForm {

def render(in: NodeSeq): NodeSeq = {

var nodes=new Queue[NodeSeq]

nodes += in

// use a Scala for-comprehension to evaluate each parameter

for {

r <- S.request

if r.post_? // make sure it's a post

name <- S.param("name") // get the name field

passwd <- S.param("passwd") // get the age field

} {

// if everything goes as expected,

// display a notice and send the user

// back to the home page

S.notice("Name: " + name)

S.notice("Age: " + passwd)

if (User.authenticate(name, passwd) != None)

S.redirectTo("/")

else{

nodes += <div> <span class="label label-warning"> Hi,你的用户名或密码不正确 !!</span> </div>

}

}

// pass through the HTML if we don't get a post and

// all the parameters

<div> {nodes} </div>

}

}

form表单的内容是:

<form class="lift:LoginForm?form=post">

用户名:

<input type="text" id="name" placeholder="用户名:" class="input-large" value="admin2"

name="name">

<br>

密 码:

<input type="password" id="passwd" placeholder="密 码: " class="input-large" value="123456"

name="passwd">

<br>

<br>

<button type="submit" class="btn btn-primary">登 录</button>

<button type="reset" class="btn btn-primary">重 置</button>

</form>

如果登陆失败,就在最后加一个提醒,目前只能用这个笨办法来告诉用户,你的用户名和密码错误了,上一个截图,

登陆前:

admin2是个默认值,是可以登陆的

修改用户名,让它失败,登陆失败后

登陆成功当然就直接跳转了

本文出自 “沐浴心情” 博客,请务必保留此出处http://lj3331.blog.51cto.com/5679179/1020916
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  login lift scala form