-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Rudolf\Modules\Users\One\Admin\Profile; | ||
|
||
use Rudolf\Component\Alerts\Alert; | ||
use Rudolf\Component\Alerts\AlertsCollection; | ||
use Rudolf\Framework\Controller\AdminController; | ||
|
||
class AddController extends AdminController | ||
{ | ||
/** | ||
* @throws \Exception | ||
*/ | ||
public function add() | ||
{ | ||
if (isset($_POST['add'])) { | ||
if (empty($_POST['password']) || trim($_POST['password']) !== $_POST['password_again']) { | ||
AlertsCollection::add( | ||
new Alert( | ||
'error', | ||
'Podane hasła nie są identyczne!' | ||
) | ||
); | ||
$this->redirect(DIR.'/admin/users/add'); | ||
} | ||
|
||
$id = (new AddModel())->add($_POST); | ||
|
||
if ($id) { | ||
AlertsCollection::add( | ||
new Alert( | ||
'success', | ||
'Dodano użytkownika' | ||
) | ||
); | ||
$this->redirect(DIR.'/admin/users/edit/'.$id); | ||
} | ||
AlertsCollection::add( | ||
new Alert( | ||
'error', | ||
'Wystąpił nieoczekiwany błąd' | ||
) | ||
); | ||
} | ||
$view = new AddView(); | ||
$view->display(); | ||
$view->render(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Rudolf\Modules\Users\One\Admin\Profile; | ||
|
||
use Rudolf\Component\Auth\Auth; | ||
use Rudolf\Framework\Model\AdminModel; | ||
|
||
class AddModel extends AdminModel | ||
{ | ||
public function add($p) | ||
{ | ||
$auth = new Auth($this->pdo, $this->prefix); | ||
$hash = $auth->getPasswordHash($p['password']); | ||
|
||
$stmt = $this->pdo->prepare("INSERT INTO {$this->prefix}users SET | ||
nick = :nick, first_name = :first_name, surname = :surname, email = :email, | ||
password = :password, active = :active"); | ||
$stmt->bindValue(':nick', $p['nick']); | ||
$stmt->bindValue(':first_name', $p['first_name']); | ||
$stmt->bindValue(':surname', $p['surname']); | ||
$stmt->bindValue(':email', $p['email']); | ||
$stmt->bindValue(':password', $hash); | ||
$stmt->bindValue(':active', $p['active']); | ||
$stmt->execute(); | ||
|
||
return $this->pdo->lastInsertId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Rudolf\Modules\Users\One\Admin\Profile; | ||
|
||
use Rudolf\Framework\View\AdminView; | ||
use Rudolf\Modules\Users\One\Admin\User; | ||
|
||
class AddView extends AdminView | ||
{ | ||
protected $user; | ||
|
||
protected $path; | ||
|
||
public function display() | ||
{ | ||
$this->pageTitle = _('Profile'); | ||
$this->head->setTitle($this->pageTitle); | ||
|
||
$this->user = new User(); | ||
$this->path = DIR.'/admin/users/add'; | ||
$this->templateType = 'add'; | ||
$this->template = 'user-one'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Rudolf\Modules\Users\One\Admin\Profile; | ||
|
||
use Rudolf\Component\Alerts\Alert; | ||
use Rudolf\Component\Alerts\AlertsCollection; | ||
use Rudolf\Framework\Controller\AdminController; | ||
|
||
class DelController extends AdminController | ||
{ | ||
/** | ||
* @param $id | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function del($id) | ||
{ | ||
if (isset($_POST['delete'])) { | ||
if ((new DelModel())->del($id)) { | ||
AlertsCollection::add(new Alert( | ||
'success', | ||
'Poprawnie usunięto użytkownika' | ||
)); | ||
$this->redirect(DIR.'/admin/users'); | ||
} else { | ||
AlertsCollection::add(new Alert( | ||
'error', | ||
'Wystąpił nieoczekiwany błąd' | ||
)); | ||
} | ||
} | ||
|
||
$view = new DelView(); | ||
$view->display((new EditModel())->getUserInfoById($id)); | ||
$view->render(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Rudolf\Modules\Users\One\Admin\Profile; | ||
|
||
use Rudolf\Framework\Model\AdminModel; | ||
|
||
class DelModel extends AdminModel | ||
{ | ||
public function del($id) | ||
{ | ||
$query = $this->pdo->prepare("DELETE FROM {$this->prefix}users WHERE id = :id"); | ||
$query->bindValue(':id', $id, \PDO::PARAM_INT); | ||
|
||
return $query->execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Rudolf\Modules\Users\One\Admin\Profile; | ||
|
||
use Rudolf\Framework\View\AdminView; | ||
use Rudolf\Modules\Users\One\Admin\User; | ||
|
||
class DelView extends AdminView | ||
{ | ||
/** @var User */ | ||
protected $user; | ||
|
||
protected $path; | ||
|
||
public function display(array $user) | ||
{ | ||
$this->pageTitle = _('Profile'); | ||
$this->head->setTitle($this->pageTitle); | ||
$this->user = new User($user); | ||
|
||
$this->path = $this->user->delUrl(); | ||
$this->template = 'users-del'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters