Store Implementation for Users in MongoDB
MongoDB User Stores for Python
Frappy MongoDB Store Implementation for Users and UserTokens for Python
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)
Base methods for both stores provided by
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
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
frappyflaskauthpackage 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
adminpermission, which is also the default to manage users using the package
create_api_key(user_id)- the function will update a user's
apiKeykey in the database and return the new key. The key is something like this:
get_users_with_api_key()- retrieves a list of users that have an API key set (
apiKeyexists) - 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.
create(user_id, token, lifetime)- simple, just creates a new token. The
lifetimeis provided as
datetime.timedelta(and defaults to 30 days)
get_by_token(token)- searches for a specific token and returns a matching entry or
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_updatedate of the token - deprecated, because rather useless
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
frappymongouser-1.5.1.tar.gz (5.0 kB view hashes)
Hashes for frappymongouser-1.5.1-py3-none-any.whl