create auth_user programatically?

701 views
Skip to first unread message

Carlos

unread,
Nov 15, 2010, 7:42:31 PM11/15/10
to web2py-users
Hi,

What's the best way to create an auth_user programatically?.

If I do db.auth_user.insert(...), then the password is not encrypted
and the validations are not executed, as far as I can tell.

In order to accomplish this, is it possible to execute a
crud.create(...) as if the form data was already posted, such that the
insert is done automatically (but without any web requests)?.

Thanks,

Carlos

ron_m

unread,
Nov 16, 2010, 1:29:40 AM11/16/10
to web2py-users
Look in gluon/tools.py at the Auth class, function register to see how
it is done with the code behind the register form. Some of this
function builds the form for initial posting, then on submit the
function is revisited and the real work of adding the user is done in
the if form.accepts(....): area of the function.

villas

unread,
Nov 16, 2010, 4:34:16 AM11/16/10
to web2py-users
I'm sure that you can insert a user easily enough. I think you'll
need the CRYPT validator to encrypt the password.

-D

mdipierro

unread,
Nov 16, 2010, 7:07:21 AM11/16/10
to web2py-users
db.auth_user.insert(....password=db.auth_user.password.validate(password),...)

Carlos

unread,
Nov 16, 2010, 2:28:07 PM11/16/10
to web2py-users
Thanks, but I can still insert multiple users with the same login
(email/password combination), which should not be allowed.

I need to have the same validations that are executed when the user
tries to register via web requests.

Is there anything automatic I can use or should I check manually?.

Furthermore is there a way I can programatically execute a crud.create
with data I provide (as if it came from a web request)?.

Thanks again,

Carlos


On Nov 16, 6:07 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> db.auth_user.insert(....password=db.auth_user.password.validate(password),. ..)
Reply all
Reply to author
Forward
0 new messages