diff --git a/system/admin/admin.php b/system/admin/admin.php index 8daf023..7d81e62 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -71,7 +71,20 @@ function edit_author($name, $title, $user, $password, $content) $name = get_author_info($name); $name = $name[0]; - create_user($user, $password, $name->role); + // Jika edit tanpa ganti password + if(empty($password)) { + $file = 'config/users/' . $user . '.ini'; + if (!file_exists($file)) + { + // Hanya akan dieksekusi ketika tidak melakukan penggantian password namun melakukan penggantian username + file_put_contents($file, "password = " . $name->password . "\n" . + "encryption = password_hash\n" . + "role = " . $name->role . "\n"); + } + } else { + // jika melakukan pergantian password + create_user($user, $password, $name->role); + } $user_title = safe_html($title); $user_content = '' . "\n\n" . $content; @@ -91,9 +104,10 @@ function edit_author($name, $title, $user, $password, $content) // Jika username lama tidak sama dengan yang baru maka file username lama akan dihapus if($name->username !== $user) { + // copying all content and file dari username lama ke username baru copy_folders('content/' . $name->username, 'content/' . $user); remove_folders('content/' . $name->username); - // Memastikan kalau username sesi sama dengan username lama + // Jika username sesi sama dengan username lama if($_SESSION[config("site.url")]['user'] === $name->username) { if (session_status() == PHP_SESSION_NONE) session_start(); $_SESSION[config("site.url")]['user'] = $user; diff --git a/system/admin/views/edit-author.html.php b/system/admin/views/edit-author.html.php index 912ca4c..f28d5ec 100644 --- a/system/admin/views/edit-author.html.php +++ b/system/admin/views/edit-author.html.php @@ -40,21 +40,23 @@ if(!empty($username)) {
+
- +
+
- +
- +
diff --git a/system/admin/views/layout.html.php b/system/admin/views/layout.html.php index 2a8aee6..950ae7e 100644 --- a/system/admin/views/layout.html.php +++ b/system/admin/views/layout.html.php @@ -30,15 +30,19 @@ -
+ + + @@ -95,12 +99,14 @@ + + + +
  • Password Confirm field is required.
  • '; + } + if (!password_match($password, $passconfirm)) { + $message['error'] .= '
  • Password and Password Confirm is not match.
  • '; + } + } else { + // If session user role not as admin + if (empty($passconfirm)) { + $message['error'] .= '
  • Password Confirm field is required.
  • '; + } + if (!password_match($password, $passconfirm)) { + $message['error'] .= '
  • Password and Password Confirm is not match.
  • '; + } + if (!valid_password($name, $oldpassword)) { + $message['error'] .= '
  • Old Password is not valid.
  • '; + } + } + + config('views.root', 'system/admin/views'); + render('edit-author', array( + 'title' => 'Edit author - ' . blog_title(), + 'description' => strip_tags(blog_description()), + 'canonical' => site_url(), + 'error' => '', + 'aTitle' => $title, + 'aUsername' => $username, + 'aOldPassword' => $oldpassword, + 'aPassword' => $password, + 'aPassConfirm' => $passconfirm, + 'aContent' => $content, + 'heading' => 'Edit author', + 'is_admin' => true, + 'bodyclass' => 'edit-author', + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit author' + )); + } + } } else { $message['error'] = ''; if (empty($title)) { @@ -430,18 +490,6 @@ post('/author/:name/edit', function ($name) { if (username_exists($username, $name)) { $message['error'] .= '
  • Username is already exist.
  • '; } - if (empty($password)) { - $message['error'] .= '
  • Password field is required.
  • '; - } - if (empty($passconfirm)) { - $message['error'] .= '
  • Password Confirm field is required.
  • '; - } - if (!password_match($password, $passconfirm)) { - $message['error'] .= '
  • Password and Password Confirm is not match.
  • '; - } - if (!valid_password($name, $oldpassword)) { - $message['error'] .= '
  • Old Password is not valid.
  • '; - } if (!$proper) { $message['error'] .= '
  • CSRF Token not correct.
  • '; } @@ -509,7 +557,7 @@ get('/author/:name/delete', function ($name) { // Get data Delete author post('/author/:name/delete', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); - if ($proper && login()) { + if ($proper && is_admin()) { $file = from($_REQUEST, 'file'); $destination = from($_GET, 'destination'); delete_author($file, $destination); diff --git a/system/includes/functions.php b/system/includes/functions.php index 5f5cef3..41f30b0 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -2943,8 +2943,6 @@ function head_contents() // Return toolbar function toolbar() { - $user = $_SESSION[config("site.url")]['user']; - $role = user('role', $user); $base = site_url(); echo <<