2016-03-05 00:36:11 +01:00
|
|
|
<?php
|
2016-07-06 01:40:30 +02:00
|
|
|
use RedBeanPHP\Facade as RedBean;
|
2016-03-05 00:36:11 +01:00
|
|
|
|
2016-07-19 07:35:37 +02:00
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
2016-03-05 00:51:59 +01:00
|
|
|
class SignUpController extends Controller {
|
|
|
|
const PATH = '/signup';
|
2016-03-05 00:36:11 +01:00
|
|
|
|
2016-07-04 20:57:00 +02:00
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'any',
|
2016-07-19 07:35:37 +02:00
|
|
|
'requestData' => [
|
|
|
|
'name' => [
|
2016-07-19 07:38:43 +02:00
|
|
|
'validation' => DataValidator::length(2, 55),
|
2016-07-19 07:35:37 +02:00
|
|
|
'error' => ERRORS::INVALID_NAME
|
|
|
|
],
|
|
|
|
'email' => [
|
|
|
|
'validation' => DataValidator::contains('@'),
|
|
|
|
'error' => ERRORS::INVALID_EMAIL
|
|
|
|
],
|
|
|
|
'password' => [
|
|
|
|
'validation' => DataValidator::length(5, 20),
|
|
|
|
'error' => ERRORS::INVALID_PASSWORD
|
|
|
|
]
|
|
|
|
]
|
2016-07-04 20:57:00 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-03-05 00:51:59 +01:00
|
|
|
public function handler() {
|
|
|
|
$email = Controller::request('email');
|
|
|
|
$password = Controller::request('password');
|
|
|
|
|
2016-03-20 19:45:40 +01:00
|
|
|
$userId = $this->createNewUserAndRetrieveId($email, $password);
|
|
|
|
|
|
|
|
Response::respondSuccess(array(
|
|
|
|
'userId' => $userId,
|
|
|
|
'userEmail' => $email
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-04-05 01:00:39 +02:00
|
|
|
public function createNewUserAndRetrieveId($email, $password) {
|
2016-03-05 00:51:59 +01:00
|
|
|
$userInstance = new User();
|
|
|
|
$userInstance->setProperties(array(
|
|
|
|
'email' => $email,
|
2016-05-15 00:08:30 +02:00
|
|
|
'password' => Hashing::hashPassword($password)
|
2016-03-05 00:51:59 +01:00
|
|
|
));
|
|
|
|
|
2016-03-20 19:45:40 +01:00
|
|
|
return $userInstance->store();
|
2016-03-05 00:51:59 +01:00
|
|
|
}
|
|
|
|
}
|