Here is t2.login and layout.html changed in t3 so that:

1. when there is a failed login, it keeps the email in the email field
and puts the cursor in the password field
2. if it is an invalid email address it puts the cursor at the end of
the email address so it can be fixed
3. theirs IS a better way to do this - i just don't know how :)
4. i did this cuz retyping email in username fields after login
failure bugs me ;)

-wj

t3/modules/t2.py:

    def login(self,next='index',onlogin=None):
        """
        To use, create a controller:

             def login(): return t2.login()
        """
        request,response,session,cache,T,db=self._globals()
        db.t2_person.email.requires=IS_EMAIL()
        form=SQLFORM(db.t2_person,fields=['email','password'],\
                     hidden=dict(_destination=request.vars._destination),
                     _class='t2-login')
        if FORM.accepts(form,request.vars,session):
             rows=db(db.t2_person.email==form.vars.email)\
                    (db.t2_person.password==form.vars.password)\
                    (db.t2_person.registration_key=='').select()
             if rows:
                 session.t2.person_id=rows[0].id
                 session.t2.person_name=rows[0].name
                 session.t2.person_email=rows[0].email
                 session.flash=self.messages.logged_in
                 if onlogin: onlogin(rows[0])
                 if request.vars._destination:
                     redirect(request.vars._destination)
                 self.redirect(next)
             else:
                 session.flash=self.messages.invalid_login
                 session.email=form.vars.email
# added this next line
                 session.cnt=1
                 self.redirect()
# added this else section
        else:
            if session.email and len(session.email) and not session.cnt:
                 if not form.vars.email:
                     session.email=None
            else:
                if not session.cnt:
                     session.email=form.vars.email

        return form

t3/views/layout.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<title>{{=response.title}}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="{{=response.description}}" />
<meta name="keywords" content="{{=response.keywords}}" />
<meta name="description" content="{{=response.author}}" />
<style>
{{=XML(configuration.styles.replace('APPLICATION',request.application))}}
</style>
{{include 'web2py_ajax.html'}}
<script 
src="/{{=request.application}}/static/scripts/sfmenu.js"></script><script
src="/{{=request.application}}/static/scripts/fancyzoom.min.js"></script><link
charset="utf-8"
href="/{{=request.application}}/static/styles/rating.css"
rel="stylesheet" type="text/css" /><script
src="/{{=request.application}}/static/scripts/rating.js"></script>
<script>$(document).ready(function(){
try { $('.zoom').fancyZoom({scaleImg:true, closeOnClick:true,
directory:"/{{=request.application}}/static/media"}); } catch(e) {};
try { $('.sf-menu').superfish({ animation: {height:'show'}, delay:500
}); } catch(e) {};
});

{{# put cursor at end of text when field is set focus}}

$(function() {
 $('input[type="text"]').bind('focus',function() {
  window.o=this;
  if (o.setSelectionRange)     /* DOM */
   setTimeout('o.setSelectionRange(o.value.length,o.value.length)',2);
  else if (o.createTextRange)     /* IE */
  {
   var r=o.createTextRange();
   r.moveStart('character',o.value.length);
   r.select();
  }
 });
});

{{ # if response.flash has invalid login, set focus to password field }}

{{if response.flash == 'Invalid Login':}}
$(document).ready(function() { $
('#t2_person_password').focus(); });
{{pass}}

</script>
</head>

<body>
    <div class="wrapper">
  <div class="header">
    <div class="title">{{=response.title}}</div>
    <div class="subtitle">{{=response.subtitle}}</div>
    <div class="search">
      <form method="get" action="http://www.google.com/search";>
        <input class="search-text" type="text" name="as_q" value="" size="15"/>
        <input type="hidden" name="as_sitesearch"
value="{{=request.env.http_host}}">
        <input type="submit" class="search-submit" value="Search" />
      </form>
    </div><!-- search //-->
     <div class="authentication">
      {{if t2.logged_in:}}
        {{=A('Profile',_href=URL(r=request,c='default',f='profile'))}} |
        {{=A('Logout',_href=URL(r=request,c='default',f='logout'))}}
      {{else:}}
        {{=A('Login',_href=URL(r=request,c='default',f='login'))}} |
        {{=A('Register',_href=URL(r=request,c='default',f='register'))}} |
        {{=A('Password',_href=URL(r=request,c='default',f='password'))}}
      {{pass}}
    </div><!-- auth //-->
  </div><!-- header //-->
  <div class="menu">{{=t2.menu(response.menu)}}</div>
  <div class="page">
    {{if response.flash:}}<div class="flash">{{=response.flash}}</div>{{pass}}
    <div class="left-column">
      {{try:}}

        {{if form[0][0][1][0]['_name'] == 'email':}}

        <form action="" class="t2-login" enctype="multipart/form-data"
method="post"><table>

        <tr id="t2_person_email__row">
        <td><label for="t2_person_email"
id="t2_person_email__label">Email: </label></td>
        <td><input class="string" id="t2_person_email" name="email"
type="text" value="{{=session.email if session.email else ''}}" />
        {{if form.errors.email:}}
        <div class="error">{{=form.errors.email}}</div>
        <script>
$(document).ready(function() { $
('#t2_person_email').focus(); });
</script>
        {{pass}}

        </td>
        <td></td></tr>

        <tr id="t2_person_password__row"><td><label
for="t2_person_password" id="t2_person_password__label">Password:
</label></td>
        <td><input class="password" id="t2_person_password"
name="password" type="password" />
        {{if form.errors.password:}}
        <div class="error">{{=form.errors.password}}</div>
        {{if not form.errors.email:}}
                <script>
        $(document).ready(function() { $
('#t2_person_password').focus(); });
</script>
{{pass}}
        {{pass}}

        </td><td></td></tr>
        <tr id="submit_record__row"><td></td><td><input type="submit"
value="Submit" /></td>
        <td></td></tr></table>

        {{=form.hidden_fields()}}

       </form>
        {{else:}}
          {{include}}
        {{pass}}
      {{except:}}
        {{include}}
      {{pass}}


    </div>
    <div class="right-column">
     <ul>
      {{for _i in settings.sidebar or []:}}
      <li>
         <h2>{{=_i[0]}}</h2>
         {{if isinstance(_i[1],list):}}
         <ul>
           {{for _j in _i[1]:}}
           <li>{{=A(_j[0],_href=_j[1])}}</li>
           {{pass}}
         </ul>
         {{else:}}
         <p>{{=_i[1]}}</p>
         {{pass}}
      </li>
      {{pass}}
     </ul>
    </div><!-- sidebar //-->
  </div><!-- page //-->
  <div class="footer">
    {{if settings.footer:}}
    {{=XML(settings.footer)}}
    {{else:}}
    <p>Created by {{=response.author}} - Powered by <a
href="http://www.web2py.com";>web2py</a></p>
    {{pass}}  </div><!-- footer //-->
  </div><!-- wrapper //-->
</body>
</html>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to