<commit_before>class AuthController {
    constructor(data) {
        this.data = data;
    }

    getRegisterForm(req, res) {
        return res.render('auth/register');
    }

    getLogInForm(req, res) {
        return res.render('auth/login');
    }

    getProfileForm(req, res) {
        return res.render('auth/profile');
    }

    getMyBookings(req, res) {
        return res.render('auth/bookings');
    }

    getReviewForm(req, res) {
        return res.render('auth/review');
    }

    getViewBookings(req, res) {
        return res.render('auth/admin/viewbookings');
    }

    getViewCars(req, res) {
        return res.render('auth/admin/viewcars');
    }

    getViewUsers(req, res) {
        return res.render('auth/admin/viewusers');
    }

    getViewDeals(req, res) {
        return res.render('auth/admin/viewdeals');
    }

    logOut(req, res) {
        req.logout();
        return res.redirect('/');
    }

<<<<<<< HEAD
=======
    addCar(req, res) {
        const bodyCar = req.body;
        if (!req.file) {
            return res.status(400).send('No files were uploaded.');
        }

        const carPhotoFileName = req.file.originalname;

        return res.status(200)
            .redirect('/auth/addcar');
    }

>>>>>>> master
    updateProfile(req, res) {
        const bodyUser = req.body;
        return this._updateUserProperties(bodyUser)
            .then((user) => {
                return this.data.users.updateById(user);
            })
            .then((dbUser) => {
                return res.redirect('/');
            })
            .catch((err) => {
                req.flash('error', err.message);
                return res.redirect('/auth/profile');
            });
    }

    register(req, res) {
        const bodyUser = req.body;
        return this._checkIfUserExists(bodyUser)
            .then(() => {
                return this.data.users.create(bodyUser);
            })
            .then((dbUser) => {
                return res.redirect('/auth/login');
            })
            .catch((err) => {
                req.flash('error', err.message);
                return res.redirect('/auth/register');
            });
    }

    _checkIfUserExists(user) {
        return this.data.users.findByUsername(user._username)
            .then((dbUser) => {
                if (dbUser) {
                    throw new Error('User already exists');
                }

                return Promise.resolve(true);
            });
    }

    _updateUserProperties(user) {
        return this.data.users.findByUsername(user._username)
            .then((dbUser) => {
                if (dbUser) {
                    user._id = dbUser._id;
                    user._username = dbUser._username;
        converted.bookings = [];

                    if (user._password === '' ||
                        typeof user._password === '<PASSWORD>') {
                        delete user._password;
                        delete user['repeat-password'];
                        user.passHash = <PASSWORD>;
                        return Promise.resolve(user);
                    }

                    if (user._password !== user['repeat-password']) {
                        throw new Error(`Passwords do not match!`);
                    }
                    return Promise.resolve(user);
                }

                if (user._username) {
                    throw new Error(`User ${user._username} not found!`);
                } else {
                    throw new Error(`No username provided!`);
                }
            });
    }
}

const init = (data) => {
    return new AuthController(data);
};

module.exports = { init };<commit_msg>some cleaning<commit_after>class AuthController {
    constructor(data) {
        this.data = data;
    }

    getRegisterForm(req, res) {
        return res.render('auth/register');
    }

    getLogInForm(req, res) {
        return res.render('auth/login');
    }

    getProfileForm(req, res) {
        return res.render('auth/profile');
    }

    getMyBookings(req, res) {
        return res.render('auth/bookings');
    }

    getReviewForm(req, res) {
        return res.render('auth/review');
    }

    getViewBookings(req, res) {
        return res.render('auth/admin/viewbookings');
    }

    getViewCars(req, res) {
        return res.render('auth/admin/viewcars');
    }

    getViewUsers(req, res) {
        return res.render('auth/admin/viewusers');
    }

    getViewDeals(req, res) {
        return res.render('auth/admin/viewdeals');
    }

    logOut(req, res) {
        req.logout();
        return res.redirect('/');
    }

    updateProfile(req, res) {
        const bodyUser = req.body;
        return this._updateUserProperties(bodyUser)
            .then((user) => {
                return this.data.users.updateById(user);
            })
            .then((dbUser) => {
                return res.redirect('/');
            })
            .catch((err) => {
                req.flash('error', err.message);
                return res.redirect('/auth/profile');
            });
    }

    register(req, res) {
        const bodyUser = req.body;
        return this._checkIfUserExists(bodyUser)
            .then(() => {
                return this.data.users.create(bodyUser);
            })
            .then((dbUser) => {
                return res.redirect('/auth/login');
            })
            .catch((err) => {
                req.flash('error', err.message);
                return res.redirect('/auth/register');
            });
    }

    _checkIfUserExists(user) {
        return this.data.users.findByUsername(user._username)
            .then((dbUser) => {
                if (dbUser) {
                    throw new Error('User already exists');
                }

                return Promise.resolve(true);
            });
    }

    _updateUserProperties(user) {
        return this.data.users.findByUsername(user._username)
            .then((dbUser) => {
                if (dbUser) {
                    user._id = dbUser._id;
                    user._username = dbUser._username;

                    if (user._password === '' ||
                        typeof user._password === '<PASSWORD>') {
                        delete user._password;
                        delete user['repeat-password'];
                        user.passHash = <PASSWORD>;
                        return Promise.resolve(user);
                    }

                    if (user._password !== user['repeat-password']) {
                        throw new Error(`Passwords do not match!`);
                    }
                    return Promise.resolve(user);
                }

                if (user._username) {
                    throw new Error(`User ${user._username} not found!`);
                } else {
                    throw new Error(`No username provided!`);
                }
            });
    }
}

const init = (data) => {
    return new AuthController(data);
};

module.exports = { init };

{'fraction_non_alphanumeric': 0.13430719046943695, 'fraction_numerical': 0.0008509431286342362, 'mean_word_length': 1.406825938566553, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 32, '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': '4135975', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1848, 'n_words': 324}