<commit_before>'use strict';

/**
 * @name ngmReportHubApp.factory:ngmUser
 * @description
 * # ngmAccess
 * Manages browser local storage
 *
 * @name ngmReportHubApp.factory:ngmUser
 * @description
 * # ngmAccess
 * Manages browser local storage
 *
 */
angular.module('ngmReportHub')
	.factory('ngmUser', function() {

		return {

			get: function() {
				return angular.fromJson(localStorage.auth_token);
			},

			set: function(val) {
				return localStorage.setItem('auth_token', val);
			},

			unset: function() {
				return localStorage.removeItem('auth_token');
			},			

			hasRole: function(role) {
				var user = angular.fromJson(localStorage.auth_token);
				return angular.uppercase(user.roles).indexOf(angular.uppercase(role)) >= 0;
			},

			hasAnyRole: function( roles ) {
				var user = angular.fromJson(localStorage.auth_token);
				return !!user.roles.filter(function( role ) {
					return angular.uppercase(roles).indexOf( angular.uppercase(role) ) >= 0;
				}).length;
			}

		};
	})
	.factory('ngmAuth', ['$q', '$http', '$location', 'ngmUser', 'appConfig', function($q, $http, $location, ngmUser, appConfig) {

		var ngmAuth = {

			OK: 200,
			UNAUTHORIZED: 401,
			FORBIDDEN: 403,

			login: function(user) {
				
				// set the $http object
				var login = $http({
					method: 'GET',
					url: appConfig.host + '/login?name=' + user.name + '&password=' + user.password
				});

				// on success store in localStorage
				login.success(function(result) {
					ngmUser.set(JSON.stringify(result));
				});

				return login;
			},

			register: function(user) {

				ngmUser.unset();

				var register = $http({
					method: 'POST',
					url: appConfig.host + '/register',
					data: user
				});

				register.success(function(result) {
					ngmUser.set(JSON.stringify(result));
				});

				return register;
			},

			logout: function() {
				// unset token, backend dosnt care about logouts 
				ngmUser.unset('auth_token');
				$location.path( '/login' );
			},

			hasRole: function( role ) {
				
				var deferred = $q.defer();

				if ( ngmUser.hasRole( role ) ) {
					deferred.resolve(ngmAuth.OK );<commit_msg>Update api user to 'create'<commit_after>'use strict';

/**
 * @name ngmReportHubApp.factory:ngmUser
 * @description
 * # ngmAccess
 * Manages browser local storage
 *
 * @name ngmReportHubApp.factory:ngmUser
 * @description
 * # ngmAccess
 * Manages browser local storage
 *
 */
angular.module('ngmReportHub')
	.factory('ngmUser', function() {

		return {

			get: function() {
				return angular.fromJson(localStorage.auth_token);
			},

			set: function(val) {
				return localStorage.setItem('auth_token', val);
			},

			unset: function() {
				return localStorage.removeItem('auth_token');
			},			

			hasRole: function(role) {
				var user = angular.fromJson(localStorage.auth_token);
				return angular.uppercase(user.roles).indexOf(angular.uppercase(role)) >= 0;
			},

			hasAnyRole: function( roles ) {
				var user = angular.fromJson(localStorage.auth_token);
				return !!user.roles.filter(function( role ) {
					return angular.uppercase(roles).indexOf( angular.uppercase(role) ) >= 0;
				}).length;
			}

		};
	})
	.factory('ngmAuth', ['$q', '$http', '$location', 'ngmUser', 'appConfig', function($q, $http, $location, ngmUser, appConfig) {

		var ngmAuth = {

			OK: 200,
			UNAUTHORIZED: 401,
			FORBIDDEN: 403,

			login: function(user) {
				
				// set the $http object
				var login = $http({
					method: 'GET',
					url: appConfig.host + '/login?name=' + user.name + '&password=' + <PASSWORD>.password
				});

				// on success store in localStorage
				login.success(function(result) {
					console.log(result)
					ngmUser.set(JSON.stringify(result));
				});

				return login;
			},

			register: function(user) {

				ngmUser.unset();

				var register = $http({
					method: 'POST',
					url: appConfig.host + '/create',
					data: user
				});

				register.success(function(result) {
					ngmUser.set(JSON.stringify(result));
				});

				return register;
			},

			logout: function() {
				// unset token, backend dosnt care about logouts 
				ngmUser.unset('auth_token');
				$location.path( '/login' );
			},

			hasRole: function( role ) {
				
				var deferred = $q.defer();

				if ( ngmUser.hasRole( role ) ) {
					deferred.resolve(ngmAuth.OK );
{'fraction_non_alphanumeric': 0.15446779034864927, 'fraction_numerical': 0.005079658277534056, 'mean_word_length': 3.07909604519774, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '1998658', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1416, 'n_words': 287}