import uuid


def generate_csrf_token(controller):
    """ Generates a new csrf token and stores it in the session"""
    session = controller.session
    if '_csrf_token' not in session:
        session['_csrf_token'] = uuid.uuid4()
    return session['_csrf_token']