Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval issue; "data is not defined" #754

Closed
originalbluef3x opened this issue Mar 25, 2024 · 1 comment
Closed

Eval issue; "data is not defined" #754

originalbluef3x opened this issue Mar 25, 2024 · 1 comment

Comments

@originalbluef3x
Copy link

originalbluef3x commented Mar 25, 2024

Hello! I am receiving the error "data is not defined" however, the page is being rendered without any issues.

First my main code is here:

const app = express();
let validUserTokens = {};
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const cookieParser = require('cookie-parser');
app.set('view engine', 'ejs');
app.use(cookieParser());
const path = require('path')
const fs = require('fs')
const generateToken = // Redacted for copyright reasons, I was told.

app.get("/", async (req, res) => {
    try {
        // Load indexData from JSON file
        let indexData = JSON.parse(fs.readFileSync('./pagedata/indexData.json'));
        // Render index.ejs template and pass indexData
        res.render("index", {
            data: indexData  // Pass indexData to the template
         
        });
    } catch (err) {
        console.error('Error loading indexData:', err);
        res.status(500).send('Internal Server Error');
    }
});

app.get("/edit/:file", (req, res) =>{
    try{
        res.render(req.params.file, {
            editMode: true,
            dark: true
        })
    }catch{
        res.sendStatus(401).send("Err.")
    }
})

app.get(['/secure/enter', '/login'], (req, res)=>{
    if(req.query.render == "NXUSR"){
        res.render("loginV2")
    }else{
        res.render('login')
    }
    
})

app.post('/login/backend', (req, res) =>{
    let loginsFile = JSON.parse(fs.readFileSync('./logins.json'));
    let responseData = req.body;
    //console.log(responseData);

    // Check if the request body contains username and password
    if (!responseData || !responseData.username || !responseData.password) {
        return res.status(400).send("Username and password are required.");
    }

    // Check if there are login entries
    if (loginsFile.length === 0) {
        return res.status(401).send("No users found in the system.");
    }

    // Check if the provided credentials match any entry in loginsFile
    const user = loginsFile.find(user => user.username === responseData.username && user.password === responseData.password);

    if (user) {
        // Credentials are valid
        let newToken = generateToken(128, "method")
        res.cookie("token", newToken)
    console.log(user)
        validUserTokens[newToken] = {
            username: user.username,
            id: user.id,
            name: user.name
        }
        return res.redirect('/app');
    } else {
        // Credentials are invalid
        return res.redirect('/secure/enter/?render=NXUSR')
    }
});

app.get('/app', (req, res) =>{
    let token = req.cookies['token']
    let user = validUserTokens[token]
    if(!user || typeof(user) == 'undefined') return res.redirect('/')
    res.render('app', {
        user
    })
})

app.get('/assets/:asset', (req, res) =>{
res.sendFile(path.resolve(`./assets/${req.params.asset}`))
})

app.get('*', (req, res) =>{
    res.render("index", {
        dark: true
    })
   // res.se("<html><p>The Requested Resource could not be found. <a href="/">Head Back</a></p></html>")
})

process.on('unhandledRejection', function(){
    
})

process.on('uncaughtException', function(){

})

app.listen(1080, function(){console.log("Running a marathon on port 1080ti")})`

My JSON file is here

{
    "title": "REDACTED ENTIRELY",
    "underConstruction": "Hello and welcome! This site is under construction, if you have any suggestions on how we can make this site better, tell us ",
    "navBar": [
        {
            "text": "Events",
            "url": "#"
        },
        {
            "text": "Donate",
            "url": "/venmo"
        },
        {
            "text": "Contact",
            "url": "mailto:[email protected]"
        },
        {
            "text": "Login",
            "url": "/secure/enter"
        },
        {
            "text": "Venmo",
            "url": "/venmo"
        }
    ],

    "carousel": [
        {
                "imgSource": "",
                "id": "crescendo",
                "textData": [
                    {
                        "text": "2024 Competition: Crescendo"
                    },
                    {
                        "text": "Learn More",
                        "url": "/2024/game"
                    }
                ]
        
        }
            ]

        }
        
   

I do not believe my actual page is configured wrong, If you need it, I will send it in a follow up but it is too long to send now

Thank you!

@originalbluef3x
Copy link
Author

Issue resolved, res.render("*") was for some reason still firing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant