Users¶
Use the Users
class when setting up your users in hyfiles
like this:
(setv users
(Users
[{"admin" ;; username
"password" ;; password
:nickname "admin"} ;; extra optional data
{"user1" "password1"
:attribute "blah"
:nickname "mynickname"
:email "admin@example.com"}]))
Create the Users object by giving it a list where
each list item is a dictionary
with user data. Each user entry is required to have at least on
key:value
pair which is assumed to be username:password
and
can therefore be accessed by the Variable
Plugin
as (Variable "username")
and
(Variable "password")
respectively.
To use the optional user data, do the same but replace
username/password with the symbol name you specified earlier, for
example (Variable "nickname")
will return admin
if the first
user is active and mynickname
if the second one is.
- class Users(users, active_user=None)[source]¶
Class holding all the users of the application.
Users inherits from
DataStructure
, and contains the users set up in hyfiles. Each user is anUser
object. The data from aUsers
object can be accessed same way like from theDataStore
.
The Users
class inherits from DataStore
where each element is a User
class containing data about a single user:
- class User(username, password, **kwargs)[source]¶
Class holding user related information.
User
objects are created inside theUsers
. EachUser
object contains at least theusername
and thepassword
. Every time aPlugin
generates an output, it is saved in theUser
object. If thePlugin
is aCookie
or aHeader
, the output will be stored in the thecookies
andheaders
attributes respectively. Otherwise they’ll be saved insidedata
.- username¶
A string containing the user’s email or username used to log in.
- password¶
A string containing the user’s password.
- cookies¶
A
CookieStore
object containing all of the collected cookies for this user. TheCookie
plugin only writes here.
- headers¶
A
HeaderStore
object containing all of the collected headers for this user. TheHeader
plugin only writes here.
- __init__(username, password, **kwargs)[source]¶
Initializes a
User
object.Creates an object for easy access to user specific information. It’s used to store the
username
,password
,cookies
,headers
, and otherdata
extracted from thePlugin
objects.- Parameters
username (
str
) – A string with the username used for the login process.password (
str
) – A string with the password used for the login process.**kwargs – A dictionary with additional data about the user.
- set_cookie(cookie)[source]¶
Sets the
cookies
for the user.Given a
Cookie
object, update the user’scookies
attribute to include thisCookie's
value.
- set_cookies_from_dict(data)[source]¶
Set user’s
cookies
from a dictionary.Given a dictionary of cookie values as strings, convert them to
Cookie
objects, and load them in theUser
object respectively.- Parameters
data (
Dict
[str
,str
]) – A dictionary of strings corresponding to cookie keys and values.- Return type
None
- set_header(header)[source]¶
Sets the
headers
for the user.Given a
Header
object, update the user’sheaders
attribute to include this header value.
- set_headers_from_dict(data)[source]¶
Set user’s
headers
from a dictionary.Given a dictionary of header values as strings, convert them to
Header
objects, and load them in theUser
object respectively.- Parameters
data (
Dict
[str
,str
]) – A dictionary of strings corresponding to header keys and values.- Return type
None
- set_data(data)[source]¶
Sets the
data
for the user.Given a
Plugin
, update the user’sdata
attribute to include this data.