}).error(function(response){$scope.error=response.message})}}]),angular.module("users").controller("VerifyController",["$scope","$state","$rootScope","User","Auth","$stateParams",function($scope,$state,$rootScope,User,Auth,$stateParams){$scope.isReset=!1,$scope.credentials={},$scope.resendVerifyEmail=function(){console.log($scope.credentials.email),User.resendVerifyEmail($scope.credentials.email).then(function(response){$scope.success=response.message,$scope.credentials=null,$scope.isResetSent=!0},function(error){$scope.error=error,$scope.credentials=null,$scope.isReset=!1})},$scope.validateVerifyToken=function(){$stateParams.token&&(console.log($stateParams.token),User.validateVerifyToken($stateParams.token).then(function(response){console.log("Success: "+response.message),$scope.success=response.message,$scope.isReset=!0,$scope.credentials=null},function(error){console.log("Error: "+error.message),$scope.isReset=!1,$scope.error=error,$scope.credentials=null}))}}]),angular.module("users").factory("Auth",["$window",function($window){varuserState={isLoggedIn:!1},service={_currentUser:null,getcurrentUser(){returnthis._currentUser},ensureHasCurrentUser:function(User){returnservice._currentUser&&service._currentUser.username?(console.log("Using local current user."),service._currentUser):$window.user?(console.log("Using cached current user."),service._currentUser=$window.user,service._currentUser):(console.log("Fetching current user from the server."),voidUser.getCurrent().then(function(user){returnservice._currentUser=user,userState.isLoggedIn=!0,$window.user=service._currentUser,service._currentUser},function(response){returnuserState.isLoggedIn=!1,service._currentUser=null,$window.user=null,console.log("User.getCurrent() err",response),null}))},isAuthenticated:function(){return!!service._currentUser},getUserState:function(){returnuserState},login:function(new_user){userState.isLoggedIn=!0,service._currentUser=new_user},logout:function(){$window.user=null,userState.isLoggedIn=!1,service._currentUser=null}};returnservice}]),angular.module("users").service("Authorizer",function(APP_PERMISSIONS,USER_ROLES){returnfunction(user){return{canAccess:function(permissions){vari,len,permission;for(angular.isArray(permissions)||(permissions=[permissions]),i=0,len=permissions.length;len>i;i++){if(permission=permissions[i],null===APP_PERMISSIONS[permission])throw"Bad permission value";if(!user||!user.roles)return!1;switch(permission){caseAPP_PERMISSIONS.viewAdminSettings:caseAPP_PERMISSIONS.editAdminSettings:returnuser.roles.indexOf(USER_ROLES.admin)>-1;caseAPP_PERMISSIONS.viewPrivateForm:caseAPP_PERMISSIONS.editForm:returnuser.roles.indexOf(USER_ROLES.admin)>-1||user.roles.indexOf(USER_ROLES.normal)>-1}}return!1}}}}),angular.module("users").factory("User",["$window","$q","$timeout","$http","$state",function($window,$q,$timeout,$http,$state){varuserService={getCurrent:function(){vardeferred=$q.defer();return$http.get("/users/me").success(function(response){deferred.resolve(response)}).error(function(){deferred.reject("User's session has expired")}),deferred.promise},login:function(credentials){vardeferred=$q.defer();return$http.post("/auth/signin",credentials).success(function(response){deferred.resolve(response)}).error(function(error){deferred.reject(error.message||error)}),deferred.promise},logout:function(){vardeferred=$q.defer();return$http.get("/auth/signout").success(function(response){deferred.resolve(null)}).error(function(error){deferred.reject(error.message||error)}),deferred.promise},signup:function(credentials){vardeferred=$q.defer();return$http.post("/auth/signup",credentials).success(function(response){deferred.resolve(response)}).error(function(error){deferred.reject(error.message||error)}),deferred.promise},resendVerifyEmail:function(_email){vardeferred=$q.defer();return$http.post("/auth/verify",{email:_email}).success(function(response){deferred.resolve(response)}).error(function(error){deferred.reject(error.message||error)}),deferred.promise},validateVerifyToken:function(token){varvalidTok