<commit_before>// Pay - /app/public/factories/etu.js

// Site Etu factory

'use strict';

pay.factory('SiteEtu', ['$http', 'Error', function ($http, error) {
    var etuData = null;

    function SiteEtu (baseURL) {
        var rights = [
            'public',
            'private_user_account',
            'private_user_organizations'
        ].join('+');

        this.token = null;

        this.etu = etuData;

        /**
          * Checks if the user browser is IE (window.opener is not supported)
          */
        this.isIE = function () {
            var msie = navigator.userAgent.indexOf('MSIE') > -1;
            var trident = navigator.userAgent.indexOf('Trident') > -1;
            return msie || trident;
        };

        /**
          * Authenticates a user via site etu
          * @param {string} clientId - The site etu buckutt's clientid
          * @param {function} callback - Callback called when the popup gets an answer
          */
        this.auth = function (clientId, callback) {
            var url = baseURL + 'oauth/authorize?client_id=' +
                      clientId + '&scopes=' + rights;
            var params = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,width=490,height=741';

            if (this.isIE()) {
                params = 'dialogWidth=490,dialogHeight=650,resizable=0,scroll=0,status=0';
                window.showModalDialog(url, window, params);
                window.onMessage = function (data) {
                    localStorage.setItem('refreshToken', e.data.refreshToken);
                    localStorage.setItem('date', (new Date()).getTime());
                    callback(data);
                };
            } else {
                window.open(url, '_blank', params);
                window.addEventListener('message', function (e) {
                    localStorage.setItem('refreshToken', e.data.refreshToken);
                    localStorage.setItem('date', (new Date()).getTime());
                    callback(e.data);
                }, false);
            }
        };

        /**
          * Checks if the popup has a code in the query (opened with auth())
          */
        this.checkAuth = function () {
            var isIE = this.isIE;

            // location.search = ?authorization_code=8a0d56bfe3eb6cb5ff67ab888d31bb211f70fb21&state=buckutt
            var query = location.href.split('?authorization_code=');
            if (query.length !== 2) {
                return;
            }

            var code = query[1];

            $http.post('api/authEtu', JSON.stringify({
                code: code
            })).success(function (data) {
                if (isIE()) {
                    window.dialogArguments.onMessage(data);
                } else {
                    window.opener.postMessage(data, '*');
                    window.close();
                }
            }).error(function (data, status, headers) {
                error('Erreur', data.error);
            });
        };

        /**
          * Checks if the refresh token is here and still viable
          * @param {function} loadingCallback - Called when the refresh token is being refreshed
          * @param {function} callback - Called when the refresh token has been refreshed
          */
        this.pleaseRefreshToken = function (loadingCallback, callback) {
            if (this.etu !== null) {
                loadingCallback();
                callback(this.etu);
                return;
            }

            var token = localStorage.getItem('refreshToken');
            var date = localStorage.getItem('date');
            var oneMonth = 1000 * 60 * 60 * 24 * 30;

            if (token && date) {
                if ((new Date()) - date < oneMonth) {
                    loadingCallback();
                    $http.post('api/authEtu', JSON.stringify({
                        refreshToken: token
                    })).success(function (data) {
                        localStorage.setItem('refreshToken', data.refreshToken);
                        localStorage.setItem('date', (new Date()).getTime());
                        callback(data);
                    }).error(function (data, status, headers) {
                        error('Erreur', data.error);
                    });
                }
            }
        };
    }

    return new SiteEtu('https://etu.utt.fr/api/');
}]);<commit_msg>Do not store the refreshToken (as it will now be one for the month, reusable)<commit_after>// Pay - /app/public/factories/etu.js

// Site Etu factory

'use strict';

pay.factory('SiteEtu', ['$http', 'Error', function ($http, error) {
    var etuData = null;

    function SiteEtu (baseURL) {
        var rights = [
            'public',
            'private_user_account',
            'private_user_organizations'
        ].join('+');

        this.token = <PASSWORD>;

        this.etu = etuData;

        /**
          * Checks if the user browser is IE (window.opener is not supported)
          */
        this.isIE = function () {
            var msie = navigator.userAgent.indexOf('MSIE') > -1;
            var trident = navigator.userAgent.indexOf('Trident') > -1;
            return msie || trident;
        };

        /**
          * Authenticates a user via site etu
          * @param {string} clientId - The site etu buckutt's clientid
          * @param {function} callback - Callback called when the popup gets an answer
          */
        this.auth = function (clientId, callback) {
            var url = baseURL + 'oauth/authorize?client_id=' +
                      clientId + '&scopes=' + rights;
            var params = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,width=490,height=741';

            if (this.isIE()) {
                params = 'dialogWidth=490,dialogHeight=650,resizable=0,scroll=0,status=0';
                window.showModalDialog(url, window, params);
                window.onMessage = function (data) {
                    localStorage.setItem('refreshToken', e.data.refreshToken);
                    localStorage.setItem('date', (new Date()).getTime());
                    callback(data);
                };
            } else {
                window.open(url, '_blank', params);
                window.addEventListener('message', function (e) {
                    localStorage.setItem('refreshToken', e.data.refreshToken);
                    localStorage.setItem('date', (new Date()).getTime());
                    callback(e.data);
                }, false);
            }
        };

        /**
          * Checks if the popup has a code in the query (opened with auth())
          */
        this.checkAuth = function () {
            var isIE = this.isIE;

            // location.search = ?authorization_code=8a0d56bfe3eb6cb5ff67ab888d31bb211f70fb21&state=buckutt
            var query = location.href.split('?authorization_code=');
            if (query.length !== 2) {
                return;
            }

            var code = query[1];

            $http.post('api/authEtu', JSON.stringify({
                code: code
            })).success(function (data) {
                if (isIE()) {
                    window.dialogArguments.onMessage(data);
                } else {
                    window.opener.postMessage(data, '*');
                    window.close();
                }
            }).error(function (data, status, headers) {
                error('Erreur', data.error);
            });
        };

        /**
          * Checks if the refresh token is here and still viable
          * @param {function} loadingCallback - Called when the refresh token is being refreshed
          * @param {function} callback - Called when the refresh token has been refreshed
          */
        this.pleaseRefreshToken = function (loadingCallback, callback) {
            if (this.etu !== null) {
                loadingCallback();
                callback(this.etu);
                return;
            }

            var token = localStorage.getItem('refreshToken');
            var date = localStorage.getItem('date');
            var oneMonth = 1000 * 60 * 60 * 24 * 30;

            if (token && date) {
                if ((new Date()) - date < oneMonth) {
                    loadingCallback();
                    $http.post('api/authEtu', JSON.stringify({
                        refreshToken: token
                    })).success(function (data) {
                        // Refresh token is not refreshable anymore
                        /*localStorage.setItem('refreshToken', data.refreshToken);
                        localStorage.setItem('date', (new Date()).getTime());*/
                        callback(data);
                    }).error(function (data, status, headers) {
                        error('Erreur', data.error);
                    });
                }
            }
        };
    }

    return new SiteEtu('https://etu.utt.fr/api/');
}]);
{'fraction_non_alphanumeric': 0.12191598132918427, 'fraction_numerical': 0.012891753723049567, 'mean_word_length': 1.4969478357380688, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '3927784', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2297, 'n_words': 532}