Hello fellow programmers,
as you might know from my previous questions I’m an absolute newbie in the Scala/Lift world, therefore I might ask some trivial questions, sorry for that 🙂
I’d love to make a custom login form to authenticate a user (the user is not authenticated via a database but instead via an API call through Google Protocol Buffer), so all I need to do is grab the inputs and send them to the API.
So far, I came up with my login.html page:
<div id="loginContainer" class="loginMainContainer centerContainer">
<div class="loginInputWrapper">
<input type="text" name="loginName" id="loginName" class="txtLogin" />
</div>
<div class="loginInputWrapper">
<input type="password" name="loginPassword" id="loginPassword" class="pwLogin" />
</div>
<div class="buttonWrapper loginButtonWrapper">
<button type="submit" class="hiddenButton qsbfont">Login</button>
</div>
</div>
and I want to grap the loginName and loginPassword field values. Which is the (best) way to achieve this?
I tried to get it with this class and add it to the snippet package, but I can’t figure out how to wire these two together. Here’s my snippet:
object MyAuthentication {
def authentication(name: String, password: String) = {
def validate(user: String, password: String): Boolean = {
if(user == "tac" && password == "tac") true else false
}
def createUser(loggedIn: Boolean): Boolean = {
if (loggedIn) {
val user = new MyUser
user.setName(name)
user.setUID(1111)
user.setLoginState(loggedIn)
user.setLanguage("en_EN")
}
loggedIn
}
if (createUser(validate(name, password)))
<span>loggedIn</span>
else
<span>failure!</span>
}
def render = SHtml.onSubmitList(credentials => {
authentication(credentials(0), credentials(1))
})
}
So, is it possible like that? How can I wire these two things together?
Not a complete answer, but hopefully a pointer for where to start:
Check out this Ajax Form demo. The related scala source is here and the template source is here.
This seems to be similar to what you’re trying to do. The way they tie everything up is to wrap the fields of what-would-be-the-form in a
<lift:snippet type="AjaxForm:show" form="post">. Then on the server side, theshowmethod takes the template xml (they useGroupas the argument type, but I’m pretty sure you can interchange that forNodeSeq) and bind the fields to Ajax-enabled fields.Note the
import SHtml._in the demo’s source… frankly I dislike the demos for doing this as it makes it hard to understand where methods are coming from, for newcomers to Lift. Methods likeuntrustedSelect,select,submit, andajaxCallare coming from that import.As a last note, I find Lift’s Google Groups page to be more helpful than SO for Lift-related questions. I’m no Lift guru, but the people there are. Good luck!