Skip to main content

Store Implementation for Users in MongoDB

Project description

MongoDB User Stores for Python

Frappy MongoDB Store Implementation for Users and UserTokens for Python

  1. Usage
  2. Methods

Usage

from frappymongouser import UserStore, UserTokenStore

MONGO_URL = "mongodb://localhost:27017"  # use your MongoDB url and add potential credentials

# this is how the stores are instantiated
user_store = UserStore(mongo_url=MONGO_URL, mongo_db="databaseName", collection_name="users")
token_store = UserTokenStore(mongo_url=MONGO_URL, mongo_db="databaseName", collection_name="userTokens")

# example usage: retrieve all documents
user_list = user_store.get_all() 
for user in user_list:
    # user is of type User and has attributes
    print(user.email, user.permissions)

Methods

Base methods for both stores provided by pbu

UserStore

  • create_local_user(username, password, permissions) - will create a new local user. The password will be MD5 encoded. The same encoding mechanism used for the login check.
  • login_with_password(username, password) - will attempt to perform a login with the provided credentials.
  • change_password(user_id, new_password) - update the users password using MD5 to encode the password.
  • update_permissions(user_id, permissions) - completely overwrites the permissions of a user with the provided.
  • update_profile(user_id, new_profile) - completely overwrites the profile of a user with the provided value
  • get_by_username(username) - fetches a user by it's username attribute.
  • initial_local_user_check(initial_username, initial_password, initial_permissions) - this function can be called when using local users only. It is already incorporated in the frappyflaskauth package when using local logins. It will check if there are any existing users. If there are no users in the system yet, this will create an initial user with the provided credentials and permissions that can be used as initial administrator account. If no permissions are provided, the user will receive the admin permission, which is also the default to manage users using the package frappyflaskauth (and/or @frappy/react-authentication
  • create_api_key(user_id) - the function will update a user's apiKey key in the database and return the new key. The key is something like this: e31d7880-e968-4195-96ac-4be8798f1915 and a str.
  • get_users_with_api_key() - retrieves a list of users that have an API key set (apiKey exists) - only used in context of admin functions
  • revoke_api_key(user_id) - removes an API key from a user leaving the user without an active API key.

UserTokenStore

  • create(user_id, token, lifetime) - simple, just creates a new token. The lifetime is provided as datetime.timedelta (and defaults to 30 days)
  • get_by_token(token) - searches for a specific token and returns a matching entry or None
  • clean_up_expired() - checking the expired flag on each token and deleting entries that exceed their lifetime
  • update_token(token_id) - just updates the last_update date of the token - deprecated, because rather useless

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

frappymongouser-1.5.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

frappymongouser-1.5.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file frappymongouser-1.5.1.tar.gz.

File metadata

  • Download URL: frappymongouser-1.5.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.12

File hashes

Hashes for frappymongouser-1.5.1.tar.gz
Algorithm Hash digest
SHA256 e6d9a7348a1a24e101b74cd8487245c9bdf58ecaa9f7f88b6ff9a15d8d557c5f
MD5 cc2bdb67a91e6693eace7d69766d7b5e
BLAKE2b-256 dc7f83570c1bc6a8912d2cd19e012218be5ae960f166cb4e69fe10cf6d1e8d51

See more details on using hashes here.

File details

Details for the file frappymongouser-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: frappymongouser-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.12

File hashes

Hashes for frappymongouser-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cec511407d768ec9523fd5d23d5f988232ea292055079ca4ecb4d861e040c0fb
MD5 4f19f3599be15c542c624d812e56d01c
BLAKE2b-256 8fc833159dd34fdbbd0b3ac54ceffe597c70e60fdf3f1d7f33a2a18165b42ac4

See more details on using hashes here.

Supported by

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