From 7183b55f736bd63085395b4b97276ee11207fed0 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Thu, 24 Aug 2017 17:25:42 +0200 Subject: [PATCH] added admin signup --- app.js | 7 ++++--- index.html | 1 + views/login/login.html | 2 +- views/signup/signup.html | 41 +++++++++++++++++++++++++++++++++++++++ views/signup/signup.js | 42 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 views/signup/signup.html create mode 100644 views/signup/signup.js diff --git a/app.js b/app.js index 4259168..446dd16 100644 --- a/app.js +++ b/app.js @@ -2,7 +2,7 @@ var urlapi = "http://localhost:3000/api/"; //var urlapi = "http://192.168.1.36:3000/api/"; -//var urlapi = "http://51.255.193.106:3000/api/"; +//var urlapi = "http://37.59.123.45:3000/api/"; // Declare app level module which depends on views, and components angular.module('adminApp', [ @@ -10,6 +10,7 @@ angular.module('adminApp', [ 'ngMessages', 'angularBootstrapMaterial', 'app.navbar', + 'app.signup', 'app.login', 'app.main', 'app.search', @@ -26,14 +27,14 @@ config(['$locationProvider', '$routeProvider', function($locationProvider, $rout if((localStorage.getItem('cic_admin_token'))) { console.log(window.location.hash); - if(window.location.hash==='#!/login') + if((window.location.hash==='#!/login')||(window.location.hash==='#!/signup')) { window.location='#!/main'; } $routeProvider.otherwise({redirectTo: '/main'}); }else{ - if(window.location!=='#!/login') + if((window.location!=='#!/login')||(window.location!=='#!/signup')) { console.log('app, user no logged'); diff --git a/index.html b/index.html index 7d3ee55..e9a8c89 100644 --- a/index.html +++ b/index.html @@ -64,6 +64,7 @@ + diff --git a/views/login/login.html b/views/login/login.html index 9adf663..07c30ac 100644 --- a/views/login/login.html +++ b/views/login/login.html @@ -15,7 +15,7 @@
- + Create Admin
Login
diff --git a/views/signup/signup.html b/views/signup/signup.html new file mode 100644 index 0000000..764ca58 --- /dev/null +++ b/views/signup/signup.html @@ -0,0 +1,41 @@ +
+
+
+ +
+
+
+
+

Signup

+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ Back +
Login
+
+
+
+ + +
+ +
+
+
diff --git a/views/signup/signup.js b/views/signup/signup.js new file mode 100644 index 0000000..0336f66 --- /dev/null +++ b/views/signup/signup.js @@ -0,0 +1,42 @@ +'use strict'; + +angular.module('app.signup', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/signup', { + templateUrl: 'views/signup/signup.html', + controller: 'SignupCtrl' + }); +}]) + +.controller('SignupCtrl', function($scope, $http, $routeParams) { + $scope.user = {}; + $scope.doLogin = function() { + console.log('Doing login', $scope.user); + + $http({ + url: urlapi + 'admin/signup', + method: "POST", + data: $scope.user + }) + .then(function(response) { + console.log("response: "); + console.log(response.data); + if (response.data.success == true) + { + localStorage.setItem("cic_admin_token", response.data.token); + localStorage.setItem("cic_admin_userdata", JSON.stringify(response.data.user)); + window.location.reload(); + }else{ + console.log("login failed"); + } + + + }, + function(response) { // optional + // failed + console.log(response); + }); + + }; +});