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