예제 #1
0
 public function signup(array $data)
 {
     $response = new Response();
     if (empty($data)) {
         $response->setContent($this->app->trans('UNKNOWN_ERROR'));
         return false;
     }
     $constraints = new Assert\Collection(array('username' => array(new Assert\NotBlank(array('message' => 'FILL_ALL_FIELDS')), new Assert\Length(array('min' => 4)), new Assert\Length(array('max' => 15))), 'password' => array(new Assert\NotBlank(array('message' => 'FILL_ALL_FIELDS')), new Assert\Length(array('min' => 4))), 'confirm' => array(new Assert\NotBlank(array('message' => 'FILL_ALL_FIELDS')), new Assert\Length(array('min' => 4))), 'email' => array(new Assert\NotBlank(array('message' => 'FILL_ALL_FIELDS')), new Assert\Email(array('message' => 'INVALID_EMAIL'))), 'terms' => array(new Assert\NotBlank(array('message' => 'FILL_ALL_FIELDS')))));
     $errors = $this->app['validator']->validateValue($data, $constraints);
     if (count($errors) > 0) {
         $response->setStatusCode(400);
         $response->setContent($this->app->trans($errors[0]->getMessage()));
         return $response;
     }
     if ($data['password'] !== $data['confirm']) {
         $response->setStatusCode(400);
         $response->setContent($this->app->trans('PASSWORDS_DONT_MATCH'));
         return $response;
     }
     $check_username = $this->app['db']->fetchColumn('SELECT username FROM users WHERE username=? LIMIT 1', array($data['username']));
     if ($check_username) {
         $response->setStatusCode(400);
         $response->setContent($this->app->trans('USERNAME_TAKEN'));
         return $response;
     }
     $check_email = $this->app['db']->fetchColumn('SELECT email FROM users WHERE email=? LIMIT 1', array($data['email']));
     if ($check_email) {
         $response->setStatusCode(400);
         $response->setContent($this->app->trans('EMAIL_REGISTERED'));
         return $response;
     }
     $hashed = $this->hash($this->app['defaults']['salt'] . $data['password']);
     $default_group = $this->app['db']->fetchColumn('SELECT id FROM groups WHERE `default`=1 LIMIT 1');
     $insert = $this->app['db']->insert('users', array('username' => $data['username'], 'password' => $hashed, 'email' => $data['email'], 'ip' => $_SERVER['REMOTE_ADDR'], 'perm_group' => $default_group, 'regdate' => time(), 'lastActive' => time()));
     if (!$insert) {
         $response->setStatusCode(500);
         $response->setContent($this->app->trans('UNKNOWN_ERROR'));
         return $response;
     }
     $user_id = $this->app['db']->lastInsertId();
     $this->app['db']->insert('profiles', array('id' => $user_id));
     if ($this->app['board']['confirmEmail']) {
         \ASF\Mailer::setTemplate('emailConfirmation', array('username' => $data['username'], 'boardTitle' => $this->app['board']['name'], 'boardUrl' => $this->app['board']['url'], 'confirmCode' => base64_encode($data['email'] . '-' . $user_id)));
         \ASF\Mailer::send($data['email'], $this->app['email']['noReply'], 'Email confirmation');
         $response->setStatusCode(200);
         $response->setContent($this->app->trans('ACCOUNT_CREATED_CONFIRM_EMAIL'));
     } else {
         $response->setStatusCode(200);
         $resopnse->setContent($this->app->trans('ACCOUNT_CREATED'));
     }
     return $response;
 }
예제 #2
0
 public function testCompile()
 {
     \ASF\Mailer::setTemplate('test', array('name' => 'Carl'));
     \ASF\Mailer::compile();
     $this->assertEquals(\ASF\Mailer::$template, 'Carl');
 }