<commit_before>//expecting from database
const Data = require('../data');

//expecting from login
const configPassport = require('./passportconfig');

const passport = require('passport');
configPassport(passport);


const constructorMethod = (app) => {
    app.post('/login',
        passport.authenticate('local', {
            successRedirect: '/profile',
            failureRedirect: '/login',
            failureFlash: true
        })
    );

    app.post('/signup', (req, res) => {
        Data.user.Signup(req.body.email, req.body.password).then(info => {
            console.log(info); //e.g.  sign up successed, usrname: pasword:

            /* refer from
            http://code.runnable.com/VKHrGJKvwo55gHL7/express-passport-js-login-and-register-for-node-js-and-hello-world            
            */
            passport.authenticate('local')(req, res, function() {
                res.redirect('/profile');
            });

        }).catch(err => {
            res.render('partials/sigup', {
                email: req.body.email,
                message: err
            });
        });

    });

    app.get('/login', (req, res) => {
        if (req.isAuthenticated()) {
            res.redirect('/profile');
        } else {
            // message expecting from login
            render('partials/login', {
                message: req.flash('loginmessage')
            });
        }
    });

    app.get('/logout',
        function(req, res) {
            req.logout();
            res.redirect('/');
        });



    app.get('/signup', (req, res) => {
        render('partials/login', {
            // message expecting from login
            message: req.flash('signupmessage')
        });

    });

    app.get('/profile',
        require('connect-ensure-login').ensureLoggedIn(),
        function(req, res) {
            res.render('partials/profile', {
                user: req.user
            })
        });

    app.get('/', (req, res) => {

        // expecting from database
        // get user setting and prefer 
        // in order to display the homepage postlist
        // it will always work even user is undefined
        Data.DefaultSearch(req.user).then(postlist => {
            res.render('partials/home', {
                list: postlist
                user: req.user
            });
        }).catch(err => {
            res.render('partials/home', {
                user: req.user,
                listerrormessage: err
            })
        });
    });

    app.get('/searchpost', (req, res) => {
        //excepting searching ULR like :
        // :3000/search?q=java
        // then i got java
        Data.post.Search(req.query.q).then(postlist => {
            res.render('partials/home', {
                list: postlist,
                user: req.user
            })
        }).catch(err => {
            res.render('partials/home', {
                user: req.user,
                listerrormessage: err
            })
        });
    });

    // search user ???  not sure
    app.get('/searchuser', (req, res) => {
        //excepting searching ULR like :
        // :3000/search?q=java
        // then i got java
        Data.user.Search(req.query.q).then(userlist => {
            res.render('partials/userlist', {
                list: userlist,
                user: req.user //logged in user
            })
        }).catch(err => {
            res.render('partials/home', {
                user: req.user,
                listerrormessage: err
            })
        });
    });

    //the single post page
    app.get('/post/:id', (req, res) => {
        Data.findpostbyid(req.param.id).then(post => {
            res.render('partials/singlepost', {
                post: post
            });
        }).catch(err => {
            res.render('partials/singlepost', {
                message: err
            });
        });
    });

    //form page for creating a new post(quesiton)
    app.get('/posting', (req, res) => {
        res.render('partials/postform')
    });

    //post method to create a new post(quesiton)
    app.post('/posting', (req.res) => {
        if (!req.isAuthenticated()) {
            res.render('partials/postform', {
                loginerrormessage: 'Please login'
            });
        } else {
            Data.posts.create(req.user, req.body).then(newpost => {
                res.redirect('/post/{{newpost._id}}');
            }).catch(err => {
                res.render('partials/postform', {
                    message: err
                });
            });
        }
    });

    //post method to create a new anster, 
    //no single page for answer, the form is on the bottom 
    app.post('/answering', (req.res) => {
        if (!req.isAuthenticated()) {
            res.render('partials/postform', {
                loginerrormessage: 'Please login'
            });
        } else {
            Data.answers.create(req.user, req.body).then(locationhash => {

                // answer successed, go to the new answer location of the same post page
                res.redirect('/post/' + req.body.postid + '#' + locationhash);
            }).catch(err => {

                // answer falied, stay on the post page
                res.redirect('/post/' + req.body.postid);

            });
        }
    });

    //post method to create a new comment, 
    //no single page for comment, the form is inside the postpage 
    app.post('/commenting', (req.res) => {
        if (!req.isAuthenticated()) {

            res.render('partials/postform', {
                loginerrormessage: 'Please login'
            });
        } else {
            Data.cmoments.create(req.user, req.body).then(locationhash => {

                // comment successed, go to the new answer comment of the same post page
                res.redirect('/post/' + req.body.postid + '#' + locationhash);
            }).catch(err => {

                // comment falied, stay on the post page
                res.redirect('/post/' + req.body.postid);
<commit_msg>Update index.js<commit_after>//expecting from database
const Data = require('../data');

//expecting from login
const configPassport = require('./passportconfig');

const passport = require('passport');
configPassport(passport);


const constructorMethod = (app) => {
    app.post('/login',
        passport.authenticate('local', {
            successRedirect: '/profile',
            failureRedirect: '/login',
            failureFlash: true
        })
    );

    app.post('/signup', (req, res) => {
        Data.user.Signup(req.body.email, req.body.password).then(info => {
            console.log(info); //e.g.  sign up successed, usrname: pasword:

            /* refer from
            http://code.runnable.com/VKHrGJKvwo55gHL7/express-passport-js-login-and-register-for-node-js-and-hello-world            
            */
            passport.authenticate('local')(req, res, function() {
                res.redirect('/profile');
            });

        }).catch(err => {
            res.render('partials/sigup', {
                email: req.body.email,
                message: err
            });
        });

    });

    app.get('/login', (req, res) => {
        if (req.isAuthenticated()) {
            res.redirect('/profile');
        } else {
            // message expecting from login
            render('partials/login', {
                message: req.flash('loginmessage')
            });
        }
    });

    app.get('/logout',
        function(req, res) {
            req.logout();
            res.redirect('/');
        });



    app.get('/signup', (req, res) => {
        render('partials/login', {
            // message expecting from login
            message: req.flash('signupmessage')
        });

    });

    app.get('/profile',
        require('connect-ensure-login').ensureLoggedIn(),
        function(req, res) {
            res.render('partials/profile', {
                user: req.user
            })
        });

    app.get('/', (req, res) => {

        // expecting from database
        // get user setting and prefer 
        // in order to display the homepage postlist
        // it will always work even user is undefined
        Data.DefaultSearch(req.user).then(postlist => {
            res.render('partials/home', {
                list: postlist
                user: req.user
            });
        }).catch(err => {
            res.render('partials/home', {
                user: req.user,
                listerrormessage: err
            })
        });
    });
    
    // when search cliked with a 'post' dropdown tag
    app.get('/searchpost', (req, res) => {
        //excepting searching ULR like :
        // :3000/search?q=java
        // then i got java
        Data.post.Search(req.query.q).then(postlist => {
            res.render('partials/home', {
                list: postlist,
                user: req.user
            })
        }).catch(err => {
            res.render('partials/home', {
                user: req.user,
                listerrormessage: err
            })
        });
    });
    
    // when search cliked with a 'user' dropdown tag
    // search user ???  not sure
    app.get('/searchuser', (req, res) => {
        //excepting searching ULR like :
        // :3000/search?q=java
        // then i got java
        Data.user.Search(req.query.q).then(userlist => {
            res.render('partials/userlist', {
                list: userlist,
                user: req.user //logged in user
            })
        }).catch(err => {
            res.render('partials/home', {
                user: req.user,
                listerrormessage: err
            })
        });
    });

    //the single post page
    app.get('/post/:id', (req, res) => {
        Data.findpostbyid(req.param.id).then(post => {
            res.render('partials/singlepost', {
                post: post
            });
        }).catch(err => {
            res.render('partials/singlepost', {
                message: err
            });
        });
    });

    //form page for creating a new post(quesiton)
    app.get('/posting', (req, res) => {
        res.render('partials/postform')
    });

    //post method to create a new post(quesiton)
    app.post('/posting', (req.res) => {
        if (!req.isAuthenticated()) {
            res.render('partials/postform', {
                loginerrormessage: 'Please login'
            });
        } else {
            Data.posts.create(req.user, req.body).then(newpost => {
                res.redirect('/post/{{newpost._id}}');
            }).catch(err => {
                res.render('partials/postform', {
                    message: err
                });
            });
        }
    });

    //post method to create a new answer, 
    //no single page for answer, the form is on the bottom of the post page
    app.post('/answering', (req.res) => {
        if (!req.isAuthenticated()) {
            res.render('partials/postform', {
                loginerrormessage: 'Please login'
            });
        } else {
            
            // the postid that this comment belongs to is included in the req.body
            Data.answers.create(req.user, req.body).then(locationhash => {

                // answer successed, go to the new answer location of the same post page
                res.redirect('/post/' + req.body.postid + '#' + locationhash);
            }).catch(err => {

                // answer falied, stay on the post page
                res.redirect('/post/' + req.body.postid);

            });
        }
    });

    //post method to create a new comment, 
    //no single page for comment, the form apperas inside the post page when you click comment
    app.post('/commenting', (req.res) => {
        if (!req.isAuthenticated()) {

            res.render('partials/postform', {
                loginerrormessage: 'Please login'
            });
        } else {
            
            // the answer that this comment belongs to is included in the req.body
            // the post id that the answer belongs to is included in the req.body too
            Data.cmoments.create(req.user, req.body).then(locationhash => {

                // comment successed, go to the new comment location of the same post page
                res.redirect('/post/' + req.body.postid + '#' + locationhash);
            }).catch(err => {

                // comment falied, stay on the post page
                res.redirect('/post/' + req.body.postid);

{'fraction_non_alphanumeric': 0.1447032546266752, 'fraction_numerical': 0.0017549457562220803, 'mean_word_length': 1.4669421487603307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3658979', 'n_tokens_mistral': 3571, 'n_tokens_neox': 3399, 'n_words': 744}