old_contents: 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,
  	}
  });
new_contents: define([], function() {
  
  	var service = ['api', '$window', '$cookies', '$location', function(api, $window, $cookies, $location) {
  		var self = this;
  
  		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);
                  self.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,
  	}
  });
subject: Fix incorrect "this" reference.