Advertisement
Guest User

LocalStorage

a guest
Jun 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. var app = angular.module("myApp", ['ngRoute']);
  4. var user = {};
  5. var user_arr = [];
  6.  
  7. app.config(function ($routeProvider) {
  8.  
  9.     $routeProvider.when('/', {
  10.         templateUrl: 'login.html',
  11.         controller:'loginCntrl'
  12.     }).when('/register', {
  13.         templateUrl: 'register.html',
  14.         controller:'registerCntrl'
  15.         }).when('/homepage', {
  16.             templateUrl: 'homePage.html',
  17.             controller:'homePageCntrl'
  18.         }).when('/profile', {
  19.             templateUrl: 'profile.html',
  20.             controller:'profileCntrl'
  21.         }).when('/messages', {
  22.             templateUrl: 'messages.html',
  23.             controller:'messageCntrl'
  24.         }).otherwise({
  25.         redirectTo: "/login"
  26.     });
  27. });
  28.  
  29. app.controller('loginCntrl', ['$scope', '$location', function ($scope, $location) {
  30.     var current_user_Obj = {};
  31.     $scope.Login = function () {
  32.         var user_name = $scope.usernameL;
  33.         var pwd = $scope.passwordL;
  34.         for (var i = 0; i < localStorage.length; i++) {
  35.             var val = JSON.parse(localStorage.getItem('userlist'));
  36.             if (val.username == user_name && val.password == pwd) {
  37.                 alert('Login successful');
  38.                 current_user_Obj = val;
  39.                 $location.path("/homepage");
  40.  
  41.             }
  42.         }
  43.  
  44.     }
  45.        
  46.     }
  47. ]);
  48. app.controller('registerCntrl', ['$scope', '$location', function ($scope, $location) {
  49.  
  50.     $scope.CreateAccount = function () {
  51.        
  52.         user.username = $scope.userName;
  53.         user.firstname = $scope.firstName;
  54.         user.lastname = $scope.lastName;
  55.         user.phone = $scope.phone;
  56.         user.email = $scope.email;
  57.         user.gender = $scope.myVar;
  58.         user.password = $scope.password;
  59.         user_arr.push(user);
  60.         localStorage.setItem('userlist', JSON.stringify(user));
  61.     }
  62.  
  63.     $scope.goBack = function () {
  64.         $location.path("/");
  65.     }
  66. }]);
  67. app.controller('homePageCntrl', ['$scope', '$location', function ($scope,$location) {
  68.  
  69.     $scope.go2Profile = function () {
  70.  
  71.         $location.path('/profile');
  72.  
  73.     }
  74.     $scope.go2Messages = function () {
  75.  
  76.         $location.path('/messages');
  77.  
  78.     }
  79.  
  80. }])
  81. app.controller('profileCntrl', ['$scope', '$location', function ($scope, $location) {
  82.  
  83.  
  84.  
  85. }])
  86. app.controller('messageCntrl', ['$scope', '$location', function ($scope, $location) {
  87.  
  88.  
  89.  
  90. }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement