Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. 'use strict';
  2. angular.module('main')
  3. .controller('LoginCtrl', function ($log,$scope, $state, Autentificacion, Validate) {
  4. $scope.user= {};
  5.  
  6. $scope.user.username= "";
  7. $scope.user.password= "";
  8. $scope.user.mac= "";
  9. $scope.show=false;
  10.  
  11. $scope.signIn = function() {
  12. if(Validate.validateLoginForm($scope.user)){
  13. $scope.show=false;
  14. try{
  15. window.MacAddress.getMacAddress(
  16. function(macAddress) {
  17. $scope.mac=macAddress;
  18. var credentials = {"username":"user", "password":"pass", "mac":"mac"};
  19. $log.log(credentials);
  20.  
  21. Autentificacion.login(credentials)
  22. .then(
  23. function (juanperez){
  24. console.log(juanperez);
  25. //$scope.juanito=juanperez;
  26. //TODO aquí vamos a guardar el token en una cookie
  27.  
  28. //TODO aquí va el goTo hacia el home
  29. },
  30. function(tarantino){console.log(tarantino)}
  31. );
  32. },
  33. function(fail) {alert(fail);}
  34. );
  35. }
  36. catch(err){
  37. $scope.user.mac="macAddress";
  38. var credentials=$scope.user;
  39. $log.log(credentials);
  40. Autentificacion.login(credentials)
  41. .then(
  42. function (juanperez){
  43. console.log(juanperez);
  44. //TODO aquí vamos a guardar el token en una cookie
  45. $scope.juanito=juanperez.data.token;
  46. //TODO aquí va el goTo hacia el home
  47. $state.go('home');
  48. },
  49. function(tarantino){
  50. console.log(tarantino)
  51. }
  52. );
  53. }
  54. }
  55. else{
  56. $scope.show=true;
  57. }
  58. };
  59. $log.log('Hello from your Controller: LoginCtrl in module main:. This is your controller:', this);
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement