Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(angular) {
  2.   'use strict';
  3.  
  4.   var connectMangasApp = angular.module('ConnectMangasApp', ['ngRoute']);
  5.  
  6.   connectMangasApp.config(function($routeProvider, $httpProvider) {
  7.  
  8.     $httpProvider.defaults.headers.post['Client-Service'] = 'frontend-client';
  9.     $httpProvider.defaults.headers.post['Auth-Key'] = 'simplerestapi';
  10.     $httpProvider.defaults.headers.post['Access-Control-Allow-Origin'] = '*';
  11.     $httpProvider.defaults.headers.post['X-Content-Type-Options'] = 'nosniff';
  12.     $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  13.  
  14.     $routeProvider.when('/', {
  15.       templateUrl: 'pages/auth.html',
  16.       controller: 'AuthController'
  17.     }).otherwise({
  18.       redirectTo: '/'
  19.     });
  20.  
  21.   });
  22.  
  23.   connectMangasApp.factory('authService', function($http) {
  24.  
  25.     return {
  26.  
  27.       register: function(username, password, email) {
  28.         return $http({
  29.           method: 'POST',
  30.           url: 'http://localhost/jg/ConnectMangas/server/UserController/register',
  31.           data: { username: username, password: password, email: email }
  32.         }).then(function(response) {
  33.           console.log(repsonse);
  34.           /* var registerInfos = response.data.infos;
  35.           return registerInfos; */
  36.         });
  37.       }
  38.  
  39.     }
  40.  
  41.     /* var register = function(username, password, email) {
  42.       return $http({
  43.         method: 'POST',
  44.         url: 'http://localhost/jg/ConnectMangas/server/UserController/register',
  45.         data: { username: username, password: password, email: email }
  46.       }).then(function(response) {
  47.         console.log(response);
  48.       });
  49.     };
  50.     return { register: register }; */
  51.  
  52.   });
  53.  
  54.   connectMangasApp.controller('AuthController', function($scope, authService) {
  55.  
  56.     $scope.register = function() {
  57.       var username = $scope.register.username;
  58.       var password = $scope.register.password;
  59.       var email = $scope.register.email;
  60.  
  61.       if ( typeof username != 'undefined' && typeof password != 'undefined' && typeof email != 'undefined' ) {
  62.         var registerPromise = authService.register(username, password, email);
  63.         console.log(registerPromise);
  64.         registerPromise.then(function(registerResult) {
  65.           console.log(registerResult);
  66.         });
  67.       }
  68.     }
  69.  
  70.   });
  71.  
  72. })(window.angular);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement