create users manually

97 views
Skip to first unread message

Yebach

unread,
Apr 23, 2018, 8:12:33 AM4/23/18
to web2py-users
Hello

I would like to create or import users into auth_users table and then send them e-mails with temp passwords that they could change to login into my app.
I know it is not the most secure way but so far this is the only solution.

How could I achieve that? Or what would be the best way to do that?

thank you

Anthony

unread,
Apr 24, 2018, 10:45:23 AM4/24/18
to web2py-users
You can use the auth.register_bare() method to loop through a set of user records, register each, and then send an email with the temporary password. I think you can also leave out the password altogether, in which case, users will have to go through the password reset process to create a password and log in.

Anthony

Anthony

unread,
Apr 25, 2018, 11:01:30 AM4/25/18
to web2py-users
There is also auth.bulk_register(), which produces a form that allows you to register a set of email addresses and automatically sends out email notifications to the registrants (it does not set temporary passwords, so requires users to create passwords before gaining access). For it to work, you must set auth.settings.bulk_register_enabled=True (it is False by default).

Anthony

Joe Willrich Lutalo

unread,
May 18, 2018, 10:48:35 AM5/18/18
to web2py-users
Thanks, but in the typical application structure, where would you place these function invocations? In my case, am working on an existing application instance, and want to easily add a new user into the db, if possible, merely overriding the password of an existing account with a new one. Just can't find good docs - or am looking in the wrong place?

Anthony

unread,
May 18, 2018, 10:55:28 AM5/18/18
to web...@googlegroups.com
On Friday, May 18, 2018 at 10:48:35 AM UTC-4, Joe Willrich Lutalo wrote:
Thanks, but in the typical application structure, where would you place these function invocations?

It is up to you, depending on your desired workflow. auth.bulk_register() produces a form, so the idea would be to create a controller action to display that form in the user interface. If you instead want to use auth.register_bare(), you would have to write your own custom logic to handle the inserts. You could do this by (a) creating an interface in the web application itself via a controller and view, or (b) manually running the commands in a web2py shell. Of course, if you add a controller action to the web application, you should protect it so only a logged in administrator can access it.

Example:

@auth.requires_membership('administrators')
def invite_users():
   
return dict(form=auth.bulk_register())

Then create an associated view with:

{{=form}}

Anthony
Reply all
Reply to author
Forward
0 new messages