Lerndatenbank/lernplattform/classes.py

33 lines
1.2 KiB
Python
Raw Normal View History

2024-08-06 20:11:36 +02:00
from flask import Flask, request, session
from lernplattform import app
from lernplattform.models import User
class login():
"""
A class for handling user login functionality.
Attributes:
user_name (str): The username to be checked for authentication.
Methods:
__init__(self, user_name=None): Initializes the login object with a given user name.
check(user_name): A static method that checks if the provided user name is valid.
login(self): Prints "Login" to indicate that the login method has been called.
"""
def __init__(self, user_name=None):
self.user_name = user_name # Initialize the user name attribute for the login class
def check(user_name):
if user_name is None:
2024-08-06 20:11:36 +02:00
session['logged_in'] = False
session['user_name'] = 'Gast'
return False # Return False if the user name is not provided
else:
2024-08-06 20:11:36 +02:00
session['logged_in'] = True
session['user_name'] = user_name
return True # Otherwise, return True indicating a valid user name
2024-08-06 20:11:36 +02:00
def login(self):
print("Login") # Print "Login" to indicate that the login method has been called