Ejemplo n.º 1
0
 /**
  * 向用户表表注册新用户
  *
  * @param string $username     用户名
  * @param string $password     密码
  * @param string $hashMethod   密码散列方式
  * @param int    $active       用户激活状态
  * @param string $regDate      注册日期
  * @param string $regIp        注册IP地址
  * @throws ResourceException
  */
 public function postUserAction($username, $password, $hashMethod, $active, $regDate, $regIp)
 {
     $user = Users::findFirst(array('username = ?0', 'bind' => array($username)));
     if ($user) {
         throw new ResourceException('Conflict', 409);
     }
     $password = Hash::rich_hash($password, $hashMethod);
     $user = new Users();
     $user->username = $this->validation->validate('username', $username);
     $user->password = $this->validation->validate('password', $password);
     $user->hash_method = $hashMethod;
     $user->active = $active;
     $user->reg_date = $regDate;
     $user->reg_ip = $this->validation->validate('ipv4', $regIp);
     $user->last_login_date = '';
     $user->last_login_ip = '';
     if ($user->create()) {
         $this->response(201, 'Created', array('UID' => $user->UID));
         $this->response->setHeader('Location', 'user/' . $user->UID);
     } else {
         throw new ResourceException('Internal Server Error', 500);
     }
 }