Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Uncaught SyntaxError: Unexpected token )
- angular.module('myApp.Services').service('SessionService', function(){
- var userIsAuthenticated = false;
- this.setUserAuthenticated = function(value){
- userIsAuthenticated = value;
- };
- this.getUserAuthenticated = function(){
- return userIsAuthenticated;
- });
- }); <----------------- Error
- angular.module('myApp.Services').service('SessionService', function(){
- var userIsAuthenticated = false;
- this.setUserAuthenticated = function(value){
- userIsAuthenticated = value;
- };
- this.getUserAuthenticated = function(){
- return userIsAuthenticated;
- });
- });
- window.routes =
- {
- "/login": {
- templateUrl: 'login.html',
- controller: 'myCtrl',
- requireLogin: false
- },
- "/index": {
- templateUrl: 'index.html',
- requireLogin: true
- }
- };
- var app = angular.module('myApp', ['myApp.Services']);
- app.controller('myCtrl', function($scope, $http) {
- $scope.anyDirtyAndInvalid = function (){
- for(var x in $scope.testlogin) {
- var prop = $scope.testlogin[x];
- if(prop && prop.$dirty && prop.$invalid) {
- console.log(prop);
- return true;
- }
- }
- return false;
- };
- myApp.config(['$routeProvider', function($routeProvider){
- //this loads up our routes dynamically from the previous object
- for(var path in window.routes) {
- $routeProvider.when(path, window.routes[path]);
- }
- $routeProvider.otherwise({redirectTo: '/login'});
- }]).run(function(){
- $rootScope.$on("$locationChangeStart", function(event, next, current) {
- for(var i in window.routes) {
- if(next.indexOf(i) != -1) {
- if(window.routes[i].requireLogin && !SessionService.getUserAuthenticated()) {
- alert("You need to be authenticated to see this page!");
- event.preventDefault();
- }
- }
- }
- });
- });
- $scope.submit = function() {
- // alert("SUBMIT "+$scope.regObj.username);
- var stat="false";
- angular.forEach($scope.mydata, function(item){
- // alert(item.email);
- if((item.email==$scope.regObj.username)&&(item.Password==$scope.regObj.password))
- {
- stat="true";
- }
- });
- $scope.regObj.username="";
- $scope.regObj.password="";
- if(stat=="true")
- window.location.href = 'index.html';
- // else
- // alert("Wrong Details");
- };
- $scope.regObj = {
- "username" : "",
- "password" : ""
- };
- $scope.mydata;
- $http.get("data.json")
- .then(function(response) {
- $scope.mydata = response.data;
- angular.forEach($scope.mydata, function(item){
- // alert(item.email);
- })
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement