You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

7 years ago
7 years ago
7 years ago
  1. angular.module('app.signup', ['pascalprecht.translate'])
  2. .controller('SignupCtrl', function($scope, $ionicModal, $timeout, $http, $window, $ionicLoading) {
  3. $scope.signupData = {};
  4. $scope.doSignup = function() {
  5. console.log('Doing signup', $scope.signupData);
  6. if ($scope.emptyParams($scope.signupData)) {
  7. $http({
  8. url: urlapi + 'signup',
  9. method: "POST",
  10. data: $scope.signupData
  11. })
  12. .then(function(response) {
  13. // success
  14. console.log("response: ");
  15. console.log(response.data);
  16. if (response.data.success == true)
  17. {
  18. localStorage.setItem("cim_app_token", response.data.token);
  19. localStorage.setItem("cim_app_userdata", JSON.stringify(response.data.user));
  20. window.location.reload();
  21. }else{
  22. console.log("signup failed");
  23. $ionicLoading.show({ template: 'signup failed, user or password error.', noBackdrop: true, duration: 2000 });
  24. }
  25. },
  26. function(response) { // optional
  27. // failed
  28. $ionicLoading.show({
  29. template: 'Error on signup',
  30. noBackdrop: true,
  31. duration: 2000
  32. });
  33. });
  34. } else {
  35. $ionicLoading.show({
  36. template: 'First complete all parameters',
  37. noBackdrop: true,
  38. duration: 2000
  39. });
  40. }
  41. };
  42. $scope.emptyParams = function(obj) {
  43. if (obj.username == undefined) {
  44. return (false);
  45. }
  46. if (obj.password == undefined) {
  47. return (false);
  48. }
  49. if (obj.email == undefined) {
  50. return (false);
  51. }
  52. return (true);
  53. };
  54. });