User management à la Lino¶
This is a tested document. The following instructions are used for initialization:
>>> from lino import startup >>> startup('lino_book.projects.min1.settings.demo') >>> from lino.api.doctest import *
The most Linoish way to create a root user (or a set of demo users) is to run
prep. This will reset the database to a virgin state and then load
demo fixture, which will create our well-known demo users Robin,
Rolf, Romain, Rando, Rik, Ronaldo ... depending on your
If you don't want to reset your database, then you can write a script
and run it with
run. For example:
from lino.api.shell import users obj = users.User(username="root") obj.set_password("1234!") obj.full_clean() obj.save()
Note that the password field of a newly created user is empty,
and the account therefore cannot be used to log in. If you create
a new user manually using the web interface, you must click their
ChangePassword action and set their password.
>>> u = users.User(username="test") >>> u.full_clean() >>> u.save()
Since we didn't set a password, Django stores a "non usable" password, and the
User.check_password() method returns False:
>>> u.password '!...' >>> u.check_password('') False
>>> u.has_usable_password() False
When setting the password for a newly created user, leave the field Current password empty.
>>> ses = rt.login('robin') >>> values = dict(current="", new1="1234", new2="1234") >>> rv = ses.run(u.change_password, action_param_values=values) >>> print(rv['message']) New password has been set for test.
Note that a site administrator (a user having the
lino.core.roles.SiteAdmin role) never needs to specify the current
password when setting a new password for any user.