Storage SQlite and Python

35 views
Skip to first unread message

Nicolas Hiblot

unread,
Jun 13, 2019, 11:02:25 AM6/13/19
to web2py-users
Dear All,

I have to modify the Storage DB and for some reasons I have to do it via a controller
I already know how to get informations from the DB
Juste like te last loggued session as :

lastUserLogged  = db(db.auth_event.description.contains('connect')).select(orderby=~db.auth_event.time_stamp,limitby=(0, 1)).first().user_id

But today I would like to do something else (i don't know how to do it properly)

How to (in python)

1. Change a already existing password of a user if I kow the username of the user (username or ID)
2. Create a new user if it's possible (with a username and a password of course)
3. List all the users in the storage db by username
4. Delete user (with username) if it's possible (if it's exist)

if you have the solution for one of this question ( or for all)
Really and Great thanks in advance


黄祥

unread,
Jun 13, 2019, 11:14:09 AM6/13/19
to web2py-users
pls try (not tested) 
1. Change a already existing password of a user if I kow the username of the user (username or ID)

db(db.auth_user.id == 2).update(password = db.auth_user.password.validate("password")[0] ) 

2. Create a new user if it's possible (with a username and a password of course)

db.auth_user.insert(first_name = 'first', last_name = 'last', 
email = 'em...@email.com', username = 'first_last', 
password = db.auth_user.password.validate("password")[0] ) 

3. List all the users in the storage db by username
 
db(db.auth_user.id > 0).select()
or
db().select(db.auth_user.ALL) 

4. Delete user (with username) if it's possible (if it's exist)
 
db(db.auth_user. username == 'first_last').delete() 

ref:

best regards,
stifan

Nicolas Hiblot

unread,
Jun 13, 2019, 11:20:05 AM6/13/19
to web2py-users

Thank you so much
I will test it this evening
But I will say to you Thanks even if something is wrong

I will publish the results tomorrow evening

Regards

Dave S

unread,
Jun 13, 2019, 4:23:42 PM6/13/19
to web...@googlegroups.com


On Thursday, June 13, 2019 at 8:20:05 AM UTC-7, Nicolas Hiblot wrote:

Thank you so much
I will test it this evening
But I will say to you Thanks even if something is wrong

I will publish the results tomorrow evening

Regards


The second URL has the script (in 2 pieces), the first includes Leonel's answer to the question.

And in the welcome app distributed with Web2py, the user() function at the end of controllers/default.py hooks into auth, and the navbar menus include links to user().

/dps


/dps
 
Reply all
Reply to author
Forward
0 new messages