<commit_before>bcrypt = require 'bcrypt'
User = require '../models/user'


# CONTROLLER
# ----------
module.exports = (app) ->

    # POST /api/services/login
    app.post '/api/services/login', 'services.login.post', (req, res) ->
        {nickname, password} = req.body
        # check the password
        if not nickname? or not password?
            res.genericError 'Paramètres invalides', 'AuthenticationError'
        else
            User.findOne
                where: $or:
                    nickname: nickname
                    email: nickname
            .done (user) ->
                unless user
                    res.genericError "Utilisateur #{nickname} n\'existe pas", 'AuthenticationError'
                else
                    bcrypt.compare password, user.password, (err, same) ->
                        unless same
                            res.genericError "Mot de passe invalide pour #{nickname}", 'AuthenticationError'
                        else
                            req.session.user = user.dataValues
                            selectUserFromReq user.id, req, (user) ->
                                res.json formatUser(user)

formatUser = (user) ->
    result = user<commit_msg>One upon the time, there was a little backslash. Then morgan came, and the backslash was gone.<commit_after>bcrypt = require 'bcrypt'
User = require '../models/user'


# CONTROLLER
# ----------
module.exports = (app) ->

    # POST /api/services/login
    app.post '/api/services/login', 'services.login.post', (req, res) ->
        {nickname, password} = req.body
        # check the password
        if not nickname? or not password?
            res.genericError 'Paramètres invalides', 'AuthenticationError'
        else
            User.findOne
                where: $or:
                    nickname: nickname
                    email: nickname
            .done (user) ->
                unless user
                    res.genericError "Utilisateur #{nickname} n'existe pas", 'AuthenticationError'
                else
                    bcrypt.compare password, user.password, (err, same) ->
                        unless same
                            res.genericError "Mot de passe invalide pour #{nickname}", 'AuthenticationError'
                        else
                            req.session.user = user.dataValues
                            selectUserFromReq user.id, req, (user) ->
                                res.json formatUser(user)

formatUser = (user) ->
    result = user
{'fraction_non_alphanumeric': 0.10047281323877069, 'fraction_numerical': 0.0, 'mean_word_length': 1.418095238095238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1158538', 'n_tokens_mistral': 647, 'n_tokens_neox': 610, 'n_words': 173}