From d89fa8e54641e4113f5d70421707352331a13960 Mon Sep 17 00:00:00 2001 From: Zarak Khan Date: Tue, 9 Jan 2024 15:31:34 +0500 Subject: [PATCH] User App --- .../templates/baseTemplate/newBase.html | 9 +- .../static/userManagment/userManagementV2.js | 407 ++++++++++++++++++ .../templates/userManagment/createUserV2.html | 153 +++++++ .../templates/userManagment/listUsersV2.html | 78 ++++ userManagment/urls.py | 6 +- userManagment/views.py | 52 +++ .../websiteFunctions/websiteFunctionsV2.js | 6 - 7 files changed, 699 insertions(+), 12 deletions(-) create mode 100644 userManagment/static/userManagment/userManagementV2.js create mode 100644 userManagment/templates/userManagment/createUserV2.html create mode 100644 userManagment/templates/userManagment/listUsersV2.html diff --git a/baseTemplate/templates/baseTemplate/newBase.html b/baseTemplate/templates/baseTemplate/newBase.html index d167aa549..2f916011c 100644 --- a/baseTemplate/templates/baseTemplate/newBase.html +++ b/baseTemplate/templates/baseTemplate/newBase.html @@ -11,6 +11,7 @@ {% load static %} + @@ -228,13 +229,13 @@ Profile
  • - • Create New User
  • - • List Users @@ -1662,9 +1663,11 @@ - +{##} + + \ No newline at end of file diff --git a/userManagment/static/userManagment/userManagementV2.js b/userManagment/static/userManagment/userManagementV2.js new file mode 100644 index 000000000..46a07d42c --- /dev/null +++ b/userManagment/static/userManagment/userManagementV2.js @@ -0,0 +1,407 @@ +newapp.controller('createUserCtrV2', function ($scope, $http) { + + $scope.acctsLimit = true; + $scope.webLimits = true; + $scope.userCreated = true; + $scope.userCreationFailed = true; + $scope.couldNotConnect = true; + $scope.userCreationLoading = true; + $scope.combinedLength = true; + + $scope.createUserFunc = function () { + + $scope.webLimits = false; + $scope.userCreated = true; + $scope.userCreationFailed = true; + $scope.couldNotConnect = true; + $scope.userCreationLoading = false; + $scope.combinedLength = true; + + + var firstName = $scope.firstName; + var lastName = $scope.lastName; + var email = $scope.email; + var selectedACL = $scope.selectedACL; + var websitesLimits = $scope.websitesLimits; + var userName = $scope.userName; + var password = $scope.password; + + + var url = "/users/submitUserCreation"; + + var data = { + firstName: firstName, + lastName: lastName, + email: email, + selectedACL: selectedACL, + websitesLimit: websitesLimits, + userName: userName, + password: password, + securityLevel: $scope.securityLevel + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.createStatus == 1) { + + $scope.userCreated = false; + $scope.userCreationFailed = true; + $scope.couldNotConnect = true; + $scope.userCreationLoading = true; + + $scope.userName = userName; + + + } else { + + $scope.acctsLimit = false; + $scope.webLimits = false; + $scope.userCreated = true; + $scope.userCreationFailed = false; + $scope.couldNotConnect = true; + $scope.userCreationLoading = true; + + $scope.errorMessage = response.data.error_message; + + + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.acctsLimit = false; + $scope.webLimits = false; + $scope.userCreated = true; + $scope.userCreationFailed = true; + $scope.couldNotConnect = false; + $scope.userCreationLoading = true; + + + } + + + }; + + $scope.hideSomeThings = function () { + + $scope.userCreated = true; + + + }; + + /// + + $scope.generatedPasswordView = true; + + $scope.generatePassword = function () { + $scope.generatedPasswordView = false; + $scope.password = randomPassword(16); + }; + + $scope.usePassword = function () { + $scope.generatedPasswordView = true; + }; + +}); + +newapp.controller('listTableUsersV2', function ($scope, $http) { + + $scope.cyberpanelLoading = true; + + var UserToDelete; + + $scope.populateCurrentRecords = function () { + $scope.cyberpanelLoading = false; + + url = "/users/fetchTableUsers"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + + if (response.data.status === 1) { + + $scope.records = JSON.parse(response.data.data); + + new PNotify({ + title: 'Success!', + text: 'Users successfully fetched!', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + + }; + $scope.populateCurrentRecords(); + + + $scope.deleteUserInitial = function (name){ + UserToDelete = name; + $scope.UserToDelete = name; + }; + + $scope.deleteUserFinal = function () { + $scope.cyberpanelLoading = false; + + var url = "/users/submitUserDeletion"; + + var data = { + accountUsername: UserToDelete, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.deleteStatus === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Users successfully deleted!', + type: 'success' + }); + + } else { + + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberpanelLoading = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + + + }; + + $scope.editInitial = function (name) { + + $scope.name = name; + + }; + + $scope.saveResellerChanges = function () { + + $scope.cyberpanelLoading = false; + + url = "/users/saveResellerChanges"; + + var data = { + userToBeModified: $scope.name, + newOwner: $scope.newOwner + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Changes successfully applied!', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.errorMessage, + type: 'error' + }); + } + + + } + + function cantLoadInitialDatas(response) { + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + + + }; + + $scope.changeACLFunc = function () { + + $scope.cyberpanelLoading = false; + + url = "/users/changeACLFunc"; + + var data = { + selectedUser: $scope.name, + selectedACL: $scope.selectedACL + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + + if (response.data.status === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'ACL Successfully changed.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.errorMessage, + type: 'error' + }); + } + + + } + + function cantLoadInitialDatas(response) { + $scope.aclLoading = true; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + + + }; + + $scope.controlUserState = function (userName, state) { + + $scope.cyberpanelLoading = false; + + var url = "/users/controlUserState"; + + var data = { + accountUsername: userName, + state: state + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Action successfully started.', + type: 'success' + }); + + } else { + + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + + + } + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberpanelLoading = false; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + + } + } + +}); \ No newline at end of file diff --git a/userManagment/templates/userManagment/createUserV2.html b/userManagment/templates/userManagment/createUserV2.html new file mode 100644 index 000000000..646e51a76 --- /dev/null +++ b/userManagment/templates/userManagment/createUserV2.html @@ -0,0 +1,153 @@ +{% extends "baseTemplate/newBase.html" %} +{% load i18n %} +{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %} +{% block newContent %} + + {% load static %} + +
    +
    +

    Create New User

    +

    Create root, reseller or normal users on this page.

    +
    +
    +
    +

    User Details

    + +
    +
    +
    +
    +
    +

    First Name

    +
    +
    + +
    {% trans "First Name should contain only alphabetic characters." %}
    +
    +
    +
    +
    +

    Last Name

    +
    +
    + +
    {% trans "Last Name should contain only alphabetic characters." %}
    +
    +
    +
    +
    +

    Email

    +
    +
    + +
    {% trans "Invalid Email" %}
    +
    +
    +
    +
    +

    Select ACL

    +
    +
    + +
    +
    +
    +
    +

    Website Limit

    +
    +
    + +
    +
    +
    +
    +

    Username

    +
    +
    + +
    +
    +
    +
    +

    Password

    +
    +
    + +
    +
    + +
    +
    +
    + +
    + +
    +
    + +
    +
    +
    +
    +

    Security Level

    +
    +
    + +
    +
    +
    + +
    + +
    + +
    +
    +

    {% trans "Account with username:" %} {$ userName + $} {% trans "is successfully created." %}

    +
    + +
    +

    {% trans "Cannot create user. Error message:" %} {$ errorMessage $}

    +
    + +
    +

    {% trans "Could not connect to server. Please refresh this page." %}

    +
    + +
    +

    {% trans "Length of first and last name combined should be less than or equal to 20 characters" %}

    +
    +
    +
    + +
    +
    +
    +{% endblock %} diff --git a/userManagment/templates/userManagment/listUsersV2.html b/userManagment/templates/userManagment/listUsersV2.html new file mode 100644 index 000000000..4bb88119f --- /dev/null +++ b/userManagment/templates/userManagment/listUsersV2.html @@ -0,0 +1,78 @@ +{% extends "baseTemplate/newBase.html" %} +{% load i18n %} +{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %} +{% block newContent %} + + {% load static %} + +
    +
    +
    +

    List Users

    +

    List users that you own.

    +
    +
    +
    +

    List Users

    + +
    +
    + +
    +
    + + +
    +
    + + + + + + + + + + +
    UsernameWebsite LimitDisk UsageACLOwnerStateAction
    +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + +
    +
    +
    + +
    +
    +
    +{% endblock %} diff --git a/userManagment/urls.py b/userManagment/urls.py index 2c589319c..9d5e1187a 100755 --- a/userManagment/urls.py +++ b/userManagment/urls.py @@ -6,15 +6,14 @@ url(r'^$', views.loadUserHome, name='loadUsersHome'), url(r'^viewProfile$', views.viewProfile, name='viewProfile'), url(r'^viewProfileV2$', views.viewProfileV2, name='viewProfileV2'), - url(r'^createUser', views.createUser, name='createUser'), - + url(r'^createUser$', views.createUser, name='createUser'), + url(r'^createUserV2$', views.createUserV2, name='createUserV2'), url(r'^submitUserCreation', views.submitUserCreation, name='submitUserCreation'), url(r'^modifyUsers', views.modifyUsers, name="modifyUsers"), url(r'^fetchUserDetails', views.fetchUserDetails, name="fetchUserDetails"), url(r'^saveModifications', views.saveModifications, name="saveModifications"), - url(r'^deleteUser', views.deleteUser, name="deleteUser"), url(r'^submitUserDeletion', views.submitUserDeletion, name="submitUserDeletion"), @@ -32,6 +31,7 @@ url(r'^apiAccess$', views.apiAccess, name="apiAccess"), url(r'^saveChangesAPIAccess$', views.saveChangesAPIAccess, name="saveChangesAPIAccess"), url(r'^listUsers$', views.listUsers, name="listUsers"), + url(r'^listUsersV2$', views.listUsersV2, name="listUsersV2"), url(r'^fetchTableUsers$', views.fetchTableUsers, name="fetchTableUsers"), url(r'^controlUserState$', views.controlUserState, name="controlUserState"), ] diff --git a/userManagment/views.py b/userManagment/views.py index 4c8df4c82..ef6ec61ea 100755 --- a/userManagment/views.py +++ b/userManagment/views.py @@ -86,6 +86,27 @@ def createUser(request): else: return ACLManager.loadError() +def createUserV2(request): + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + aclNames = ACLManager.unFileteredACLs() + proc = httpProc(request, 'userManagment/createUserV2.html', + {'aclNames': aclNames, 'securityLevels': SecurityLevel.list()}) + return proc.render() + elif currentACL['changeUserACL'] == 1: + aclNames = ACLManager.unFileteredACLs() + proc = httpProc(request, 'userManagment/createUserV2.html', + {'aclNames': aclNames, 'securityLevels': SecurityLevel.list()}) + return proc.render() + elif currentACL['createNewUser'] == 1: + aclNames = ['user'] + proc = httpProc(request, 'userManagment/createUserV2.html', + {'aclNames': aclNames, 'securityLevels': SecurityLevel.list()}) + return proc.render() + else: + return ACLManager.loadError() def apiAccess(request): userID = request.session['userID'] @@ -821,6 +842,37 @@ def listUsers(request): else: return ACLManager.loadError() +def listUsersV2(request): + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + aclNames = ACLManager.unFileteredACLs() + elif currentACL['changeUserACL'] == 1: + aclNames = ACLManager.unFileteredACLs() + elif currentACL['createNewUser'] == 1: + aclNames = ['user'] + else: + aclNames = [] + + if currentACL['admin'] == 1: + resellerPrivUsers = ACLManager.userWithResellerPriv(userID) + elif currentACL['resellerCenter'] == 1: + resellerPrivUsers = ACLManager.userWithResellerPriv(userID) + else: + resellerPrivUsers = [] + + if currentACL['admin'] == 1: + proc = httpProc(request, 'userManagment/listUsersV2.html', + {'aclNames': aclNames, 'resellerPrivUsers': resellerPrivUsers}) + return proc.render() + elif currentACL['listUsers'] == 1: + proc = httpProc(request, 'userManagment/listUsersV2.html', + {'aclNames': aclNames, 'resellerPrivUsers': resellerPrivUsers}) + return proc.render() + else: + return ACLManager.loadError() + def fetchTableUsers(request): try: try: diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctionsV2.js b/websiteFunctions/static/websiteFunctions/websiteFunctionsV2.js index f7e661d79..26061a71c 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctionsV2.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctionsV2.js @@ -3410,12 +3410,6 @@ function create_staging_checkbox_function() { newapp.controller('WPsiteHomeV2', function ($scope, $http, $timeout, $compile, $window) { - new PNotify({ - title: 'Operation Failed!', - text: 'hanbokjnjdknvjfsnkjg habbi', - type: 'error' - }); - var CheckBoxpasssword = 0;