define([], function() {

	var service = ['api', '$window', '$cookies', '$location', function(api, $window, $cookies, $location) {

		this.loginRedirect = function(provider, target) {
			
			$cookies.afterAuth = target || "";

			api.authentication.getAuthRedirect({provider: provider}).$promise.then(function(data) {
				console.log("Redirect data:", data);

				$window.location.href = data.redirectUrl;
			})
		}

		this.providerCallback = function(provider, params) {

            var next = $cookies.afterAuth || "/";
            next = next.replace("#!", "");
            
            delete $cookies.afterAuth;

            params.provider = provider;

            api.authentication.getAuthResult(params).$promise.then(function(u) {
                console.debug("Logged in user:", u);
                console.debug("Redirecting to", next);
                this.user = u;

                $location.replace();
                $location.url(next);
            }).catch(function(e) {
                console.error(e);
            });

		}

		this.linkRedirect = function(provider, target) {
			
			//$window.location.href = api.authenticationEndpoint + '/' + provider +"/link?redirect=http://" + $window.location.host;
		}

		this.logout = function() {
			this.user = null;
			return api.authentication.logout().$promise;
		}

		this.getUser = function(forceRefresh) {

			if (!this.user || forceRefresh)
				this.user = api.currentUser.get();

			return this.user;
		}

		this.login = function(email, password) {
			return new Promise(function(resolve, reject){
				api.login(email, password).$promise.then(function(u){
					this.user = u;
					resolve();
				}).catch(function(u){
					this.user = null;
					reject();
				});
			});
		}

		this.register = function(email, password) {

		}

	}];

	var resolver = ['auth', function(auth) {
		return auth.getUser().$promise.catch(function(r) {
			if (r.status == 401)
				return Promise.reject("require_login");
			return Promise.reject("Something went wrong:", r);
		});
	}];

	return {
		service: service,
		resolver: resolver,
	}
});
@@ -122,16 +122,35 @@
 ation) %7B
+%0A%09%09var self = this;
 %0A%0A%09%09this
@@ -577,28 +577,16 @@
 %22, %22%22);%0A
-            
 %0A       
@@ -864,20 +864,20 @@
         
-this
+self
 .user = 

Fix incorrect "this" reference.