Esempio n. 1
0
def login():
    msg_err, msg_suc = (None,) * 2

    # Case 1 : Complete login form
    if (request.method == 'POST'
        and bool(request.form['email'])    == 1
        and bool(request.form['password']) == 1
    ):
        email    = request.form['email'].lower()
        password = request.form['password']

        # Email form verification
        msg_err = form_email_check(email)

        # Password form verification
        msg_err = form_password_check(password)

        if (msg_err is None):
            # Connect to database
            cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

            # Get user_details
            user_infos      = user_details(cursor, email, None)
            query_count_res = cursor.rowcount

            # Check if query contain result
            if (query_count_res > 0):

                # Get user details
                username    = user_infos[1]
                email       = user_infos[2]
                hashed_pass = user_infos[3]
                lang        = user_infos[4]

                # Verify password POST and hashed password
                pass_verify = pwd_context.verify(password, hashed_pass)

                if (bool(pass_verify == 1)):
                    # Update last connection date
                    date_now = date.today().strftime('%Y-%m-%d')
                    user_upd_last_connection(cursor, username, email, date_now)

                    # Break connection
                    cursor.close()

                    # Create session data
                    session['loggedin'] = True
                    session['username'] = username.capitalize()
                    session['email']    = email
                    session['lang']     = lang.lower()

                    # Success
                    msg_suc = 'Logged in successfully !'

                else:
                    msg_err = 'Incorrect email or password !'
                    cursor.close()

            else:
                msg_err = 'Incorrect email or password !'
                cursor.close()


    # Case 2 : One or more field missing
    elif (request.method == 'POST'
          and (bool(request.form['email'])    == 0
          or   bool(request.form['password']) == 0)
    ):
        msg_err = 'All fields are required !'

    return render_template(
        'users/login.html', 
        title='EasyML - Login',
        msg_err=msg_err,
        msg_suc=msg_suc
    )
Esempio n. 2
0
def home():
    # Check if user is loggedin
    if ('loggedin' in session):

        # Get session details
        username = session['username']
        email = session['email']
        lang = session['lang']

        # Define category tag
        cat_tag = 'HOME'

        # Connect to database
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

        # Get categories of navbar
        navbar_cat = datas_cat_nav(cursor, lang)
        navbar_cat_name = navbar_cat[0]
        navbar_cat_tag = navbar_cat[1]
        navbar_cat_icon = navbar_cat[2]
        navbar_cat_link = navbar_cat[3]

        # Get models of navbar
        navbar_models = datas_mod_nav(cursor, lang, navbar_cat_tag)

        # Get settings of navbar
        navbar_settings = datas_set_nav(cursor, lang)
        navbar_set_name = navbar_settings[0]
        navbar_set_icon = navbar_settings[1]
        navbar_set_link = navbar_settings[2]

        # Get category details
        cat_details = cards_categories(cursor, lang, cat_tag)
        cat_name = cat_details[0]
        cat_link = cat_details[3]

        # Get user ID
        user_infos = user_details(cursor, email, username)
        user_id = user_infos[0]

        # Get favorite list
        favorite = favorite_list(cursor, user_id)

        # Have favorite cards
        if (len(favorite) > 0):

            # Get favorite card datas
            favorite_cards = cards_favorite(cursor, lang, username, email)
            favorite_card_id = favorite_cards[0]
            favorite_card_name = favorite_cards[1]
            favorite_card_desc = favorite_cards[2]
            favorite_card_link = favorite_cards[3]
            favorite_card_img = favorite_cards[4]

            # Remove favorite
            if (request.method == 'POST'
                    and bool(request.form['model_id']) == 1):
                model_id = int(request.form['model_id'])

                # Favorite already existing -> remove favorite
                if (model_id in favorite):
                    favorite_del(cursor, user_id, model_id)

                    # Reload page
                    return redirect(url_for(cat_link))

            # Break connection
            cursor.close()

            return render_template('main/dashboard.html',
                                   title=cat_name,
                                   username=username,
                                   lang=lang,
                                   nav_cat_name=navbar_cat_name,
                                   nav_cat_tag=navbar_cat_tag,
                                   nav_cat_icon=navbar_cat_icon,
                                   nav_cat_lnk=navbar_cat_link,
                                   nav_models=navbar_models,
                                   nav_set_name=navbar_set_name,
                                   nav_set_icon=navbar_set_icon,
                                   nav_set_lnk=navbar_set_link,
                                   cat_tag=cat_tag,
                                   card_id=favorite_card_id,
                                   card_name=favorite_card_name,
                                   card_desc=favorite_card_desc,
                                   card_link=favorite_card_link,
                                   card_image=favorite_card_img,
                                   favorite=favorite)

        else:
            # Break connection
            cursor.close()

            return render_template('main/dashboard.html',
                                   title=cat_name,
                                   username=username,
                                   lang=lang,
                                   nav_cat_name=navbar_cat_name,
                                   nav_cat_tag=navbar_cat_tag,
                                   nav_cat_icon=navbar_cat_icon,
                                   nav_cat_lnk=navbar_cat_link,
                                   nav_models=navbar_models,
                                   nav_set_name=navbar_set_name,
                                   nav_set_icon=navbar_set_icon,
                                   nav_set_lnk=navbar_set_link,
                                   cat_tag=cat_tag,
                                   favorite=favorite)

    else:
        return render_template('home.html', title='Welcome to EasyML')
Esempio n. 3
0
def settings():
    msg_err, msg_suc = (None,) * 2

    # Check if user is loggedin
    if ('loggedin' in session):

        # Get session details
        username = session['username']
        email    = session['email']
        lang     = session['lang']

        # Connect to database
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

        # Get categories of navbar
        navbar_cat      = datas_cat_nav(cursor, lang)
        navbar_cat_name = navbar_cat[0]
        navbar_cat_tag  = navbar_cat[1]
        navbar_cat_icon = navbar_cat[2]
        navbar_cat_link = navbar_cat[3]

        # Get models of navbar
        navbar_models = datas_mod_nav(cursor, lang, navbar_cat_tag)

        # Get settings of navbar
        navbar_settings = datas_set_nav(cursor, lang)
        navbar_set_name = navbar_settings[0]
        navbar_set_icon = navbar_settings[1]
        navbar_set_link = navbar_settings[2]

        # Case 1 : Update all fields
        if (request.method == 'POST'
            and bool(request.form['username'])     == 1
            and bool(request.form['email'])        == 1
            and bool(request.form['password'])     == 1
            and bool(request.form['new_password']) == 1
        ):
            new_username = form_str_cleaner(request.form['username'].lower())
            new_email    = form_email_cleaner(request.form['email'].lower())
            password     = request.form['password']
            new_password = request.form['new_password']
            new_lang     = request.form['lang_sel'].upper()

            # Username form verification
            msg_err = form_username_check(username)

            # Email form verification
            msg_err = form_email_check(email)

            # Password form verification
            msg_err = form_password_check(password)
            msg_err = form_password_check(new_password)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, new_email, new_username)
                query_count_res = cursor.rowcount

                # No account found
                if (query_count_res == 0):

                    # Get user_details
                    user_infos      = user_details(cursor, email, username)
                    query_count_res = cursor.rowcount

                    if (query_count_res > 0):

                        # Verify old password
                        hashed_pass = user_infos[4]
                        pass_verify = pwd_context.verify(password, hashed_pass)

                        if (bool(pass_verify == 1)):
                            # Encrypt new_password
                            new_password = pwd_context.encrypt(new_password)

                            query = (
                                'UPDATE users '
                                'SET username = %s, email = %s, password = %s '
                                'WHERE (username = %s AND email = %s);'
                            )

                            cursor.execute(query, (new_username, new_email, new_password, username, email))

                            # Commit to DB
                            mysql.connection.commit()

                            if (new_lang != lang.upper()):
                                user_upd_lang(cursor, new_lang, username, email)

                            if (lang == 'en'):
                                # Success
                                msg_suc = 'All fields was successfully updated !'

                            else:
                                msg_suc = (
                                    'Tous les champs ont été mis à jour '
                                    ' avec succès !'
                                )

                            # Break connection
                            cursor.close()

                        else:
                            if (lang == 'en'):
                                msg_err = 'Old password is invalid !'
                            else:
                                msg_err = (
                                    'L\'ancien mot de passe n\'est '
                                    'pas valide !'
                                )
                            cursor.close()

                    else:
                        if (lang == 'en'):
                            msg_err = 'An error was occurred !'
                        else:
                            msg_err = 'Une erreur s\'est produite !'
                        cursor.close()

                else:
                    if (lang == 'en'):
                        msg_err = 'Username or email already exists !'
                    else:
                        msg_err = (
                            'Le nom d\'utilisateur ou l\'adresse '
                            'mail existe déjà !'
                        )
                    cursor.close()

        # Case 2 : Update username + email + lang
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 1
              and bool(request.form['email'])        == 1
              and bool(request.form['password'])     == 0
              and bool(request.form['new_password']) == 0
        ):
            new_username = form_str_cleaner(request.form['username'].lower())
            new_email    = form_email_cleaner(request.form['email'].lower())
            new_lang     = request.form['lang_sel'].upper()

            # Username form verification
            msg_err = form_username_check(username)

            # Email form verification
            msg_err = form_email_check(email)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, new_email, new_username)
                query_count_res = cursor.rowcount

                # No account found
                if (query_count_res == 0):
                    query = (
                        'UPDATE users '
                        'SET username = %s, email = %s '
                        'WHERE (username = %s AND email = %s);'
                    )

                    cursor.execute(query, (new_username, new_email, username, email))

                    # Commit to DB
                    mysql.connection.commit()

                    if (new_lang != lang.upper()):
                        user_upd_lang(cursor, new_lang, username, email)

                        if (lang == 'en'):
                            # Success
                            msg_suc = (
                                'Username, email and language was '
                                'successfully updated !'
                            )

                        else:
                            msg_suc = (
                                'Le nom d\'utilisateur, l\'adresse '
                                'mail et la langue ont été mis à jour '
                                'avec succès !'
                            )

                        # Break connection
                        cursor.close()

                    else:
                        if (lang == 'en'):
                            # Success
                            msg_suc = (
                                'Username and email was successfully '
                                'updated !'
                            )
                        
                        else:
                            msg_suc = (
                                'Le nom d\'utilisateur et l\'adresse '
                                'mail ont été mis à jour avec succès !'
                            )

                        # Break connection
                        cursor.close()

                else :
                    if (lang == 'en'):
                        msg_err = 'Username or email already exists !'
                    else:
                        msg_err = (
                            'Le nom d\'utilisateur ou l\'adresse '
                            'mail existe déjà !'
                        )
                    cursor.close()

        # Case 3 : Update username + password + lang
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 1
              and bool(request.form['email'])        == 0
              and bool(request.form['password'])     == 1
              and bool(request.form['new_password']) == 1
        ):
            new_username = form_str_cleaner(request.form['username'].lower())
            password     = request.form['password']
            new_password = request.form['new_password']
            new_lang     = request.form['lang_sel'].upper()

            # Username form verification
            msg_err = form_username_check(username)

            # Password form verification
            msg_err = form_password_check(password)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, None, new_username)
                query_count_res = cursor.rowcount

                # No account found
                if (query_count_res == 0):

                    # Get user_details
                    user_infos      = user_details(cursor, email, username)
                    query_count_res = cursor.rowcount

                    if (query_count_res > 0):

                        # Verify old password
                        hashed_pass = user_infos[4]
                        pass_verify = pwd_context.verify(password, hashed_pass)

                        if (bool(pass_verify == 1)):

                            # Encrypt new_password
                            new_password = pwd_context.encrypt(new_password)

                            query = (
                                'UPDATE users '
                                'SET username = %s, password = %s '
                                'WHERE (username = %s AND email = %s);'
                            )

                            cursor.execute(query, (new_username, new_password, username, email))

                            # Commit to DB
                            mysql.connection.commit()

                            if (new_lang != lang.upper()):
                                user_upd_lang(cursor, new_lang, username, email)

                                if (lang == 'en'):
                                    # Success
                                    msg_suc = (
                                        'Username, password and language was '
                                        'successfully updated !'
                                    )
                                else:
                                    msg_suc = (
                                        'Le nom d\'utilisateur, le mot de '
                                        'passe et la langue ont été mis à jour '
                                        'avec succès !'
                                    )

                                # Break connection
                                cursor.close()

                            else:
                                if (lang == 'en'):
                                    # Success
                                    msg_suc = (
                                        'Username and password was successfully '
                                        'updated !'
                                    )
                                
                                else:
                                    msg_suc = (
                                        'Le nom d\'utilisateur et le mot de '
                                        'passe ont été mis à jour avec succès !'
                                    )

                            # Break connection
                            cursor.close()

                        else:
                            if (lang == 'en'):
                                msg_err = 'Old password is invalid !'
                            else:
                                msg_err = (
                                    'L\'ancien mot de passe n\'est '
                                    'pas valide !'
                                )
                            cursor.close()

                    else:
                        if (lang == 'en'):
                            msg_err = 'An error was occurred !'
                        else:
                            msg_err = 'Une erreur s\'est produite !'
                        cursor.close()

                else:
                    if (lang == 'en'):
                        msg_err = 'Username already exists !'
                    else:
                        msg_err = 'Le nom d\'utilisateur existe déjà !'

                    cursor.close()

        # Case 4 : Update email + password + lang
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 0
              and bool(request.form['email'])        == 1
              and bool(request.form['password'])     == 1
              and bool(request.form['new_password']) == 1
        ):
            new_email    = form_email_cleaner(request.form['email'].lower())
            password     = request.form['password']
            new_password = request.form['new_password']
            new_lang     = request.form['lang_sel'].upper()

            # Email form verification
            msg_err = form_email_check(email)

            # Password form verification
            msg_err = form_password_check(password)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, new_email, None)
                query_count_res = cursor.rowcount

                # No account found
                if (query_count_res == 0):

                    # Get user_details
                    user_infos      = user_details(cursor, email, username)
                    query_count_res = cursor.rowcount

                    if (query_count_res > 0):

                        # Verify old password
                        hashed_pass = user_infos[4]
                        pass_verify = pwd_context.verify(password, hashed_pass)

                        if (bool(pass_verify == 1)):

                            # Encrypt new_password
                            new_password = pwd_context.encrypt(new_password)

                            query = (
                                'UPDATE users '
                                'SET email = %s, password = %s '
                                'WHERE (username = %s AND email = %s);'
                            )

                            cursor.execute(query, (new_email, new_password, username, email))

                            # Commit to DB
                            mysql.connection.commit()

                            if (new_lang != lang.upper()):
                                user_upd_lang(cursor, new_lang, username, email)

                                if (lang == 'en'):
                                    # Success
                                    msg_suc = (
                                        'Email, password and language was '
                                        'successfully updated !'
                                    )

                                else:
                                    msg_suc = (
                                        'L\'adresse mail, le mot de passe et '
                                        'la langue ont été mis à jour avec '
                                        'succès !'
                                    )

                                # Break connection
                                cursor.close()

                            else:
                                if (lang == 'en'):
                                    # Success
                                    msg_suc = (
                                        'Email and password was successfully '
                                        'updated !'
                                    )

                                else:
                                    msg_suc = (
                                        'L\'adresse mail et le mot de passe '
                                        'ont été mis à jour avec succès !'
                                    )

                                # Break connection
                                cursor.close()

                        else:
                            if (lang == 'en'):
                                msg_err = 'Old password is invalid !'
                            else:
                                msg_err = (
                                    'L\'ancien mot de passe n\'est '
                                    'pas valide !'
                                )
                            cursor.close()

                    else:
                        if (lang == 'en'):
                            msg_err = 'An error was occurred !'
                        else:
                            msg_err = 'Une erreur s\'est produite !'
                        cursor.close()

                else:
                    if (lang == 'en'):
                        msg_err = 'Email already exists !'
                    else:
                        msg_err = 'L\'adresse mail existe déjà !'

                    cursor.close()

        # Case 5 : Update username + lang
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 1
              and bool(request.form['email'])        == 0
              and bool(request.form['password'])     == 0
              and bool(request.form['new_password']) == 0
        ):
            new_username = form_str_cleaner(request.form['username'].lower())
            new_lang     = request.form['lang_sel'].upper()

            # Username form verification
            msg_err = form_username_check(username)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, None, new_username)
                query_count_res = cursor.rowcount

                # No account found
                if (query_count_res == 0):
                    user_upd_username(cursor, new_username, username, email)

                    if (new_lang != lang.upper()):
                        user_upd_lang(cursor, new_lang, username, email)

                        if (lang == 'en'):
                            # Success
                            msg_suc = (
                                'Username and language was successfully updated !'
                            )

                        else:
                            msg_suc = (
                                'Le nom d\'utilisateur et la langue '
                                'ont été mis à jour avec succès !'
                            )

                        # Break connection
                        cursor.close()

                    else:
                        if (lang == 'en'):
                            # Success
                            msg_suc = 'Username was successfully updated !'

                        else:
                            msg_suc = (
                                'Le nom d\'utilisateur a été mis à jour avec succès !'
                            )

                        # Break connection
                        cursor.close()

                else:
                    if (lang == 'en'):
                        # Success
                        msg_err = 'Username already exists !'

                    else:
                        msg_err = (
                            'Le nom d\'utilisateur existe déjà !'
                        )

                    cursor.close()

        # Case 6 : Update email + lang
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 0
              and bool(request.form['email'])        == 1
              and bool(request.form['password'])     == 0
              and bool(request.form['new_password']) == 0
        ):
            new_email = form_email_cleaner(request.form['email'].lower())
            new_lang  = request.form['lang_sel'].upper()

            # Email form verification
            msg_err = form_email_check(email)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, new_email, None)
                query_count_res = cursor.rowcount

                # No account found
                if (query_count_res == 0):
                    user_upd_email(cursor, new_email, username, email)

                    if (new_lang != lang.upper()):
                        user_upd_lang(cursor, new_lang, username, email)

                        if (lang == 'en'):
                            # Success
                            msg_suc = (
                                'Email and language was successfully updated !'
                            )

                        else:
                            msg_suc = (
                                'L\' adresse mail et la langue ont été mis '
                                'à jour avec succès !'
                            )

                        # Break connection
                        cursor.close()

                    else:
                        if (lang == 'en'):
                            # Success
                            msg_suc = 'Email was successfully updated !'

                        else:
                            msg_suc = (
                                'L\' adresse mail a été mis à jour avec succès !'
                            )

                        # Break connection
                        cursor.close()

                else:
                    if (lang == 'en'):
                        # Success
                        msg_err = 'Email already exists !'

                    else:
                        msg_err = (
                            'L\' adresse mail existe déjà !'
                        )

                    cursor.close()

        # Case 7 : Update password + lang
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 0
              and bool(request.form['email'])        == 0
              and bool(request.form['password'])     == 1
              and bool(request.form['new_password']) == 1
        ):
            password     = request.form['password']
            new_password = request.form['new_password']
            new_lang     = request.form['lang_sel'].upper()

            # Password form verification
            msg_err = form_password_check(password)

            if (msg_err is None):
                # Connect to database
                cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

                # Get user_details
                user_infos      = user_details(cursor, email, username)
                query_count_res = cursor.rowcount

                if (query_count_res > 0):

                    # Verify old password
                    hashed_pass = user_infos[3]
                    pass_verify = pwd_context.verify(password, hashed_pass)

                    if (bool(pass_verify == 1)):

                        # Encrypt new_password
                        new_password = pwd_context.encrypt(new_password)

                        user_upd_pass(cursor, new_password, username, email)

                        if (new_lang != lang.upper()):
                            user_upd_lang(cursor, new_lang, username, email)

                            if (lang == 'en'):
                                # Success
                                msg_suc = (
                                    'Password and language was successfully updated !'
                                )

                            else:
                                msg_suc = (
                                    'Le mot de passe et la langue '
                                    'ont été mis à jour avec succès !'
                                )

                                # Break connection
                                cursor.close()

                        else:
                            if (lang == 'en'):
                                # Success
                                msg_suc = 'Password was successfully updated !'

                            else:
                                msg_suc = (
                                    'Le mot de passe a été mis à jour '
                                    'avec succès !'
                                )

                            # Break connection
                            cursor.close()

                    else:
                        if (lang == 'en'):
                            msg_err = 'Old password is invalid !'
                        else:
                            msg_err = (
                                'L\'ancien mot de passe n\'est pas valide !'
                            )

                        cursor.close()

                else:
                    if (lang == 'en'):
                        msg_err = 'An error was occurred !'
                    else:
                        msg_err = 'Une erreur s\'est produite !'

                cursor.close()

        # Case 8 : Empty form
        elif (request.method == 'POST'
              and bool(request.form['username'])     == 0
              and bool(request.form['email'])        == 0
              and bool(request.form['password'])     == 0
              and bool(request.form['new_password']) == 0
        ):
            new_lang = request.form['lang_sel'].upper()

            if (new_lang != lang.upper()):
                user_upd_lang(cursor, new_lang, username, email)

                if (lang == 'en'):
                    # Success
                    msg_suc = 'The language was successfully updated !'

                else:
                    msg_suc = 'La langue a été mis à jour avec succès !'

                # Break connection
                cursor.close()

            else:
                if (lang == 'en'):
                    msg_err = (
                        'The selected language is identical to '
                        'the current language.'
                    )

                else:
                    msg_err = (
                        'La langue sélectionnée est identique à '
                        'la langue courante.'
                    )

                # Break connection
                cursor.close()

        return render_template(
            'users/settings.html',
            title        = 'EasyML - Settings',
            username     = username,
            email        = email,
            lang         = lang,
            nav_cat_name = navbar_cat_name,
            nav_cat_tag  = navbar_cat_tag,
            nav_cat_icon = navbar_cat_icon,
            nav_cat_lnk  = navbar_cat_link,
            nav_models   = navbar_models,
            nav_set_name = navbar_set_name,
            nav_set_icon = navbar_set_icon,
            nav_set_lnk  = navbar_set_link,
            msg_err      = msg_err,
            msg_suc      = msg_suc
        )

    else:
        return redirect('404')
Esempio n. 4
0
def clustering_category():
    # Check if user is loggedin
    if ('loggedin' in session):

        # Get session details
        username = session['username']
        email = session['email']
        lang = session['lang']

        # Define category tag
        cat_tag = 'CLU'

        # Connect to database
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)

        # Get categories of navbar
        navbar_cat = datas_cat_nav(cursor, lang)
        navbar_cat_name = navbar_cat[0]
        navbar_cat_tag = navbar_cat[1]
        navbar_cat_icon = navbar_cat[2]
        navbar_cat_link = navbar_cat[3]

        # Get models of navbar
        navbar_models = datas_mod_nav(cursor, lang, navbar_cat_tag)

        # Get settings of navbar
        navbar_settings = datas_set_nav(cursor, lang)
        navbar_set_name = navbar_settings[0]
        navbar_set_icon = navbar_settings[1]
        navbar_set_link = navbar_settings[2]

        # Get category details
        cat_details = cards_categories(cursor, lang, cat_tag)
        cat_name = cat_details[0]
        cat_icon = cat_details[1]
        cat_desc = cat_details[2]
        cat_link = cat_details[3]
        cat_wiki_link = cat_details[4]

        # Get models card datas
        models_cards = cards_models(cursor, lang, cat_tag)
        model_card_id = models_cards[0]
        model_card_name = models_cards[1]
        model_card_desc = models_cards[2]
        model_card_link = models_cards[3]
        model_card_img = models_cards[4]

        # Get user ID
        user_infos = user_details(cursor, email, username)
        user_id = user_infos[0]

        # Get favorite list
        favorite = favorite_list(cursor, user_id)

        # Add or remove favorite
        if (request.method == 'POST' and bool(request.form['model_id']) == 1):
            model_id = int(request.form['model_id'])

            # Case 1: Favorite already existing -> remove favorite
            if (model_id in favorite):
                favorite_del(cursor, user_id, model_id)

                # Reload page
                return redirect(url_for(cat_link, _anchor=model_id))

            # Case 2: Favorite doesn't exist -> add to favorite
            elif (model_id not in favorite):
                favorite_add(cursor, user_id, model_id)

                # Reload page
                return redirect(url_for(cat_link, _anchor=model_id))

        # Break connection
        cursor.close()

        return render_template('common/model_category.html',
                               title=cat_name,
                               username=username,
                               lang=lang,
                               nav_cat_name=navbar_cat_name,
                               nav_cat_tag=navbar_cat_tag,
                               nav_cat_icon=navbar_cat_icon,
                               nav_cat_lnk=navbar_cat_link,
                               nav_models=navbar_models,
                               nav_set_name=navbar_set_name,
                               nav_set_icon=navbar_set_icon,
                               nav_set_lnk=navbar_set_link,
                               cat_name=cat_name,
                               cat_tag=cat_tag,
                               cat_icon=cat_icon,
                               cat_desc=cat_desc,
                               cat_link=cat_link,
                               cat_wiki=cat_wiki_link,
                               card_id=model_card_id,
                               card_name=model_card_name,
                               card_desc=model_card_desc,
                               card_link=model_card_link,
                               card_image=model_card_img,
                               favorite=favorite)

    else:
        return redirect('404')