The form validators check for errors in the form inputs, not failed
authentication. Once the form is accepted, the auth.login() method then
checks to see if the user exists and the proper password was submitted. If
not, it sets session.flash to auth.messages.invalid_login and then does a
redirect.
Anthony
On Friday, May 16, 2014 7:21:52 PM UTC-4, sasogeek wrote:
>
> I have a custom login form that displays the error when the email is
> invalid (eg. like someone submits an email with a wrong email format, i.e,
> without @domain.com for example), but when an email that's not in the
> database is submitted, nothing happens, the page just reloads.
>
> Also, if an email that's in the database is submitted with a wrong
> password, the page just reloads... it's not recorded in login.errors (my
> custom form.errors)
> here's all the code relating to the login form. (I've tried both
> crud.settings.hideerror=True and crud.settings.hideerror=False, doesn't
> work) --Remember though that login.errors returns invalid email when the
> email format is wrong.
>
> Model (db.py)
> db = DAL('sqlite://storage.sqlite')
> response.generic_patterns = ['*'] if request.is_local else []
> auth = Auth(db, hmac_key=Auth.get_or_create_key())
> crud = Crud(db)
> crud.settings.hideerror=False
> ...
> ...
> ...
> db.define_table(
> auth.settings.table_user_name,
> Field('full_name', length=128, default=''),
> Field('email', length=128, default='', unique=True),
> Field('password', 'password', length=512,
> readable=False, label='Password'),
> Field('registration_key', length=512,
> writable=False, readable=False, default=''),
> Field('reset_password_key', length=512,
> writable=False, readable=False, default=''),
> Field('registration_id', length=512,
> writable=False, readable=False, default=''),
> format="%(full_name)s")
>
> custom_auth_table = db[auth.settings.table_user_name] # get the
> custom_auth_table
> custom_auth_table.full_name.requires =
> IS_NOT_EMPTY(error_message=auth.messages.is_empty)
> custom_auth_table.password.requires = [CRYPT()]
> custom_auth_table.email.requires = [
> IS_EMAIL(error_message='Invalid Email'),
> IS_NOT_IN_DB(db, custom_auth_table.email)]
>
>
> Controller (default.py)
> def home():
> login = auth.login(next="index")
> register = auth.register(next="tos")
> return dict(login=login, register=register)
>
>
> View (default/home.html)
> ...
> <body {{if login.errors!="":}}
> onload="jQuery('#loginerror').modal('show')">{{pass}}
> ...
> ...
> <div class="navbar-collapse nav-main-collapse collapse pull-left">
> <nav class="nav-main">
> <ul class="nav nav-pills nav-main scroll-menu" id="topMain">
> {{=login.custom.begin}}
> <li>
> <span style="margin-top:19px;display:inline-block;
> color:#ffffff;">Email:</span> {{=login.custom.widget.email}}
> </li>
> <li>
> <span style="margin-top:19px;display:inline-block;
> color:#ffffff">Password:</span> {{=login.custom.widget.password}}
> </li>
> <li>
> {{=login.custom.submit}}
> </li>
> {{=login.custom.end}}
> </ul>
> </nav>
> </div>
> ...
> ...
> <div class="modal fade bs-example-modal-lg" id="loginerror" tabindex="-1"
> role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
> <div class="modal-dialog modal-lg">
> <div class="modal-content">
> <div class="modal-header"><!-- modal header -->
> <button type="button" class="close" data-dismiss="modal"
> aria-hidden="true">×</button>
> <h4 class="modal-title alert alert-danger" id="myModalLabel"><i class="fa
> fa-hand-o-down"></i> Error Logging In</h4>
> </div><!-- /modal header -->
>
> <!-- modal body -->
> <div class="modal-body">
> <div class="alert alert-warning">
> {{if login.errors:}}
> {{=login.errors}}
> {{pass}}
> </div>
> </div>
> <!-- /modal body -->
>
> </div>
> </div>
> </div>
> ...
>
>
> How do I detect the incorrect password error and also the email not in
> database error? the ...email.requires=IS_NOT_IN_DB I believe allows my
> register form to work so that people can sign up. login also works
> perfectly if all the details are correct. I just need to fix this error
> issue. already searched similar topics but i'm not making any headway...
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.