Skip to main content

Login.py

Login.py is a simple library for Flask that makes you able to handle login easily without getting plenty of useless lines of code.

Installation

pip3 install git+https://gitea.com/chopin42/login.py

Usage

You can find the full demo of login.py here. You can also find the source code of login.py here.

initLogin(app, db)

This function is used to create the User class. Having this function is necessary for the rest of the program. Without this, the Users cannot get stored into the database.

from flask import Flask, request
from flask_login import UserMixin
from flask_sqlalchemy import SQLAlchemy
from login import *

# Create the "app" and "db" variables
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SECRET_KEY'] = 'aghzi vnguierhtrutizo hard to guess indeeed'
db = SQLAlchemy(app)

# Create the User class and add it to the database
User = initLogin(app, db)
db.create_all()

createUser(username, password, db, User)

This function is used to sign up a new user into the database. This is an example of usage:

@app.route('/register/post', methods=['POST'])
def register():
    try:
        createUser(request.form['username'], request.form['password'], db, User)
        return "New user created you are now logged in as " + current_user.username
    except: 
    		return "This username is already taken"

loginUser(username, password, User)

This function is used to login a user, that means that the user must already be in the database.

@app.route('/login/post', methods=['POST'])
def login():
    try:
        loginUser(request.form['username'], request.form['password'], User)
        return "You are now logged in as " + current_user.username
    except: 
    		return "Invalid username or password"

logout_user()

This is not a function from login.py, but a function from flask_login. The usage of this function is very simple:

@app.route('/logout')
def logout(): 
    logout_user()
    return "You are now logged out."

@login_required

When you add this line under a url route, it locks the page to the logged in users. The users that are not logged will have a Unauthorized error showing up.

@app.route('/locked')
@login_required # Using login_required to make a page private
def locked(): 
	return "Hello " + current_user.username + " welcome to your private page."

Metadata

Release files for loginpy 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loginpy 0.0.2
File Size Uploaded Provenance Actions
loginpy-0.0.2.tar.gz 3.1 kB Without provenance Details for loginpy-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for loginpy 0.0.2
File Interpreter ABI Platform Actions
loginpy-0.0.2-py3-none-any.whl Python 3 none any Details for loginpy-0.0.2-py3-none-any.whl

Total release size: 6.9 kB

Release files / loginpy-0.0.2.tar.gz

Download URL loginpy-0.0.2.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bf608c0cafdf0d5f5c553f0bab12d9926bf71c155d9b3828a5814ee83005df36
BLAKE2b-256 checksum
How to use checksums
b22fa08bfe92fb65feb31e23a1535d7625af40f85b471316771bec3b00b4da01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release files / loginpy-0.0.2-py3-none-any.whl

Download URL loginpy-0.0.2-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72104c7967ff453f95e9d804b0b752e32159a170b7fa08a5f1e8653598fc73e4
BLAKE2b-256 checksum
How to use checksums
483861ab74b27656934214102c7a21a674c1231a252e2293fb0fc5189958c5cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Security for loginpy 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page