Skip to main content

User Manager utilities for the Riki

Project description

Riki UserManager

Classes for handling user CRUD and login/logout for CSC485 project.

riki_usermanager

riki_usermanager.User

AuthMethodEnum Objects

class AuthMethodEnum(Enum)

Enum that stores supported authentication methods

User Objects

@dataclass
class User()

Represents User entry in the sqlite3 database

Variables: * username (str): The user's name. Used as the primary key in the database. * password (str): The user's password. Stored as text in sqlite. * roles (str): The roles a user has. It's a list of string, but will be stored as a single text value in sqlite. * authentication_method (int): Used to reference an authentication method by number. * authenticated (bool): Flag for whether a user has been authenticated. Stored in sqlite as an int. * hash (str): Stored result if password has been hashed. * anonymous (bool): Flag for anonymous users. Since a registered user is not anonymous, this is not stored in sqlite.

is_authenticated

 | is_authenticated()

Returns whether the User is authenticated.

Arguments:

  • self int - The current instance of User

Returns:

bool:authentication state

is_active

 | is_active()

Returns whether the User is active. Required by flask-login.

Arguments:

  • self int - The current instance of User

Returns:

bool:active state

is_anonymous

 | is_anonymous()

Returns whether the User is anonymous. In this case, all users are not.

Arguments:

  • self int - The current instance of User

Returns:

bool:anonymous state

get_id

 | get_id()

Returns the username of a user. Required by flask-login.

Arguments:

  • self int - The current instance of User

Returns:

str:username

from_dict

 | @staticmethod
 | from_dict(user: Dict[str, Any]) -> 'User'

converts array of sql data into dictionary

Arguments:

  • data List[str] - sql array of data

Returns:

Dict[str, Any]: Dictionary of values

riki_usermanager.UserManager

UserManager Objects

class UserManager()

A very simple User Manager, that manages User objects and writes them to database

__init__

 | __init__(db: sqlite3.Connection)

Create UserManager object

Args:

  • db (sqlite3.Connection): preexisting sqlite3 connection object

login

 | login(username: str, password: str) -> Union[User, Literal[False]]

Logins in a user after username and password have been validated

Arguments:

  • username String - username

Returns:

  • bool - True on success, else False

logout

 | logout(user: User) -> bool

Logs out the current user

Returns:

  • bool - True on success, else False

register

 | register(user: 'User') -> Union['User', Literal[False]]

Creates a new user and authenticates a new user after username and password are validated

Arguments:

  • user User - User object

Returns:

  • bool - True on success, else False

unregister

 | unregister(user: User) -> bool

Deletes current user's profile

Returns:

  • bool - True on success, else False

add_user

 | add_user(user: 'User') -> Union[User, Literal[False]]

Creates new user in the database

Arguments:

  • user User - User object

Raises:

  • NotImplementedError - if authentication method is not implemented

Returns:

  • bool - True on success, else False

get_user

 | get_user(username: str) -> Union['User', None]

Get User from the database

Args:

  • name (str): users name

Returns:

  • User | None: User object if user with the given username is found, otherwise nothing is returned.

delete_user

 | delete_user(username: str) -> bool

Deletes user from the database

Arguments:

  • name str - users username

Returns:

  • bool - True if delete was successful, otherwise False

update

 | update(user: 'User') -> bool

Update user from userdata dictionary

Arguments:

  • name str - users username
  • userdata Dict[str, Any] - dictionary of user data

Returns:

  • bool - True if delete was successful, otherwise False

check_password

 | @staticmethod
 | check_password(user: User, password: str) -> bool

Check if user password matches the password in the database

Arguments:

  • password str - user password

Returns:

  • bool - did password match

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Riki Usermanager-1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Riki_Usermanager-1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file Riki Usermanager-1.0.tar.gz.

File metadata

  • Download URL: Riki Usermanager-1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for Riki Usermanager-1.0.tar.gz
Algorithm Hash digest
SHA256 c1f566043225aa8e9e288331d55c4b0230be32b465401ef174b06433aad62395
MD5 706cb61d65867355a238299596bcc4c0
BLAKE2b-256 3cb058a3fdc4634d9285f073861c6bb8108739ba1b899339dab6efb4f8412e6a

See more details on using hashes here.

File details

Details for the file Riki_Usermanager-1.0-py3-none-any.whl.

File metadata

  • Download URL: Riki_Usermanager-1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for Riki_Usermanager-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0715b5e868f61ca07a4503b7cc25d5a45be2d72f9745f4d64eac3425696ad07
MD5 49553565976e9ffd0edb30505c8cd30a
BLAKE2b-256 e4845ae565d6ec4ade0a462e378bfe566f8cb5f48475bcc81cc54acad9573adf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page