diff --git a/.gitignore b/.gitignore index a2b6144..61e9fe8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,33 +1,33 @@ ###CI4### -public/.htaccess -public/favicon.ico -public/index.php -public/robots.txt - -build/ -system/ -tests/_support -tests/system -tests/.htaccess -tests/README.md -vendor/ -writable/ - -app/index.html -app/.htaccess - -app/Config/* -!app/Config/Aauth.php - -app/Filters/Throttle.php -app/Filters/Honeypot.php -app/Filters/CSRF.php -app/Filters/DebugToolbar.php - -app/Views/errors/ -app/Views/welcome_message.php -app/Views/form.php +/public/.htaccess +/public/favicon.ico +/public/index.php +/public/robots.txt + +/admin/ +/build/ +/system/ +/tests/_support +/tests/system +/tests/.htaccess +/tests/README.md +/vendor/ +/writable/ + +/app/index.html +/app/.htaccess + +/app/Config/* +!/app/Config/Aauth.php + +/app/Filters/Throttle.php +/app/Filters/Honeypot.php +/app/Filters/CSRF.php +/app/Filters/DebugToolbar.php + +/app/Views/errors/ +/app/Views/welcome_message.php composer.lock spark @@ -47,4 +47,3 @@ spark Thumbs.db ehthumbs.db Desktop.ini -admin diff --git a/app/Controllers/Admin/Users.php b/app/Controllers/Admin/Users.php index eb58ce8..d65a962 100644 --- a/app/Controllers/Admin/Users.php +++ b/app/Controllers/Admin/Users.php @@ -20,6 +20,7 @@ namespace App\Controllers\Admin; use CodeIgniter\Controller; use Config\Aauth as AauthConfig; use App\Libraries\Aauth; +use Config\Services; /** * Aauth Admin/Users Controller @@ -33,7 +34,9 @@ class Users extends Controller */ public function __construct() { + $this->config = new AauthConfig(); $this->aauth = new Aauth(); + $this->request = Services::request(); helper('form'); helper('aauth'); } @@ -47,7 +50,7 @@ class Users extends Controller { $data = $this->aauth->listUsersPaginated(); - $data['cssFiles'] = [ + $data['cssFiles'] = [ '/assets/css/admin/users/index.css' ]; @@ -63,10 +66,107 @@ class Users extends Controller */ public function new() { - $data = $this->aauth->listUsersPaginated(); + $data['useUsername'] = $this->config->loginUseUsername; echo view('Templates/HeaderAdmin'); echo view('Admin/Users/New', $data); echo view('Templates/FooterAdmin'); } + + /** + * Create + * + * @return void + */ + public function create() + { + $email = $this->request->getPost('email'); + $username = $this->request->getPost('username'); + $password = $this->request->getPost('password'); + + if (! $this->aauth->createUser($email, $password, empty($username) ? null : $username)) + { + return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); + } + + return redirect()->to('/admin/users'); + } + + /** + * Edit + * + * @return void + */ + public function edit($userId) + { + $data['useUsername'] = $this->config->loginUseUsername; + $data['user'] = $this->aauth->getUser($userId); + + echo view('Templates/HeaderAdmin'); + echo view('Admin/Users/Edit', $data); + echo view('Templates/FooterAdmin'); + } + + /** + * Update + * + * @return void + */ + public function update($userId) + { + $email = $this->request->getPost('email'); + $username = $this->request->getPost('username'); + $password = $this->request->getPost('password'); + + if (! $this->aauth->updateUser($userId, empty($email) ? null : $email, empty($password) ? null : $password, empty($username) ? null : $username)) + { + return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); + } + + return redirect()->to('/admin/users/edit/' . $userId); + } + + /** + * Show + * + * @return void + */ + public function show($userId) + { + $data['user'] = $this->aauth->getUser($userId); + + echo view('Templates/HeaderAdmin'); + echo view('Admin/Users/Show', $data); + echo view('Templates/FooterAdmin'); + } + + /** + * Delete + * + * @return void + */ + public function delete($userId) + { + if (! $this->aauth->getUser($userId)) + { + return redirect()->to('/admin/users'); + } + + $id = $this->request->getPost('id'); + if ($userId == $id) + { + if($this->aauth->deleteUser($userId)) + { + return redirect()->to('/admin/users'); + } + } + + $data['user'] = $this->aauth->getUser($userId); + + echo view('Templates/HeaderAdmin'); + echo view('Admin/Users/Delete', $data); + echo view('Templates/FooterAdmin'); + } + + } diff --git a/app/Language/en/Admin.php b/app/Language/en/Admin.php index 009b1b4..ed09a9f 100644 --- a/app/Language/en/Admin.php +++ b/app/Language/en/Admin.php @@ -25,29 +25,36 @@ * @codeCoverageIgnore */ return [ - 'homeHeader' => 'Admin Area', - 'homeText' => 'Welcome to CodeIgniter-Aauth\'s Admin Area', - 'homeBreadcrumbTitle' => 'Home', + 'homeHeader' => 'Admin Area', + 'homeText' => 'Welcome to CodeIgniter-Aauth\'s Admin Area', + 'homeBreadcrumbTitle' => 'Home', - 'breadcrumbCommonNew' => 'New', - 'breadcrumbCommonEdit' => 'Edit', - 'breadcrumbCommonShow' => 'Show', - 'breadcrumbCommonDelete' => 'Delete', + 'breadcrumbCommonNew' => 'New', + 'breadcrumbCommonEdit' => 'Edit', + 'breadcrumbCommonShow' => 'Show', + 'breadcrumbCommonDelete' => 'Delete', - 'usersIndexHeader' => 'Users', - 'usersNewHeader' => 'New user', - 'usersEditHeader' => 'Edit user', - 'usersShowHeader' => 'Show user', - 'usersDeleteHeader' => 'Delete user', - 'usersBreadcrumbTitle' => 'Users', - 'usersLabelId' => 'Id', - 'usersLabelEmail' => 'Email address', - 'usersLabelUsername' => 'Username', - 'usersLabelBanned' => 'Banned', - 'usersLabelCreatedAt' => 'Created at', - 'usersLabelUpdatedAt' => 'Updated at', - 'usersLabelLastIPAddress' => 'Last IP-Address', - 'usersLabelLastActivity' => 'Last Activity', - 'usersLabelLastLogin' => 'Last Login', - 'usersLinkNew' => 'Create new user', + 'usersIndexHeader' => 'Users', + 'usersNewHeader' => 'New user', + 'usersNewSubmit' => 'Create new user', + 'usersEditHeader' => 'Edit user', + 'usersEditSubmit' => 'Update user', + 'usersShowHeader' => 'Show user', + 'usersDeleteHeader' => 'Delete user', + 'usersDeleteSubmit' => 'Delete user', + 'usersBreadcrumbTitle' => 'Users', + 'usersLabelId' => 'Id', + 'usersLabelEmail' => 'Email address', + 'usersLabelUsername' => 'Username', + 'usersLabelEmailCurrent' => 'Current email address', + 'usersLabelUsernameCurrent' => 'Current username', + 'usersLabelPassword' => 'Password', + 'usersLabelBanned' => 'Banned', + 'usersLabelCreatedAt' => 'Created at', + 'usersLabelUpdatedAt' => 'Updated at', + 'usersLabelLastIPAddress' => 'Last IP-Address', + 'usersLabelLastActivity' => 'Last Activity', + 'usersLabelLastLogin' => 'Last Login', + 'usersLinkNew' => 'Create new user', + 'usersLinkBack' => 'Back', ]; diff --git a/app/Views/Admin/Users/Delete.php b/app/Views/Admin/Users/Delete.php new file mode 100644 index 0000000..4d5ed02 --- /dev/null +++ b/app/Views/Admin/Users/Delete.php @@ -0,0 +1,34 @@ +
+= $user['id'] ?>
+= $user['email'] ?>
+= $user['username'] ?>
+= $user['email'] ?>
+= $user['username'] ?>
+= $user['id'] ?>
+= $user['email'] ?>
+= $user['username'] ?>
+`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Remove the bottom border in Firefox 39-.\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Duplicate behavior to the data-* attribute for our tooltip plugin\n\nabbr[title],\nabbr[data-original-title] { // 4\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 1\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\ndfn {\n font-style: italic; // Add the correct font style in Android 4.3-\n}\n\n// stylelint-disable font-weight-notation\nb,\nstrong {\n font-weight: bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n// stylelint-enable font-weight-notation\n\nsmall {\n font-size: 80%; // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n font-size: 75%;\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n -webkit-text-decoration-skip: objects; // Remove gaps in links underline in iOS 8+ and Safari 8+.\n\n @include hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href)\n// which have not been made explicitly keyboard-focusable (without tabindex).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([tabindex]) {\n color: inherit;\n text-decoration: none;\n\n @include hover-focus {\n color: inherit;\n text-decoration: none;\n }\n\n &:focus {\n outline: 0;\n }\n}\n\n\n//\n// Code\n//\n\npre,\ncode,\nkbd,\nsamp {\n font-family: $font-family-monospace;\n font-size: 1em; // Correct the odd `em` font sizing in all browsers.\n}\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // We have @viewport set which causes scrollbars to overlap content in IE11 and Edge, so\n // we force a non-overlapping, non-auto-hiding scrollbar to counteract.\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg {\n // Workaround for the SVG overflow bug in IE10/11 is still required.\n // See https://github.com/twbs/bootstrap/issues/26878\n overflow: hidden;\n vertical-align: middle;\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $table-caption-color;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `