MegaProtoUser login

325 views
Skip to first unread message

Ján Raska

unread,
Oct 22, 2010, 4:37:41 AM10/22/10
to lif...@googlegroups.com
Hi everybody,
I have a small site running on Lift using MegaProtoUser for user management. I included User.menus into my sitemap and everything runs perfectly fine. My page consists of a header containing a logo, narrow left panel with menu and wide right panel for a content. All is done through "default" template using <lift:surround>

All pages require user to be logged in and it works perfectly with Lift, however, the login page is displayed within the "default" template at content panel. I would like the login form to be displayed at the separate page, using different template (let's say "login-tmp"), so that there is just the login form displayed in a centered panel and nothing else, no header, no menu panel, just plain login form. I tried to override MetaMegaProtoUser's loginXhtml method, but it didn't allow me to put there <lift:surround with="login_tmp" at="content">. Is it possible to somehow separate the login form from the "default" template?

Also I'm wondering, is it possible, that user logs in using a nickname (or login name) instead of an email?

Thanks

Rusho

David Pollak

unread,
Oct 22, 2010, 8:39:36 AM10/22/10
to lif...@googlegroups.com
On Fri, Oct 22, 2010 at 1:37 AM, Ján Raska <ras...@gmail.com> wrote:
Hi everybody,
I have a small site running on Lift using MegaProtoUser for user management. I included User.menus into my sitemap and everything runs perfectly fine. My page consists of a header containing a logo, narrow left panel with menu and wide right panel for a content. All is done through "default" template using <lift:surround>

All pages require user to be logged in and it works perfectly with Lift, however, the login page is displayed within the "default" template at content panel. I would like the login form to be displayed at the separate page, using different template (let's say "login-tmp"), so that there is just the login form displayed in a centered panel and nothing else, no header, no menu panel, just plain login form.

  /**
   * The LocParams for the menu item for login.
   * Overwrite in order to add custom LocParams. Attention: Not calling super will change the default behavior!
   */
  override protected def loginMenuLocParams: List[LocParam[Unit]] =
    If(notLoggedIn_? _, S.??("already.logged.in")) ::
    Template(() => /// return the template to your login page here) ::
    Nil
 
I tried to override MetaMegaProtoUser's loginXhtml method, but it didn't allow me to put there <lift:surround with="login_tmp" at="content">. Is it possible to somehow separate the login form from the "default" template?

Also I'm wondering, is it possible, that user logs in using a nickname (or login name) instead of an email?

Not today, but next week (once issue 684 which is currently on review board) makes it into the codebase.  http://reviewboard.liftweb.net/r/465/

Once 684 makes it into master, you'll be able to do:

 
  /**
   * Given an email address, find the user
   */
  override protected def findUserByEmail(email: String): Box[TheUserType] = find(By(myusernamecolumn, email))



 

Thanks

Rusho



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Rogelio

unread,
Oct 22, 2010, 8:41:00 AM10/22/10
to Lift
I'm new with lift myself, but I think you may have answered your own
question -- you say "using a different template (let's say "login-
tmp")".
So it seems like you could at the very least copy "default.html" over
to "login-tmp.html" and within "login-tmp.html" take out everything
that
you don't need (titles, footers, etc) and then use that for your
"lift:surround". (Of course you would need a "content" div in there
as the binding point).
I don't think you need to modify loginXhtml to do any of this. In
whatever html file you use to display your initial login page, just
put the
<lift:surround with="login_tmp" at="content"> at the top instead of
"<lift:surround with="default" at="content">
But again, I'm new myself. Hope I've not misunderstood your question.

As for logging in with a login name instead of email -- yes you can do
this.
For my app, I just copied the "def login ..." from the protouser.scala
code and modified to use the "loginid" in my database
instead of the email, like so (this in in my "User.scala" model file)
--

override def login = {
if (S.post_?) {
S.param("username").
flatMap(username => getSingleton.find(By(loginid, username)))
match {
.....
>  smime.p7s
> 5KViewDownload

Ján Raska

unread,
Oct 23, 2010, 8:11:20 AM10/23/10
to lif...@googlegroups.com
Thanks David,

overriding loginMenuLocParams managed to display my own login template (though I don't know why it didn't allow me to use S.??("already.logged.in"), complaining that () => LiftResponse is required). However, I might have missed how to specify a login form in such template, because though I do have there a form with action set to "/user_mgt/login" and fields with names such as "username" and "password", the actual login doesn't work and it displays login form again

Rusho


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

David Pollak

unread,
Oct 23, 2010, 8:54:10 AM10/23/10
to lif...@googlegroups.com


2010/10/23 Ján Raska <ras...@gmail.com>

Thanks David,

overriding loginMenuLocParams managed to display my own login template (though I don't know why it didn't allow me to use S.??("already.logged.in"),

Because S ?? "already.logged.in" returns a String.  A String is not a LiftResponse.
 
complaining that () => LiftResponse is required). However, I might have missed how to specify a login form in such template, because though I do have there a form with action set to "/user_mgt/login" and fields with names such as "username" and "password", the actual login doesn't work and it displays login form again

Please post your code in a compilable, runnable (either via Maven or SBT) as a GitHub project and I'll look at it.
 

Ján Raska

unread,
Oct 25, 2010, 5:37:13 AM10/25/10
to lif...@googlegroups.com
Hi David,

I know that S ?? "already.logged.in" returns a String, however, I found in ProtoUser.scala definition:
  /**
   * The LocParams for the menu item for login.
   * Overwrite in order to add custom LocParams. Attention: Not calling super will change the default behavior!
   */
  protected def loginMenuLocParams: List[LocParam[Unit]] =
    If(notLoggedIn_? _, S.??("already.logged.in")) ::
    Template(() => wrapIt(login)) ::
    Nil

That's why I was suprised, that I couldn't us it same way in the overriden method.

I posted my code to GitHub as you asked, I'll be much thankful if you can have a look: git://github.com/rusho/cmstest.git

Thanks

Rusho

David Pollak

unread,
Nov 16, 2010, 3:27:11 PM11/16/10
to lif...@googlegroups.com


2010/10/25 Ján Raska <ras...@gmail.com>

Hi David,

I know that S ?? "already.logged.in" returns a String, however, I found in ProtoUser.scala definition:
  /**
   * The LocParams for the menu item for login.
   * Overwrite in order to add custom LocParams. Attention: Not calling super will change the default behavior!
   */
  protected def loginMenuLocParams: List[LocParam[Unit]] =
    If(notLoggedIn_? _, S.??("already.logged.in")) ::
    Template(() => wrapIt(login)) ::
    Nil

That's why I was suprised, that I couldn't us it same way in the overriden method.

You have to import net.liftweb.sitemap.Loc._ to get the implicit conversion from => String to FailMsg.
 
Reply all
Reply to author
Forward
0 new messages