<commit_before>'use strict';

const httpStatus = require('http-status-codes');
const jwt = require('jsonwebtoken');
const crypto = require('crypto-js');

const config = require('js.shared').config;
const utils = require('js.shared').utils; // jshint ignore:line

const constants = require('./const');
const db = require('./db');
const users = require('./users');
const rfUtils = require('./rf-utils');

exports.authFilter = authFilter;
exports.checkObjectAccess = checkObjectAccess;
exports.passwordValidate = passwordValidate;
exports.login = login;
exports.getUserId = getUserId;
exports.createToken = createToken;
exports.createTokenWithPassword = createTokenWithPassword;
exports.addAuthHeader = addAuthHeader;
exports.passwordCheckWeakness = passwordCheckWeakness;

let pathsNoAuth = [
    '/api/service-validate',
    '/api/check-figures',
    '/api/login',
    '/api/password-validate',
    '/api/captcha',
    '/api/captcha-validate',
    '/api/register',
    '/api/registration-complete',
    '/api/password-change-request',
    '/api/password-change',
    '/api/most-visited-metapublications',
    '/api/metapublications',
    '/api/oauth/google',
    '/api/oauth/fb'
];

let pathsNoAuthGET = [
    '/api/figure',
    '/api/metapublication'
];

/**
 * Check if the given REST API request must be authenticated, i.e. contain security token
 * @param {Object} req input request
 * @returns {boolean} true if request must be authenticated
 */
function shouldAuthenticate(req) {

    let reqPath = req.path.toLowerCase();

    for (let path of pathsNoAuth) {
        if (reqPath.indexOf(path) === 0) {
            return false;
        }
    }<commit_msg>~ oauth mived to GET section<commit_after>'use strict';

const httpStatus = require('http-status-codes');
const jwt = require('jsonwebtoken');
const crypto = require('crypto-js');

const config = require('js.shared').config;
const utils = require('js.shared').utils; // jshint ignore:line

const constants = require('./const');
const db = require('./db');
const users = require('./users');
const rfUtils = require('./rf-utils');

exports.authFilter = authFilter;
exports.checkObjectAccess = checkObjectAccess;
exports.passwordValidate = passwordValidate;
exports.login = login;
exports.getUserId = getUserId;
exports.createToken = createToken;
exports.createTokenWithPassword = createTokenWithPassword;
exports.addAuthHeader = addAuthHeader;
exports.passwordCheckWeakness = passwordCheckWeakness;

let pathsNoAuth = [
    '/api/service-validate',
    '/api/check-figures',
    '/api/login',
    '/api/password-validate',
    '/api/captcha',
    '/api/captcha-validate',
    '/api/register',
    '/api/registration-complete',
    '/api/password-change-request',
    '/api/password-change',
    '/api/most-visited-metapublications',
    '/api/metapublications'
];

let pathsNoAuthGET = [
    '/api/figure',
    '/api/metapublication',
    '/api/oauth/google',
    '/api/oauth/fb'
];

/**
 * Check if the given REST API request must be authenticated, i.e. contain security token
 * @param {Object} req input request
 * @returns {boolean} true if request must be authenticated
 */
function shouldAuthenticate(req) {

    let reqPath = req.path.toLowerCase();

    for (let path of pathsNoAuth) {
        if (reqPath.indexOf(path) === 0) {
            return false;
        }
    }
{'fraction_non_alphanumeric': 0.14713814803715913, 'fraction_numerical': 0.0005993407252022775, 'mean_word_length': 3.8376811594202898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7265895', 'n_tokens_mistral': 1010, 'n_tokens_neox': 998, 'n_words': 227}