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.2.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.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Riki Usermanager-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 d4cff828233753ef2642e966e52d8b8b05e1e5090897dab8fd1f5fe7f41f7819
MD5 aef89db5c10e184dc08127ebe14bb714
BLAKE2b-256 dd9c3f39bbf5dacb561509e7e87968a42883eb1e49e65e701773e5673f6bba80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Riki_Usermanager-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca7ed6842b1d4ca08eb967c35e38cf56cb681c74fbc13d140f5ba54845f4abe8
MD5 415ab7e00cf5df94b7faf9052cb9fde0
BLAKE2b-256 cb350c25a0a3a1e172b6a469e988babdced5a4f8ecb9ffb266e43c3c6ee48baf

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