Advertisement
Guest User

Untitled

a guest
Nov 18th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('RouteControllers', [])
  2.     .controller('HomeController', function($scope) {
  3.         $scope.title = "Welcome To Angular Todo!"
  4.     })
  5.     .controller('RegisterController', function($scope, UserAPIService, store) {
  6.         $scope.registrationUser = {};
  7.         var URL = "https://morning-castle-91468.herokuapp.com/";
  8.  
  9.         $scope.login = function() {
  10.             UserAPIService.callAPI(URL + "accounts/api-token-auth/", $scope.data).then(function(results) {
  11.                 $scope.token = results.data.token;
  12.                 store.set('username', $scope.registrationUser.username);
  13.                 store.set('authToken', $scope.token);
  14.             }).catch(function(err) {
  15.                 console.log(err.data);
  16.             });
  17.         }
  18.  
  19.         $scope.submitForm = function() {
  20.             if ($scope.registrationForm.$valid) {
  21.                 $scope.registrationUser.username = $scope.user.username;
  22.                 $scope.registrationUser.password = $scope.user.password;
  23.  
  24.                 UserAPIService.callAPI(URL + "accounts/register/", $scope.registrationUser).then(function(results) {
  25.                     $scope.data = results.data;
  26.                     alert("You have successfully registered to Angular Todo");
  27.                     $scope.login();
  28.                 }).catch(function(err) {
  29.                     alert("Oops! Something went wrong!");
  30.                 });
  31.             }
  32.         };
  33.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement