Bot-detector / Bot-Detector-Core-Files

The server and processing files for the Bot Detector Plugin
GNU General Public License v3.0
17 stars 15 forks source link

Discord Verification: Return wrong code error if code not found in pending links #475

Closed Cyborger1 closed 1 year ago

Cyborger1 commented 1 year ago

Currently, the for loop that checks for a pending discord link does not error out if it gets to the end of the table without finding a matching code. It just does nothing and returns "OK".

Problem is located here https://github.com/Bot-detector/Bot-Detector-Core-Files/blob/30264887fd2562c52935aa3f31a72ab04b8d2ebf/api/routers/legacy.py#L1015-L1024

Cyborger1 commented 1 year ago

Proposed solution:

    if pending_discord: 
        found_code = False    # <---
        for record in pending_discord: 
            pending_code = int(record.Code) 

            if pending_code == provided_code: 
                found_code = True    # <---
                await set_discord_verification(id=record.Entry, token=token_id) 
                break

        if not(found_code):     # <---
            raise HTTPException(status_code=400, detail=f"Linking code is incorrect.")    # <---
    else: 
        raise HTTPException(status_code=400, detail=f"No pending links for this user.")
    return {"ok": "ok"} 
extreme4all commented 1 year ago

oh a logic error of mine, nice catch!