Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. Uncaught SyntaxError: Unexpected token )
  2.  
  3. angular.module('myApp.Services').service('SessionService', function(){
  4. var userIsAuthenticated = false;
  5.  
  6. this.setUserAuthenticated = function(value){
  7. userIsAuthenticated = value;
  8. };
  9.  
  10. this.getUserAuthenticated = function(){
  11. return userIsAuthenticated;
  12. });
  13. }); <----------------- Error
  14.  
  15. angular.module('myApp.Services').service('SessionService', function(){
  16. var userIsAuthenticated = false;
  17.  
  18. this.setUserAuthenticated = function(value){
  19. userIsAuthenticated = value;
  20. };
  21.  
  22. this.getUserAuthenticated = function(){
  23. return userIsAuthenticated;
  24. });
  25. });
  26.  
  27. window.routes =
  28. {
  29. "/login": {
  30. templateUrl: 'login.html',
  31. controller: 'myCtrl',
  32. requireLogin: false
  33. },
  34. "/index": {
  35. templateUrl: 'index.html',
  36. requireLogin: true
  37. }
  38. };
  39.  
  40. var app = angular.module('myApp', ['myApp.Services']);
  41.  
  42. app.controller('myCtrl', function($scope, $http) {
  43.  
  44. $scope.anyDirtyAndInvalid = function (){
  45. for(var x in $scope.testlogin) {
  46. var prop = $scope.testlogin[x];
  47. if(prop && prop.$dirty && prop.$invalid) {
  48. console.log(prop);
  49. return true;
  50. }
  51. }
  52. return false;
  53. };
  54.  
  55. myApp.config(['$routeProvider', function($routeProvider){
  56.  
  57. //this loads up our routes dynamically from the previous object
  58. for(var path in window.routes) {
  59. $routeProvider.when(path, window.routes[path]);
  60. }
  61. $routeProvider.otherwise({redirectTo: '/login'});
  62.  
  63. }]).run(function(){
  64.  
  65. $rootScope.$on("$locationChangeStart", function(event, next, current) {
  66. for(var i in window.routes) {
  67. if(next.indexOf(i) != -1) {
  68. if(window.routes[i].requireLogin && !SessionService.getUserAuthenticated()) {
  69. alert("You need to be authenticated to see this page!");
  70. event.preventDefault();
  71. }
  72. }
  73. }
  74. });
  75.  
  76. });
  77.  
  78. $scope.submit = function() {
  79. // alert("SUBMIT "+$scope.regObj.username);
  80. var stat="false";
  81. angular.forEach($scope.mydata, function(item){
  82. // alert(item.email);
  83. if((item.email==$scope.regObj.username)&&(item.Password==$scope.regObj.password))
  84. {
  85. stat="true";
  86. }
  87.  
  88.  
  89. });
  90. $scope.regObj.username="";
  91. $scope.regObj.password="";
  92. if(stat=="true")
  93. window.location.href = 'index.html';
  94. // else
  95. // alert("Wrong Details");
  96. };
  97.  
  98. $scope.regObj = {
  99. "username" : "",
  100. "password" : ""
  101.  
  102. };
  103. $scope.mydata;
  104. $http.get("data.json")
  105. .then(function(response) {
  106. $scope.mydata = response.data;
  107. angular.forEach($scope.mydata, function(item){
  108. // alert(item.email);
  109. })
  110.  
  111. });
  112. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement