Working on this RedisModel class
Got it working fairly well, just trying to get all of my assumption / opinions baked in. Still need to come up with a decent way to generate session hashes to help avoid session collision . Incidentally Retwis seems to be susceptible to this.
This commit is contained in:
parent
7063b7aafe
commit
9fe9eb7acf
5 changed files with 140 additions and 38 deletions
|
@ -2,29 +2,62 @@
|
|||
|
||||
class user_create extends CustomModule
|
||||
{
|
||||
//protected $ajax = true;
|
||||
//protected $method = 'POST';
|
||||
//protected $validate = array(
|
||||
// 'username' => array(
|
||||
// 'length:>:30' => 'Usernames may not be more than 30 characters.',
|
||||
// 'regex:is:/[^a-z0-9-]+/i' => 'Usernames may only contain alphanumeric characters or dashes.',
|
||||
// 'regex:is:/^(-.+|.+-)$/' => 'Usernames may not start or end with a dash.',
|
||||
// 'regex:is:/-{2,}/' => 'Usernames may not have two or more dashes in a row.',
|
||||
// ),
|
||||
// 'email' => array(
|
||||
// 'length:>:100' => 'Email addresses may not be more than 100 characters.',
|
||||
// 'filter:email' => 'Your email address is invalid.',
|
||||
// ),
|
||||
// 'password' => array(
|
||||
// 'length:<:8' => 'Passwords may not be less than 8 characters.',
|
||||
// ),
|
||||
//);
|
||||
// protected $ajax = true;
|
||||
// protected $method = 'POST';
|
||||
// protected $validate = array(
|
||||
// 'email' => array(
|
||||
// 'length:>:100' => 'Email addresses may not be more than 100 characters.',
|
||||
// 'filter:email' => 'Your email address is invalid.',
|
||||
// ),
|
||||
// 'username' => array(
|
||||
// 'length:<:4' => 'Usernames may not be less than 4 characters.',
|
||||
// 'length:>:30' => 'Usernames may not be more than 50 characters.',
|
||||
// 'regex:is:/[^a-z0-9]+/i' => 'Usernames may only contain letters and numbers.',
|
||||
// ),
|
||||
// 'password' => array(
|
||||
// 'length:<:8' => 'Passwords may not be less than 8 characters.',
|
||||
// ),
|
||||
// );
|
||||
|
||||
public function __default()
|
||||
{
|
||||
var_dump($this->redis->set('test', sha1(microtime(true))));
|
||||
var_dump($this->redis->get('test'));
|
||||
var_dump($this->redis->info());
|
||||
try
|
||||
{
|
||||
$_POST = array(
|
||||
'email' => 'foo@bar.com',
|
||||
'username' => 'fubar',
|
||||
'password' => 'insecure123',
|
||||
);
|
||||
|
||||
|
||||
$user = new User();
|
||||
|
||||
// Checks if the email or username is already in use
|
||||
foreach (array('email', 'username') as $field)
|
||||
{
|
||||
if ($user->getUID($field, $_POST[$field]))
|
||||
{
|
||||
return array('error' => 'The ' . $field . ' is already in use.');
|
||||
}
|
||||
}
|
||||
|
||||
// Grabs the next UID
|
||||
$uid = $user->nextUID();
|
||||
|
||||
// Writes the user data
|
||||
$user->set('1001', array(
|
||||
'username' => $_POST['username'],
|
||||
'email' => $_POST['email'],
|
||||
'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'),
|
||||
));
|
||||
|
||||
// Sets up the authentication cookie
|
||||
//$user->setAuth()
|
||||
}
|
||||
catch (RedisException $e)
|
||||
{
|
||||
return array('error' => $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue