예제 #1
0
 protected function _login()
 {
     $name = Dura::post('name');
     $icon = Dura::post('icon');
     $language = Dura::post('language');
     $name = trim($name);
     $icon = trim($icon);
     $language = trim($language);
     if ($name === '') {
         throw new Exception(t("Please input name."));
     }
     if (mb_strlen($name) > 10) {
         throw new Exception(t("Name should be less than 10 letters."));
     }
     $token = Dura::post('token');
     if (!Dura_Class_Ticket::check($token)) {
         throw new Exception(t("Login error happened."));
     }
     if (!isset($this->icons[$icon])) {
         $icons = array_keys($this->icons);
         $icon = reset($icons);
     }
     $user =& Dura_Class_User::getInstance();
     $user->login($name, $icon, $language);
     Dura_Class_Ticket::destory();
     Dura::redirect('lounge');
 }
예제 #2
0
 protected function _message()
 {
     $message = Dura::post('message');
     $message = trim($message);
     $messageId = md5(microtime() . mt_rand());
     if (!$message) {
         return;
     }
     foreach ($this->roomModels as $roomId => $roomModel) {
         $talk = $roomModel->addChild('talks');
         $talk->addChild('id', $messageId);
         $talk->addChild('uid', Dura::user()->getId());
         $talk->addChild('name', Dura::user()->getName());
         $talk->addChild('message', $message);
         $talk->addChild('icon', Dura::user()->getIcon());
         $talk->addChild('time', time());
         $id = Dura::user()->getId();
         foreach ($roomModel->users as $user) {
             if ($id == (string) $user->id) {
                 $user->update = time();
             }
         }
         while (count($roomModel->talks) > DURA_LOG_LIMIT) {
             unset($roomModel->talks[0]);
         }
         $this->roomHandler->save($roomId, $roomModel);
     }
     Dura::redirect('admin_announce');
 }
예제 #3
0
 protected function _login()
 {
     $name = Dura::post('name');
     $pass = Dura::post('pass');
     $name = trim($name);
     $pass = trim($pass);
     if ($name === '') {
         throw new Exception(t("Please input name."));
     }
     $token = Dura::post('token');
     if (!Dura_Class_Ticket::check($token)) {
         throw new Exception(t("Login error happened."));
     }
     if ($name !== DURA_ADMIN_NAME or $pass !== DURA_ADMIN_PASS) {
         throw new Exception(t("ID or password is wrong."));
     }
     $user =& Dura_Class_User::getInstance();
     $user->login($name, 'admin', DURA_LANGUAGE, true);
     Dura_Class_Ticket::destory();
     Dura::redirect('lounge');
 }
예제 #4
0
 protected function _createRoom()
 {
     $userName = Dura::user()->getName();
     $userId = Dura::user()->getId();
     $userIcon = Dura::user()->getIcon();
     $roomHandler = new Dura_Model_RoomHandler();
     $roomModel = $roomHandler->create();
     $roomModel->name = $this->input['name'];
     $roomModel->update = time();
     $roomModel->limit = $this->input['limit'];
     $roomModel->host = $userId;
     $roomModel->language = $this->input['language'];
     $users = $roomModel->addChild('users');
     $users->addChild('name', $userName);
     $users->addChild('id', $userId);
     $users->addChild('icon', $userIcon);
     $users->addChild('update', time());
     if (Dura::$language != $this->input['language']) {
         $langFile = DURA_TRUST_PATH . '/language/' . $this->input['language'] . '.php';
         Dura::$catalog = (require $langFile);
     }
     $talk = $roomModel->addChild('talks');
     $talk->addChild('id', md5(microtime() . mt_rand()));
     $talk->addChild('uid', 0);
     $talk->addChild('name', $userName);
     $talk->addChild('message', "{1} logged in.");
     $talk->addChild('icon', '');
     $talk->addChild('time', time());
     $id = md5(microtime() . mt_rand());
     if (!$roomHandler->save($id, $roomModel)) {
         throw new Exception(t("Data Error: Room creating failed."));
     }
     Dura_Class_RoomSession::create($id);
     Dura::redirect('room');
 }
예제 #5
0
 protected function _validateAdmin()
 {
     if (!Dura::user()->isAdmin()) {
         Dura::redirect();
     }
 }
예제 #6
0
 protected function _redirectToRoom()
 {
     if (Dura_Class_RoomSession::isCreated()) {
         Dura::redirect('room');
     }
 }
예제 #7
0
 protected function _default()
 {
     session_destroy();
     Dura::redirect();
 }
예제 #8
0
 protected function _message()
 {
     $message = Dura::post('message');
     $message = preg_replace('/^[  ]*(.*?)[  ]*$/u', '$1', $message);
     $message = trim($message);
     if (!$message) {
         return;
     }
     if (mb_strlen($message) > DURA_MESSAGE_MAX_LENGTH) {
         $message = mb_substr($message, 0, DURA_MESSAGE_MAX_LENGTH) . '...';
     }
     $talk = $this->roomModel->addChild('talks');
     $talk->addChild('id', md5(microtime() . mt_rand()));
     $talk->addChild('uid', Dura::user()->getId());
     $talk->addChild('name', Dura::user()->getName());
     $talk->addChild('message', $message);
     $talk->addChild('icon', Dura::user()->getIcon());
     $talk->addChild('time', time());
     $id = Dura::user()->getId();
     foreach ($this->roomModel->users as $user) {
         if ($id == (string) $user->id) {
             $user->update = time();
         }
     }
     while (count($this->roomModel->talks) > DURA_LOG_LIMIT) {
         unset($this->roomModel->talks[0]);
     }
     $this->roomHandler->save($this->id, $this->roomModel);
     if (Dura::get('ajax')) {
         die;
     }
     // TODO
     Dura::redirect('room');
 }