from flask import session, redirect, url_for, request
import os
from functools import wraps

class BaseView:
    @staticmethod
    def login_required(f):
        @wraps(f)
        def decorated_function(*args, **kwargs):
            if 'user_id' not in session:
                return redirect(url_for('auth.login', next=request.url))
            return f(*args, **kwargs)
        return decorated_function

    @staticmethod
    def get_current_user():
        return session.get('user_id'), session.get('username')

    @staticmethod
    def basename_filter(path):
        return os.path.basename(path)