<commit_before>angular.module('BloomLibraryApp.services', ['restangular'])
	.factory('authService', ['Restangular', "$cookies", function (restangular, $cookies) {
		var isLoggedIn = false;
		var userNameX = 'unknown';
        var bookshelves = [];
        var userObjectId = null;
        var saveUserNameTag = 'userName';
        var savePasswordTag = 'password';
        restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
            var extractedData;
            // Restangular expects getList operations to return an array. Parse.com in many cases does not.
            // This interceptor cleans them up.
            if (operation === "getList") {
                if (what == 'login') {
                    // the actual object we want is returned.
                    extractedData = [data];
                }
                else {
                    // the data is typically in the results field of the object returned
                    extractedData = data.results;
                }
            } else {
                extractedData = data;
            }
            return extractedData;
        });

        // These headers are the magic keys for our account at Parse.com
		// While someone is logged on, another header gets added (see setSession).
		// See also the keys below in the Parse.initialize call.
        var headers;
        if (window.location.href.indexOf("bloomlibrary.org") !== 0) {
            // we're running somewhere other than the official release of this site...use the silbloomlibrarysandbox api strings
            headers = {
                'X-Parse-Application-Id': 'yrXftBF6mbAuVu3fO6LnhCJiHxZPIdE7gl1DUVGR',
                'X-Parse-REST-API-Key': '<KEY>'
            };
        }
        else {
            // we're live! Use the real silbloomlibrary api strings.
            headers = {
                'X-Parse-Application-Id': 'R6qNTeumQXjJCMutAJYAwPtip1qBulkFyLefkCE5',
                'X-Parse-REST-API-Key': '<KEY>0EZkIx'
            };
        }
		restangularConfig = function (restangularConfigurer) {
			restangularConfigurer.setBaseUrl('https://api.parse.com/1'); // 1/indicates rev 1 of parse.com API
			restangularConfigurer.setDefaultHeaders(headers);
		};

		factory = {

			userName: function () { return userNameX; },
			setUserName: function (newName) { userNameX = newName; },
            bookShelves: function() {return bookshelves;},

			isLoggedIn: function () { return isLoggedIn; },
			isUserAdministrator: function () { return isUserAdministrator; },
            userObjectId: function() {return userObjectId;},

			config: function () { return restangularConfig; },

			setSession: function (sessionToken) {
				var sessionTokenKey = 'X-Parse-Session-Token';
				if (sessionToken) {
					headers[sessionTokenKey] = sessionToken;
					isLoggedIn = true;
				}
				else {
					delete headers[sessionTokenKey];
					isLoggedIn = false;
				}
			},

			login: function (username, password, successCallback, errorCallback) {
				// GET: .../login
				restangular.withConfig(restangularConfig).all('login').getList({ 'username': username, 'password': password })
					.then(function (result) {
                        userObjectId = result.objectId;
						isLoggedIn = true;
						isUserAdministrator = result.administrator;
						userNameX = username;
                        // There's no expiration on this...browser will remember your details until you log out, even
                        // if you close the browser altogether. This is not meant to be high-security.
                        $cookies[saveUserNameTag] = username;
                        $cookies[savePasswordTag] = password;
                        var query = new Parse.Query('bookshelf');
                        query.equalTo('owner', result);
//                        query.find({
//                            success: function (results) {
//                                bookshelves = response.results;
//                            },
//                            error: function (aError) {
//                                alert(aError);
//                            }
//                        });
                        restangular.withConfig(restangularConfig).all('classes/bookshelf').getList({ 'where':{'owner': {"__type":"Pointer","className":"_User","objectId":result.objectId} }})
                            .then(function (response) {
                                bookshelves = response.results;
                            },
                        function(error) {
                            alert(error);
                        });
                        factory.setSession(result.sessionToken); // im not sure this actually works
						successCallback(result);
					},
				function (result) {
					isLoggedIn = false;
					userNameX = 'unknown';
					errorCallback(result);
				});
			},

			logout: function () {
                $cookies[saveUserNameTag] = '';
                $cookies[savePasswordTag] = '';

                isLoggedIn = false;
				factory.setSession('');
			},

			// curl -X POST \
			//	-H "X-Parse-Application-Id: mqNCpJ1nB4a597asLF61OwYclJCOwfzgMNTMF6LL" \
			//  -H "X-Parse-REST-API-Key: <KEY>" \
			//  -H "Content-Type: application/json" \
			//  -d '{"email":"<EMAIL>"}' \
			//  https://api.parse.com/1/requestPasswordReset
			sendResetPassword: function(email)
			{
				// It took some experimentation to get restangular to make the post we wanted, with
				// fewer elements in the path than expected. There may be a simpler way, but this works.
				// Enhance: is there any need/possibility of detecting errors here?
				// For example, what if it's not a valid email address we know? Or if the network is down?
				return restangular.withConfig(restangularConfig).one("requestPasswordReset").post('', {"email":email});
			}
		};

        var tryUserName = $cookies[saveUserNameTag];
        var tryPassword = $cookies[savePasswordTag];
        if (tryUserName) {
            factory.login(tryUserName, tryPassword, function() {}, function() {});
        }

		return factory;
	} ])

	.service('bookService', ['Restangular', 'authService', '$q', '$rootScope', function (restangular, authService, $q, $rootScope) {
		// Initialize Parse.com javascript query module for our project.
		// Note: we would prefer to do things in this service using the REST API, but it does not currently support
		// substring matching and other things we need.
		// Please keep using the REST API wherever possible and the javascript API only where necessary.
		// Enhance: it is probably possible to implement server-side functions and access them using REST instead of
		// using the parse.com javascript API. We are limiting use of this API to this one file in order to manage
		// our dependency on parse.com.
        if (window.location.href.indexOf("bloomlibrary.org") !== 0) {
            // we're running somewhere other than the official release of this site...use the silbloomlibrarysandbox api strings
            Parse.initialize('yrXftBF6mbAuVu3fO6LnhCJiHxZPIdE7gl1DUVGR', '<KEY>');
        }<commit_msg>Third try to fix live site check<commit_after>angular.module('BloomLibraryApp.services', ['restangular'])
	.factory('authService', ['Restangular', "$cookies", function (restangular, $cookies) {
		var isLoggedIn = false;
		var userNameX = 'unknown';
        var bookshelves = [];
        var userObjectId = null;
        var saveUserNameTag = 'userName';
        var savePasswordTag = 'password';
        restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
            var extractedData;
            // Restangular expects getList operations to return an array. Parse.com in many cases does not.
            // This interceptor cleans them up.
            if (operation === "getList") {
                if (what == 'login') {
                    // the actual object we want is returned.
                    extractedData = [data];
                }
                else {
                    // the data is typically in the results field of the object returned
                    extractedData = data.results;
                }
            } else {
                extractedData = data;
            }
            return extractedData;
        });

        // These headers are the magic keys for our account at Parse.com
		// While someone is logged on, another header gets added (see setSession).
		// See also the keys below in the Parse.initialize call.
        var headers;
        if (window.location.host.indexOf("bloomlibrary.org") !== 0) {
            // we're running somewhere other than the official release of this site...use the silbloomlibrarysandbox api strings
            headers = {
                'X-Parse-Application-Id': 'yrXftBF6mbAuVu3fO6LnhCJiHxZPIdE7gl1DUVGR',
                'X-Parse-REST-API-Key': '<KEY>'
            };
        }
        else {
            // we're live! Use the real silbloomlibrary api strings.
            headers = {
                'X-Parse-Application-Id': 'R6qNTeumQXjJCMutAJYAwPtip1qBulkFyLefkCE5',
                'X-Parse-REST-API-Key': '<KEY>'
            };
        }
		restangularConfig = function (restangularConfigurer) {
			restangularConfigurer.setBaseUrl('https://api.parse.com/1'); // 1/indicates rev 1 of parse.com API
			restangularConfigurer.setDefaultHeaders(headers);
		};

		factory = {

			userName: function () { return userNameX; },
			setUserName: function (newName) { userNameX = newName; },
            bookShelves: function() {return bookshelves;},

			isLoggedIn: function () { return isLoggedIn; },
			isUserAdministrator: function () { return isUserAdministrator; },
            userObjectId: function() {return userObjectId;},

			config: function () { return restangularConfig; },

			setSession: function (sessionToken) {
				var sessionTokenKey = 'X-Parse-Session-Token';
				if (sessionToken) {
					headers[sessionTokenKey] = sessionToken;
					isLoggedIn = true;
				}
				else {
					delete headers[sessionTokenKey];
					isLoggedIn = false;
				}
			},

			login: function (username, password, successCallback, errorCallback) {
				// GET: .../login
				restangular.withConfig(restangularConfig).all('login').getList({ 'username': username, 'password': password })
					.then(function (result) {
                        userObjectId = result.objectId;
						isLoggedIn = true;
						isUserAdministrator = result.administrator;
						userNameX = username;
                        // There's no expiration on this...browser will remember your details until you log out, even
                        // if you close the browser altogether. This is not meant to be high-security.
                        $cookies[saveUserNameTag] = username;
                        $cookies[savePasswordTag] = password;
                        var query = new Parse.Query('bookshelf');
                        query.equalTo('owner', result);
//                        query.find({
//                            success: function (results) {
//                                bookshelves = response.results;
//                            },
//                            error: function (aError) {
//                                alert(aError);
//                            }
//                        });
                        restangular.withConfig(restangularConfig).all('classes/bookshelf').getList({ 'where':{'owner': {"__type":"Pointer","className":"_User","objectId":result.objectId} }})
                            .then(function (response) {
                                bookshelves = response.results;
                            },
                        function(error) {
                            alert(error);
                        });
                        factory.setSession(result.sessionToken); // im not sure this actually works
						successCallback(result);
					},
				function (result) {
					isLoggedIn = false;
					userNameX = 'unknown';
					errorCallback(result);
				});
			},

			logout: function () {
                $cookies[saveUserNameTag] = '';
                $cookies[savePasswordTag] = '';

                isLoggedIn = false;
				factory.setSession('');
			},

			// curl -X POST \
			//	-H "X-Parse-Application-Id: mqNCpJ1nB4a597asLF61OwYclJCOwfzgMNTMF6LL" \
			//  -H "X-Parse-REST-API-Key: QN9bdJ8JODDYxUSXqWZTaz2y8WcX3d5kMi6ha3TU" \
			//  -H "Content-Type: application/json" \
			//  -d '{"email":"<EMAIL>"}' \
			//  https://api.parse.com/1/requestPasswordReset
			sendResetPassword: function(email)
			{
				// It took some experimentation to get restangular to make the post we wanted, with
				// fewer elements in the path than expected. There may be a simpler way, but this works.
				// Enhance: is there any need/possibility of detecting errors here?
				// For example, what if it's not a valid email address we know? Or if the network is down?
				return restangular.withConfig(restangularConfig).one("requestPasswordReset").post('', {"email":email});
			}
		};

        var tryUserName = $cookies[saveUserNameTag];
        var tryPassword = $cookies[savePasswordTag];
        if (tryUserName) {
            factory.login(tryUserName, tryPassword, function() {}, function() {});
        }

		return factory;
	} ])

	.service('bookService', ['Restangular', 'authService', '$q', '$rootScope', function (restangular, authService, $q, $rootScope) {
		// Initialize Parse.com javascript query module for our project.
		// Note: we would prefer to do things in this service using the REST API, but it does not currently support
		// substring matching and other things we need.
		// Please keep using the REST API wherever possible and the javascript API only where necessary.
		// Enhance: it is probably possible to implement server-side functions and access them using REST instead of
		// using the parse.com javascript API. We are limiting use of this API to this one file in order to manage
		// our dependency on parse.com.
        if (window.location.host.indexOf("bloomlibrary.org") !== 0) {
            // we're running somewhere other than the official release of this site...use the silbloomlibrarysandbox api strings
            Parse.initialize('yrXftBF6mbAuVu3fO6LnhCJiHxZPIdE7gl1DUVGR', '<KEY>');
        }
{'fraction_non_alphanumeric': 0.10761081683858377, 'fraction_numerical': 0.004390855868413716, 'mean_word_length': 2.0240252897787143, 'pattern_counts': {'":': 10, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 4, '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': '1766735', 'n_tokens_mistral': 4262, 'n_tokens_neox': 3756, 'n_words': 1060}