implement user registration and improve user handling
This commit is contained in:
parent
10d9145dce
commit
7755f453db
7 changed files with 260 additions and 28 deletions
|
|
@ -37,6 +37,12 @@
|
|||
* @var array
|
||||
*/
|
||||
public $models = array('users', 'characters');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
|
||||
|
||||
|
||||
|
|
@ -102,12 +108,12 @@
|
|||
$username,
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
||||
|
||||
if(!is_null($userId))
|
||||
{
|
||||
$this->Auth->setUserId($userId);
|
||||
$user = $this->Users->getUserById($userId);
|
||||
|
||||
|
||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||
}
|
||||
}
|
||||
|
|
@ -119,6 +125,68 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: register.
|
||||
*
|
||||
* Register a new user.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$username = '';
|
||||
$prename = '';
|
||||
$surname = '';
|
||||
$email = '';
|
||||
|
||||
$fields = array('username', 'prename', 'surname', 'email', 'password');
|
||||
$validation = array();
|
||||
|
||||
// Register a new user
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('register')))
|
||||
{
|
||||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
|
||||
$username = $this->request->getPostParam('username');
|
||||
$prename = $this->request->getPostParam('prename');
|
||||
$surname = $this->request->getPostParam('surname');
|
||||
$email = $this->request->getPostParam('email');
|
||||
|
||||
// Register
|
||||
if($validation === true)
|
||||
{
|
||||
$userId = $this->Users->createUser(
|
||||
$username,
|
||||
$prename,
|
||||
$surname,
|
||||
$email,
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
||||
// Login
|
||||
$this->Auth->setUserId($userId);
|
||||
$user = $this->Users->getUserById($userId);
|
||||
|
||||
// Redirect to user page
|
||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Get validation settings
|
||||
$validationSettings = array();
|
||||
foreach($fields as &$field) {
|
||||
$validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('username', $username);
|
||||
$this->set('prename', $prename);
|
||||
$this->set('surname', $surname);
|
||||
$this->set('email', $email);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: logout.
|
||||
*
|
||||
|
|
@ -146,6 +214,8 @@
|
|||
// Create new user
|
||||
$userId = $this->Users->createUser(
|
||||
$this->request->getPostParam('username'),
|
||||
$this->request->getPostParam('prename'),
|
||||
$this->request->getPostParam('surname'),
|
||||
$this->request->getPostParam('email'),
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
|
@ -180,6 +250,8 @@
|
|||
$this->Users->editUser(
|
||||
$user['id'],
|
||||
$this->request->getPostParam('username'),
|
||||
$this->request->getPostParam('prename'),
|
||||
$this->request->getPostParam('surname'),
|
||||
$this->request->getPostParam('email'),
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue