|
|
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>LILiK Users</title>
- <link rel="stylesheet" href="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.3/angular-material.css">
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-animate.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-aria.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-route.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-cookies.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-messages.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular-sanitize.min.js"></script>
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">
- <script src="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.3/angular-material.js"></script>
- <script>
- var sericesDescriptions = {
- admin: "You can access LILiK machines as root, edit users and much more...",
- mail: "<a href='https://webmail.lilik.it' target='_blank'>Go to your webmail</a>"
- }
- angular.module('Authentication', []);
- var app = angular.module("app",
- [
- 'Authentication',
- 'ngRoute',
- 'ngCookies',
- 'ngMaterial',
- 'ngMessages',
- 'ngSanitize'
- ]);
- app.config(['$routeProvider', function ($routeProvider) {
- $routeProvider.when('/login', {
- controller: 'LoginController',
- templateUrl: 'views/login.html',
- hideMenus: true
- }).when('/users/:ID', {
- controller: 'EditController',
- templateUrl: 'views/show.html'
- }).when('/users/:ID/edit', {
- controller: 'EditController',
- templateUrl: 'views/edit.html'
- }).otherwise({ redirectTo: '/login' });
- }]).run(['$rootScope', '$location', '$cookieStore', '$http', 'AuthenticationService', '$mdDialog',
- function ($rootScope, $location, $cookieStore, $http, AuthenticationService, $mdDialog) {
- $rootScope.getUsers = function(searchText) {
- return $http.get("/api/users").then(function(response) {
- return response.data.filter(function(user) {
- return user.startsWith(searchText);
- });
- });
- };
- $rootScope.$watch('globals.currentUser', function() {
- if (typeof $rootScope.globals.currentUser !== 'undefined') {
- $http.get("/api/users/"+$rootScope.globals.currentUser.username).then(function(response) {
- $rootScope.logged_user = response.data;
- console.log(response.data);
- });
- }
- });
- // keep user logged in after page refresh
- $rootScope.globals = $cookieStore.get('globals') || {};
- if ($rootScope.globals.currentUser) {
- $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
- }
-
- $rootScope.logout = function(){
- AuthenticationService.ClearCredentials();
- $location.path('/login');
- };
-
- $rootScope.promptNewUser = function(ev) {
- // Appending dialog to document.body to cover sidenav in docs app
- var confirm = $mdDialog.prompt()
- .title('Create new user')
- .textContent('Choose a uid for the new user')
- .placeholder('username')
- .ariaLabel('username')
- .initialValue('')
- .targetEvent(ev)
- .ok('Create')
- .cancel('Cancel');
-
- $mdDialog.show(confirm).then(function(result) {
- $http.post("/api/users", {uid: result}).then(function(response) {
- console.log(response.data);
- $rootScope.editUser(result);
- });
- }, function(){});
- };
-
- $rootScope.getServiceDescription = function(service){
- if (service in sericesDescriptions){
- return sericesDescriptions[service]
- }
- return service
- };
-
- $rootScope.editUser = function(user){
- $location.path('/users/'+user+'/edit');
- }
-
- $rootScope.home = function(){
- $location.path('/users/'+$rootScope.globals.currentUser.username);
- }
-
- $rootScope.$on('$locationChangeStart', function (event, next, current) {
- // redirect to login page if not logged in
- if ($location.path() !== '/login' && !$rootScope.globals.currentUser) {
- $location.path('/login');
- }
- });
- }]).controller('EditController', ['$scope', '$routeParams', '$http', '$mdDialog', function($scope, $routeParams, $http, $mdDialog) {
- console.log($routeParams.ID);
- $scope.password = {};
- if ($routeParams.ID == $scope.globals.currentUser.username){
- $scope.user = $scope.logged_user;
- }else{
- $http.get("/api/users/"+$routeParams.ID).then(function(response) {
- $scope.user = response.data;
- console.log(response.data);
- });
- }
- $scope.save = function(){
- console.log($scope.user);
- if ($scope.password.new == $scope.password.confirm){
- $scope.user.userPassword = $scope.password.new;
- }
- $http.put("/api/users/"+$routeParams.ID, $scope.user).then(function(response) {
- console.log(response.data);
- $scope.password = {};
- $mdDialog.hide();
- });
- };
-
-
- $scope.changePassword = function(ev) {
- $scope.password = {};
- // Appending dialog to document.body to cover sidenav in docs app
- var confirm = {
- clickOutsideToClose: true,
- targetEvent: ev,
- templateUrl: 'views/changePassword.html',
- scope: $scope,
- preserveScope: true,
- }
-
- $mdDialog.show(confirm).then(function(result) {
- console.log(result);
- // $http.post("/api/users", {uid: result}).then(function(response) {
- // console.log(response.data);
- // $rootScope.editUser(result);
- // });
- }, function(){});
- };
-
- $scope.closeDialog = function() {
- $mdDialog.hide();
- };
- }]);;
-
- app.directive('valueMatches', ['$parse', function ($parse) {
- return {
- require: 'ngModel',
- link: function (scope, elm, attrs, ngModel) {
- var originalModel = $parse(attrs.valueMatches),
- secondModel = $parse(attrs.ngModel);
- // Watch for changes to this input
- scope.$watch(attrs.ngModel, function (newValue) {
- ngModel.$setValidity(attrs.name, newValue === originalModel(scope));
- });
- // Watch for changes to the value-matches model's value
- scope.$watch(attrs.valueMatches, function (newValue) {
- ngModel.$setValidity(attrs.name, newValue === secondModel(scope));
- });
- }
- };
- }]);
- // controller("myCtrl", function($scope, $http, authService) {
- // $scope.$on('event:auth-loginRequired', function() {
- // console.log(54546);
- // });
- //
- // $scope.$on('event:auth-loginRequired', function() {
- // console.log("catch");
- // });
- //
- //
- //
- // $http.get("/api/users/test").then(function(response) {
- // $scope.user = response.data;
- // console.log(response.data);
- // });
- // // $http.get("/api/users").then(function(response) {
- // // $scope.users = response.data;
- // // });
- // });
-
- </script>
- <script src="authentication.js"></script>
- <script src="controllers.js"></script>
- <style>
- #search {
- display: inline-flex;
- }
- #search md-input-container {
- margin: 0;
- padding-bottom: -10px;
- }
- #search .md-errors-spacer {
- display: none;
- }
- #search md-progress-linear.md-inline {
- bottom: 1px;
- right: 2px;
- left: 2px;
- width: auto;
- height: 1px;
- }
- </style>
- </head>
- <body ng-app="app" ng-cloak>
- <div layout="row" layout-padding layout-align="space-between center" ng-if="globals.currentUser">
- <div>
- <md-button ng-click="home();">Home</md-button>
- <md-button ng-click="promptNewUser()" ng-if="logged_user.services.admin">New</md-button>
- <md-autocomplete ng-if="logged_user.services.admin" id="search" md-selected-item="selectedItem"
- md-search-text="searchText" md-select-on-match=true md-match-case-insensitive=false
- md-require-match=true md-floating-label ="Search user" md-selected-item-change="editUser(item)" md-items="item in getUsers(searchText)" md-item-text="item" flex="25">
- <span md-highlight-text="searchText">{{item}}</span>
- </md-autocomplete>
- </div>
- <div class="nav-buttons">
- <!-- <md-button class="md-raised md-accent">My profile</md-button> -->
- <md-button class="md-raised md-warn" ng-click="logout()">Log Out</md-button>
- </div>
- </div>
- <div ng-view></div>
- </body>
- </html>
|