angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -


https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps

following tutorials, try write authentication restrict admin panel, didn't understood how can that.

this admin panel, admin panel don't want show , request database unauthenticated users.

my laravel-routes

 route::get('/admin',function(){    return view('index'); }); route::get('/api/v1/employees/{id?}', 'employees@index'); route::get('/api/v1/users/{id?}', 'employees@users'); route::post('/api/v1/employees', 'employees@store'); route::post('/api/v1/employees/{id}', 'employees@update'); route::delete('/api/v1/employees/{id}', 'employees@destroy');  route::group(['prefix' => 'api'], function() {     route::resource('authenticate', 'authenticatecontroller', ['only' => ['index']]);     route::post('authenticate', 'authenticatecontroller@authenticate');      route::get('authenticate/user', 'authenticatecontroller@getauthenticateduser'); }); 

this controller request database

angular.module('app')     .controller('employeescontroller', function($scope, $http, api_url,$stateparams,$auth,$rootscope,$state) {         //retrieve employees listing api         $scope.employees = '';           $http.get(api_url +  $stateparams.model)             .success(function(response) {                  $scope.employees = response;             });         //show modal form         $scope.toggle = function(modalstate, id) {             $scope.modalstate = modalstate;              switch (modalstate) {                 case 'add':                     $scope.form_title = "add new employee";                     break;                 case 'edit':                     $scope.form_title = "employee detail";                     $scope.id = id;                     $http.get(api_url + $stateparams.model+'/' + id)                         .success(function(response) {                             console.log(response);                             $scope.employee = response;                         });                     break;                 default:                     break;             }              $('#mymodal').modal('show');         }          //save new record / update existing record         $scope.save = function(modalstate, id) {             var url = api_url + "employees";              //append employee id url if form in edit mode             if (modalstate === 'edit') {                 url += "/" + id;             }             console.log('saved');             $http({                 method: 'post',                 url: url,                 data: $.param($scope.employee),                 headers: {                     'content-type': 'application/x-www-form-urlencoded'                 }             }).success(function(response) {                 var index = _.findindex($scope.employees, function(b) {                     return b.id == $scope.employee.id;                 });                   console.log(index);                 if (index != -1) {                     $scope.employees[index] = $scope.employee;                 } else {                    console.log($scope.employee);                     $scope.employee.id = response;                     $scope.employees.push($scope.employee);                     console.log($scope.employees);                 }                 $('#mymodal').modal('toggle');              }).error(function(response) {                 console.log(response);                 alert('this embarassing. error has occured. please check log details');             });         }          //delete record         $scope.confirmdelete = function(employee) {             var isconfirmdelete = confirm('are sure want record?');             if (isconfirmdelete) {                 $http({                     method: 'delete',                     url: api_url + 'employees/' + employee.id                 }).                 success(function(data) {                     _.remove($scope.employees, function(n) {                         return n.id == employee.id;                     });                     console.log(data);                 }).                 error(function(data) {                     console.log(data);                     alert('unable delete');                 });             } else {                 return false;             }         }         $scope.logout = function() {              $auth.logout().then(function() {                  // remove authenticated user local storage                 localstorage.removeitem('user');                  // flip authenticated false no longer                 // show ui elements dependant on user being logged in                 $rootscope.authenticated = false;                  // remove current user info rootscope                 $rootscope.currentuser = null;                  $state.go('auth')             });         }      }); 


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -