Removing email uniqueness from registration form and using other custom field for unique id of users

57 views
Skip to first unread message

Ramashish Gaurav

unread,
Jul 2, 2015, 6:02:51 AM7/2/15
to web...@googlegroups.com
Hello all !

I need to create a registration form where users can have same email ids, but different user id... say for example :

There are four users A, B, C, and D. There is a common email account they share, say "ab...@gmail.com" . Before I explain further, let me state that users wouldn't be able to register themselves via the application, but the admin of application would create unique user_id's for each users from database administration side. So let the users have unique user_id's as a123, b123, c123 and d123. 

Thus they can log in into the application by feeding in their unique user_id's and password, and when an email might be needed to send them, I would select their name or user_id and send a mail. Thus the mail arrive into an account ( "ab...@gmail.com" ) commonly accessed by all of them. I guess the changes are to be made in registration form and log in form.

If there's a way to achieve it, please share it with me. Thanks for your interest ! 

黄祥

unread,
Jul 2, 2015, 7:50:50 AM7/2/15
to web...@googlegroups.com
perhaps you can use, username (username = True) and override the email settings (custom_auth_table.email.unique = False)

ref:
http://web2py.com/books/default/chapter/29/09/access-control#Customizing-Auth

best regards,
stifan

Anthony

unread,
Jul 2, 2015, 8:00:27 AM7/2/15
to web...@googlegroups.com, steve.van...@gmail.com
On Thursday, July 2, 2015 at 7:50:50 AM UTC-4, 黄祥 wrote:
perhaps you can use, username (username = True) and override the email settings (custom_auth_table.email.unique = False)

Unique email addresses are enforced via a NOT_IS_IN_DB validator, not via the "unique" attribute. So, either define a custom auth_user table, or after defining the standard table, change the "requires" attribute of db.auth_user.email.

Anthony

Anthony

unread,
Jul 2, 2015, 8:01:01 AM7/2/15
to web...@googlegroups.com, ramas...@gmail.com
Do the users all trust each other? What happens when one wants to request a password reset?

Ramashish Gaurav

unread,
Jul 2, 2015, 9:58:34 AM7/2/15
to web...@googlegroups.com, ramas...@gmail.com
Thanks for your interest Anthony ! Actually I am building a tool for an intra-net application to be used by utmost 50 users. So I can expect that the users are all known to each other and trust each other.

For password reset option, no doubt a mail would  be sent for it. However the admin of this application might want to remove this feature via app and in that case the user will have to contact the admin for it.

I'll implement your suggestions and let you know my progress... Thanks again!.

Ramashish Gaurav

unread,
Jul 2, 2015, 10:01:31 AM7/2/15
to web...@googlegroups.com
By the way... what changes need to be made in log in for, so that user can feed his unique user_id and password?

villas

unread,
Jul 2, 2015, 11:48:19 AM7/2/15
to web...@googlegroups.com
Hi Ramashish

Your best option (by far!) is to consider this...

Gmail treats all these email addresses as equivalent for delivering emails:
The suffix must follow the '+' sign.

Use this facility for allowing each user to have his/her own log in. 

Regards, D

Ramashish Gaurav

unread,
Jul 3, 2015, 3:26:22 AM7/3/15
to web...@googlegroups.com
Hello all,

I thank Villas, Anthony and Stiffan, for their interest. I have come up with the solution to my problem. 

I defined a custom registration form, and included 'username' as one of its fields and made it true. And also removed the IS_NOT_IN_DB() constraint from the email field. As of now it works as per my expectation. If some issue occurs, I'll update this post.

Here is my code:

File > db.py

from gluon.tools import Auth, Service, PluginManager

auth = Auth(db)
service = Service()
plugins = PluginManager()

#Custom auth_table
db.define_table(
    auth.settings.table_user_name,
    Field('first_name',length=128,default=''),
    Field('last_name',length=128,default=''),
    Field('username','string',length=128),
    Field('email',length=128),
    Field('password','password'),
    Field('department','string'),
    Field('registration_key', length=512,                # required
          writable=False, readable=False,default=''),
    Field('reset_password_key', length=512,              # required
          writable=False, readable=False,default=''),
    Field('registration_id', length=512,                 # required
         writable=False, readable=False,default=''))


## create all tables needed by auth if not custom tables
auth.define_tables(username=True, signature=False)
custom_auth_table = db[auth.settings.table_user]
custom_auth_table.username.requires = IS_NOT_IN_DB(db, custom_auth_table.username)
custom_auth_table.password.requires = [CRYPT()]
custom_auth_table.email.requires = [
  IS_EMAIL(error_message=auth.messages.invalid_email)]
    

Its noteworthy that no " unique=True " is required in username field, but it ensures its uniqueness itself. 

If you have suggestions about this code, or if I am committing a silly mistake, please correct me. 

Regards,
Ramashish

Ramashish Gaurav

unread,
Jul 3, 2015, 3:28:04 AM7/3/15
to web...@googlegroups.com
So as of now, the user is able to use his unique username to log in, instead of email.
Reply all
Reply to author
Forward
0 new messages