User delete functionality
This commit is contained in:
parent
5c8fcff96c
commit
cc7738ff9e
@ -19,16 +19,22 @@ function addUser($args)
|
||||
global $Language;
|
||||
|
||||
// Check if the username already exist in db.
|
||||
if( $dbUsers->userExists($args['username']) || Text::isEmpty($args['username']) )
|
||||
if( Text::isEmpty($args['username']) )
|
||||
{
|
||||
Alert::set($Language->g('username-already-exists-or-is-empty'));
|
||||
Alert::set($Language->g('username-field-is-empty'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $dbUsers->userExists($args['username']) )
|
||||
{
|
||||
Alert::set($Language->g('username-already-exists'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate password.
|
||||
if( ($args['password'] != $args['confirm-password'] ) || Text::isEmpty($args['password']) )
|
||||
{
|
||||
Alert::set($Language->g('password-does-not-match-the-confirm-password'));
|
||||
Alert::set($Language->g('The password and confirmation password do not match'));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,7 +46,7 @@ function addUser($args)
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set($Language->g('an-error-occurred-while-trying-to-create-the-user-account'));
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the account.');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ function editPage($args)
|
||||
{
|
||||
$dbPages->regenerate();
|
||||
|
||||
Alert::set($Language->g('the-changes-have-been-saved'));
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
Redirect::page('admin', 'edit-page/'.$args['key']);
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set($Language->g('an-error-occurred-while-trying-to-edit-the-page'));
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the page.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,12 +42,12 @@ function deletePage($key)
|
||||
|
||||
if( $dbPages->delete($key) )
|
||||
{
|
||||
Alert::set('The page has been deleted successfully');
|
||||
Alert::set($Language->g('The page has been deleted successfully'));
|
||||
Redirect::page('admin', 'manage-pages');
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set('an-error-occurred-while-trying-to-delete-the-page');
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the page.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,27 +20,28 @@ function editPost($args)
|
||||
// Edit the post.
|
||||
if( $dbPosts->edit($args) )
|
||||
{
|
||||
Alert::set($Language->g('the-changes-have-been-saved'));
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
Redirect::page('admin', 'edit-post/'.$args['key']);
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set($Language->g('an-error-occurred-while-trying-to-edit-the-post'));
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the post.');
|
||||
}
|
||||
}
|
||||
|
||||
function deletePost($key)
|
||||
{
|
||||
global $dbPosts;
|
||||
global $Language;
|
||||
|
||||
if( $dbPosts->delete($key) )
|
||||
{
|
||||
Alert::set('The post has been deleted successfull');
|
||||
Alert::set($Language->g('The post has been deleted successfully'));
|
||||
Redirect::page('admin', 'manage-posts');
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set('an-error-occurred-while-trying-to-delete-the-post');
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the post.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,19 +9,52 @@ function editUser($args)
|
||||
global $dbUsers;
|
||||
global $Language;
|
||||
|
||||
if(isset($args['password']))
|
||||
if( $dbUsers->set($args) ) {
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
}
|
||||
else {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the user.');
|
||||
}
|
||||
}
|
||||
|
||||
function setPassword($args)
|
||||
{
|
||||
global $dbUsers;
|
||||
global $Language;
|
||||
|
||||
if( ($args['password']===$args['confirm-password']) && !Text::isEmpty($args['password']) )
|
||||
{
|
||||
if( ($args['password']===$args['confirm-password']) && !Text::isEmpty($args['password']) ) {
|
||||
return $dbUsers->setPassword($args);
|
||||
if( $dbUsers->setPassword($args) ) {
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
}
|
||||
else {
|
||||
Alert::set($Language->g('password-does-not-match-the-confirm-password'));
|
||||
return false;
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to change the user password.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $dbUsers->set($args);
|
||||
else {
|
||||
Alert::set($Language->g('The password and confirmation password do not match'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteUser($args, $deleteContent=false)
|
||||
{
|
||||
global $dbUsers;
|
||||
global $dbPosts;
|
||||
global $Language;
|
||||
|
||||
if($deleteContent) {
|
||||
$dbPosts->deletePostsByUser($args['username']);
|
||||
}
|
||||
else {
|
||||
$dbPosts->linkPostsToUser($args['username'], 'admin');
|
||||
}
|
||||
|
||||
if( $dbUsers->delete($args['username']) ) {
|
||||
Alert::set($Language->g('User deleted'));
|
||||
}
|
||||
else {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the user.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,17 +64,25 @@ function editUser($args)
|
||||
|
||||
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
{
|
||||
|
||||
// Prevent editors users to administrate other users.
|
||||
if($Login->role()!=='admin')
|
||||
{
|
||||
$_POST['username'] = $Login->username();
|
||||
unset($_POST['role']);
|
||||
}
|
||||
|
||||
if( editUser($_POST) ) {
|
||||
Alert::set($Language->g('the-changes-have-been-saved'));
|
||||
if(isset($_POST['delete-user-all'])) {
|
||||
deleteUser($_POST, true);
|
||||
}
|
||||
elseif(isset($_POST['delete-user-associate'])) {
|
||||
deleteUser($_POST, false);
|
||||
}
|
||||
elseif(isset($_POST['change-password'])) {
|
||||
setPassword($_POST);
|
||||
}
|
||||
elseif(isset($_POST['edit-user'])) {
|
||||
editUser($_POST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@ -11,6 +11,6 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set('Username or password incorrect');
|
||||
Alert::set($Language->g('Username or password incorrect'));
|
||||
}
|
||||
}
|
@ -3,4 +3,4 @@
|
||||
if( $Login->logout())
|
||||
{
|
||||
Redirect::home();
|
||||
}
|
||||
}
|
@ -20,12 +20,12 @@ function addPage($args)
|
||||
// Add the page.
|
||||
if( $dbPages->add($args) )
|
||||
{
|
||||
Alert::set('Page added successfuly');
|
||||
Alert::set($Language->g('Page added successfully'));
|
||||
Redirect::page('admin', 'manage-pages');
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set($Language->g('an-error-occurred-while-trying-to-create-the-page'));
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the page.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,12 @@ function addPost($args)
|
||||
// Add the page.
|
||||
if( $dbPosts->add($args) )
|
||||
{
|
||||
Alert::set('Post added successfuly');
|
||||
Alert::set($Language->g('Post added successfully'));
|
||||
Redirect::page('admin', 'manage-posts');
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert::set($Language->g('an-error-occurred-while-trying-to-create-the-post'));
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the post.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ function setSettings($args)
|
||||
Alert::set($Language->g('the-changes-have-been-saved'));
|
||||
}
|
||||
else {
|
||||
Alert::set('Error occurred when trying to saved the settings');
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the settings.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
<li><a href="#profile"><?php $Language->p('Profile') ?></a></li>
|
||||
<li><a href="#email"><?php $Language->p('Email') ?></a></li>
|
||||
<li><a href="#password"><?php $Language->p('Password') ?></a></li>
|
||||
<li><a href="#delete"><?php $Language->p('Delete') ?></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@ -14,6 +15,7 @@
|
||||
|
||||
<div id="profile">
|
||||
<form method="post" action="" class="forms">
|
||||
<input type="hidden" name="edit-user" value="true">
|
||||
<input type="hidden" name="username" value="<?php echo $_user['username'] ?>">
|
||||
|
||||
<label>
|
||||
@ -56,6 +58,7 @@
|
||||
|
||||
<div id="email">
|
||||
<form method="post" action="" class="forms">
|
||||
<input type="hidden" name="edit-user" value="true">
|
||||
<input type="hidden" name="username" value="<?php echo $_user['username'] ?>">
|
||||
|
||||
<label>
|
||||
@ -75,6 +78,7 @@
|
||||
|
||||
<div id="password">
|
||||
<form method="post" action="" class="forms">
|
||||
<input type="hidden" name="change-password" value="true">
|
||||
<input type="hidden" name="username" value="<?php echo $_user['username'] ?>">
|
||||
|
||||
<label>
|
||||
@ -90,4 +94,26 @@
|
||||
<input type="submit" class="btn btn-blue" value="<?php $Language->p('Save') ?>" name="user-password">
|
||||
<a href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>" class="btn"><?php $Language->p('Cancel') ?></a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- ===================================== -->
|
||||
<!-- Delete -->
|
||||
<!-- ===================================== -->
|
||||
|
||||
<div id="delete">
|
||||
|
||||
<form method="post" action="" class="forms">
|
||||
<input type="hidden" name="delete-user-all" value="true">
|
||||
<input type="hidden" name="username" value="<?php echo $_user['username'] ?>">
|
||||
<p><input type="submit" class="btn btn-blue" value="Delete the user and all your content"></p>
|
||||
</form>
|
||||
|
||||
<form method="post" action="" class="forms">
|
||||
<input type="hidden" name="delete-user-associate" value="true">
|
||||
<input type="hidden" name="username" value="<?php echo $_user['username'] ?>">
|
||||
<p><input type="submit" class="btn btn-blue" value="Delete the user and the content associate to admin user"></p>
|
||||
</form>
|
||||
|
||||
<a href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>" class="btn"><?php $Language->p('Cancel') ?></a>
|
||||
|
||||
</div>
|
@ -35,7 +35,7 @@ class dbPosts extends dbJSON
|
||||
return $this->numberPosts['withoutDrafts'];
|
||||
}
|
||||
|
||||
// Return an array with the database for a page, FALSE otherwise.
|
||||
// Return an array with the post's database, FALSE otherwise.
|
||||
public function getDb($key)
|
||||
{
|
||||
if($this->postExists($key)) {
|
||||
@ -273,6 +273,44 @@ class dbPosts extends dbJSON
|
||||
return array();
|
||||
}
|
||||
|
||||
// Delete all posts from an user.
|
||||
public function deletePostsByUser($username)
|
||||
{
|
||||
foreach($this->db as $key=>$value)
|
||||
{
|
||||
if($value['username']==$username) {
|
||||
unset($this->db[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the database.
|
||||
if( $this->save() === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Link-up all posts from an user to another user.
|
||||
public function linkPostsToUser($oldUsername, $newUsername)
|
||||
{
|
||||
foreach($this->db as $key=>$value)
|
||||
{
|
||||
if($value['username']==$oldUsername) {
|
||||
$this->db[$key]['username'] = $newUsername;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the database.
|
||||
if( $this->save() === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// DEBUG: Ver una mejor manera de eliminar draft post antes de ordenarlos
|
||||
private function removeUnpublished()
|
||||
{
|
||||
|
@ -90,6 +90,18 @@ class dbUsers extends dbJSON
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($username)
|
||||
{
|
||||
unset($this->db[$username]);
|
||||
|
||||
if( $this->save() === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function add($args)
|
||||
{
|
||||
$dataForDb = array();
|
||||
|
@ -91,20 +91,20 @@
|
||||
"recent-posts": "Recent Posts",
|
||||
"manage-pages": "Manage pages",
|
||||
"advanced-options": "Advanced options",
|
||||
"user-deleted": "User deleted",
|
||||
"page-added-successfully": "Page added successfully",
|
||||
"post-added-successfully": "Post added successfully",
|
||||
"the-post-has-been-deleted-successfully": "The post has been deleted successfully",
|
||||
"the-page-has-been-deleted-successfully": "The page has been deleted successfully",
|
||||
"username-or-password-incorrect": "Username or password incorrect",
|
||||
"database-regenerated": "Database regenerated",
|
||||
"the-changes-have-been-saved": "The changes have been saved",
|
||||
"html-markdown-code-supported": "HTML and Markdown code supported.",
|
||||
"enable-more-features-at": "Enable more features at",
|
||||
"username-already-exists-or-is-empty": "Username already exists or is empty",
|
||||
"password-does-not-match-the-confirm-password":"Password does not match the confirm password",
|
||||
"username-already-exists": "Username already exists",
|
||||
"username-field-is-empty": "Username field is empty",
|
||||
"the-password-and-confirmation-password-do-not-match":"The password and confirmation password do not match",
|
||||
"user-has-been-added-successfully": "User has been added successfully",
|
||||
"an-error-occurred-while-trying-to-create-the-user-account": "An error occurred while trying to create the user account",
|
||||
"an-error-occurred-while-trying-to-delete-the-page": "An error occurred while trying to delete the page",
|
||||
"an-error-occurred-while-trying-to-delete-the-post": "An error occurred while trying to delete the post",
|
||||
"an-error-occurred-while-trying-to-create-the-page": "An error occurred while trying to create the page",
|
||||
"an-error-occurred-while-trying-to-create-the-post": "An error occurred while trying to create the post",
|
||||
"an-error-occurred-while-trying-to-edit-the-post": "An error occurred while trying to edit the post",
|
||||
"an-error-occurred-while-trying-to-edit-the-page": "An error occurred while trying to edit the page",
|
||||
"you-do-not-have-sufficient-permissions": "You do not have sufficient permissions to access this page, contact the administrator.",
|
||||
"settings-advanced-writting-settings": "Settings->Advanced->Writting Settings",
|
||||
"new-posts-and-pages-synchronized": "New posts and pages synchronized.",
|
||||
@ -122,5 +122,6 @@
|
||||
"you-can-use-this-field-to-define-a-set-of": "You can use this field to define a set of parameters related to the languege, country and special preferences.",
|
||||
"you-can-modify-the-url-which-identifies":"You can modify the URL which identifies a page or post using human-readable keywords. No more than 150 characters.",
|
||||
"this-field-can-help-describe-the-content": "This field can help describe the content in a few words. No more than 150 characters.",
|
||||
"write-the-tags-separeted-by-comma": "Write the tags separeted by comma. eg: tag1, tag2, tag3"
|
||||
"write-the-tags-separeted-by-comma": "Write the tags separeted by comma. eg: tag1, tag2, tag3",
|
||||
"delete": "Delete"
|
||||
}
|
@ -278,6 +278,6 @@ Responsive
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
overflow: scroll;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user