define([ 'toaster', 'services' ], function() {
	'use strict';
	var app = angular.module('myApp', [ 'toaster', 'common.services' ]);
	app.init = function() {
		angular.bootstrap(document, [ 'myApp' ]);
	};
	app.controller('AuthCtrl', function($scope, $window, toaster, AuthenticationService) {
		$scope.loading = false;
		$scope.user = {
			j_username : "",
			j_password : ""
		};
		$scope.login = function(user) {
			$scope.loading = true;
			AuthenticationService.login(user).success(function(responseText, status) {
				if (status == 200) {
					var url = responseText;
					if(!url || url == '' || url.indexOf('/signin') > 0)
						url = './';
					$window.location.href = url;
				}
			}).error(function() {
				$scope.loading = false;
				toaster.pop('error', '登录失败', '用户名或密码错误');
			});
		};
	});
	return app;
});