Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myTodoList.controller('authController', function($scope, $rootScope, $http, $location) {
- $scope.user = { username: '', password: '' };
- $scope.error_message = '';
- $scope.login = function() {
- $http.post('/auth/login', $scope.user).success(function(data) {
- if (data.state == 'success') {
- $rootScope.authenticated = true;
- $rootScope.current_user = data.user.username;
- $location.path('/app');
- } else {
- $scope.error_message = data.message;
- }
- });
- };
- $scope.register = function() {
- $http.post('/auth/signup', $scope.user).success(function(data) {
- if (data.state == 'success') {
- $rootScope.authenticated = true;
- $rootScope.current_user = data.user.username;
- $location.path('/app');
- } else {
- $scope.error_message = data.message;
- }
- });
- };
- var myTodoList = angular.module("myTodoList", ['ngRoute', 'ngResource']).run(function($http, $rootScope) {
- $rootScope.authenticated = false;
- $rootScope.current_user = 'Guest';
- $rootScope.signout = function() {
- $http.get('auth/signout');
- $rootScope.authenticated = false;
- $rootScope.current_user = 'Guest';
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement