javascript - Savely hide login information in MEAN app -
i'm building login function application using mean stack. i've got working login using angular ofcourse username , password shown in source it's not save use.
how can block information public?
this login use:
(function() { var app = angular.module('myapp', ['ui.router']); app.run(function($rootscope, $location, $state, loginservice) { $rootscope.$on('$statechangestart', function(event, tostate, toparams, fromstate, fromparams){ console.log('changed state to: ' + tostate); }); if(!loginservice.isauthenticated()) { $state.transitionto('login'); } }); app.config(['$stateprovider', '$urlrouterprovider', function($stateprovider, $urlrouterprovider) { $urlrouterprovider.otherwise('/home'); $stateprovider .state('login', { url : '/login', templateurl : 'login.html', controller : 'logincontroller' }) .state('home', { url : '/home', templateurl : 'home.html', controller : 'homecontroller' }); }]); app.controller('logincontroller', function($scope, $rootscope, $stateparams, $state, loginservice) { $rootscope.title = "angularjs login sample"; $scope.formsubmit = function() { if(loginservice.login($scope.username, $scope.password)) { $scope.error = ''; $scope.username = ''; $scope.password = ''; $state.transitionto('home'); } else { $scope.error = "incorrect username/password !"; } }; }); app.controller('homecontroller', function($scope, $rootscope, $stateparams, $state, loginservice) { $rootscope.title = "angularjs login sample"; }); app.factory('loginservice', function() { var admin = 'admin'; var pass = 'pass'; var isauthenticated = false; return { login : function(username, password) { isauthenticated = username === admin && password === pass; return isauthenticated; }, isauthenticated : function() { return isauthenticated; } }; }); })();
Comments
Post a Comment