Browse Source

added admin signup

master
arnaucode 7 years ago
parent
commit
7183b55f73
5 changed files with 89 additions and 4 deletions
  1. +4
    -3
      app.js
  2. +1
    -0
      index.html
  3. +1
    -1
      views/login/login.html
  4. +41
    -0
      views/signup/signup.html
  5. +42
    -0
      views/signup/signup.js

+ 4
- 3
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');

+ 1
- 0
index.html

@ -64,6 +64,7 @@
<!-- app's js -->
<script src="app.js"></script>
<script src="views/navbar.js"></script>
<script src="views/signup/signup.js"></script>
<script src="views/login/login.js"></script>
<script src="views/main/main.js"></script>
<script src="views/search/search.js"></script>

+ 1
- 1
views/login/login.html

@ -15,7 +15,7 @@
<div class="form-group">
<input ng-model="user.password" abmFormControl class="form-control" id="inputPassword" placeholder="Password" type="password">
</div>
<a ng-href="#!/signup" class="btn btn-raised c_grey500">Create Admin</a>
<div ng-click="doLogin()" class="btn btn-raised c_deepPurple300 pull-right">Login</div>
</div>
</div>

+ 41
- 0
views/signup/signup.html

@ -0,0 +1,41 @@
<div class="container">
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-4">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">Signup</h3>
</div>
<div class="panel-body">
<div class="form-group">
<input ng-model="user.adminPassword" abmFormControl class="form-control" id="inputAdminPassword" placeholder="AdminPassword" type="password">
</div>
<div class="form-group label-floating">
<input ng-model="user.username" abmFormControl class="form-control" id="inputUsername" placeholder="Username" type="text">
</div>
<div class="form-group">
<input ng-model="user.password" abmFormControl class="form-control" id="inputPassword" placeholder="Password" type="password">
</div>
<div class="form-group label-floating">
<input ng-model="user.email" abmFormControl class="form-control" id="inputEmail" placeholder="Email" type="text">
</div>
<div class="form-group label-floating">
<input ng-model="user.phone" abmFormControl class="form-control" id="inputPhone" placeholder="Phone" type="text">
</div>
<div class="form-group label-floating">
<input ng-model="user.telegram" abmFormControl class="form-control" id="inputTelegram" placeholder="Telegram" type="text">
</div>
<a ng-href="#!/login" class="btn btn-raised c_grey500">Back</a>
<div ng-click="doLogin()" class="btn btn-raised c_deepPurple300 pull-right">Login</div>
</div>
</div>
</div>
<div class="col-sm-4">
</div>
</div>
</div>

+ 42
- 0
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);
});
};
});

Loading…
Cancel
Save