Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. myTodoList.controller('authController', function($scope, $rootScope, $http, $location) {
  2. $scope.user = { username: '', password: '' };
  3. $scope.error_message = '';
  4.  
  5. $scope.login = function() {
  6. $http.post('/auth/login', $scope.user).success(function(data) {
  7. if (data.state == 'success') {
  8. $rootScope.authenticated = true;
  9. $rootScope.current_user = data.user.username;
  10. $location.path('/app');
  11. } else {
  12. $scope.error_message = data.message;
  13. }
  14. });
  15. };
  16.  
  17. $scope.register = function() {
  18. $http.post('/auth/signup', $scope.user).success(function(data) {
  19. if (data.state == 'success') {
  20. $rootScope.authenticated = true;
  21. $rootScope.current_user = data.user.username;
  22. $location.path('/app');
  23. } else {
  24. $scope.error_message = data.message;
  25. }
  26. });
  27. };
  28.  
  29. var myTodoList = angular.module("myTodoList", ['ngRoute', 'ngResource']).run(function($http, $rootScope) {
  30. $rootScope.authenticated = false;
  31. $rootScope.current_user = 'Guest';
  32.  
  33. $rootScope.signout = function() {
  34. $http.get('auth/signout');
  35. $rootScope.authenticated = false;
  36. $rootScope.current_user = 'Guest';
  37. };
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement