I had the same problem: I want an extra field in the login form without an
additional field in auth_user. Some months ago I wrote a proposal how to
implement it, but I did not get any response. Here is the proposal again:
A proposal to extend the register form and the login form
The issue:
I want to have a register form with an extra field,* which should not be
part of auth_user*. The purpose: a new user can only register if this field
contrains (e.g.) some special code. This code can be checked by a
validation function, set by auth.settings.register_onvalidation
I have tried to change the form which is created by def user in default.py.
The result was a very long code which is hard to read and which needs some
additional statements for the error message. A better way would be a small
modification of gluon/tools.py. And the same could be done with the
login-form.
We need only 6 additional lines in gluon/tools.py
At the end of default_settings (line 1206) add:
register_extra_fields=[],
login_extra_fields=[]
At the end of settings.update (line 1506) add:
register_extra_fields = [],
lo
gin_extra_fields = []
I
n def login() add after line 2561ff:
if settings.remember_me_form:
extra_fields = [
Field('remember_me', 'boolean', default=False,
label = self.messages.label_remember_me)]
else:
extra_fields = []
extra_fields += self.settings.login_extra_fields
In def register() add after line 2862 ff:
if self.settings.register_verify_password:
extra_fields = [
Field("password_two", "password", requires=IS_EQUAL_TO(
request.post_vars.get(passfield, None),
error_message=self.messages.mismatched_password),
label=current.T("Confirm Password"))]
else:
extra_fields = []
extra_fields += self.settings.register_extra_fields
How to use:
Yes, it’s only a very simple check: the user has to write “VALID” into the
field “extracode”.
In db.py, before auth.define_tables:
def validate_registercode(form):
if form.vars.extracode != "VALID":
form.errors.extracode=T("Invalid extra code")
auth.settings.register_extra_fields=
[Field('extracode',
label='My extracode',
comment='This is the extracode')
]
auth.settings.register_onvalidation=[validate_registercode]
That’s all. Now we have a nice register form with an extra field labeled “My
extracode”. If the user does not know the right answer “VALID” he could
not register. All css attributes are the same as in the remaining register
form.
Regards, Martin
2016-01-28 3:32 GMT+01:00 Spokes <[email protected]>:
> Hi, Massimo. Yes, I'm trying to add an extra input field to the
> registration form. The above code does this successfully, with the
> exception of validation, which is not performed. If I'm not mistaken, the
> 'extra_fields' way of solving this problem will add an otherwise useless
> field to the 'auth_user' table, which doesn't seem like the optimal way of
> going about it.
>
> --
> 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.
>
--
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.