Exemplo n.º 1
0
 public function indexAction()
 {
     $user = $this->get('user');
     $appSettings = $this->get('config')->data['appSettings'];
     if ($user->hasRole('ADMIN')) {
         $userData = $user->getData();
     } else {
         $userEntry = UserModel::repo()->find($user->getId());
         $userData = $userEntry->getData();
     }
     return $this->render('admin/index.html', array('userData' => json_encode($userData), 'installed' => $appSettings['installed'], 'installStatus' => json_encode($this->getInstallStatus()), 'messageSound' => $appSettings['messageSound'], 'defaultAvatars' => json_encode($this->getDefaultAvatars()), 'messageSounds' => $this->getMessageSounds(), 'widgetThemes' => $this->getWidgetThemes()));
 }
Exemplo n.º 2
0
 public function getTypingStatusAction()
 {
     $request = $this->get('request');
     $userId = $this->get('guest')->getId();
     $userIds = $request->postVar('ids');
     if ($userId) {
         if (is_array($userIds)) {
             $results = array();
             foreach ($userIds as $id) {
                 $results[$id] = UserModel::repo()->getTypingStatus($userId, $id);
             }
             return $this->json(array('success' => true, 'results' => $results));
         }
     }
     return $this->json(array('success' => false));
 }
Exemplo n.º 3
0
 public function validateDb()
 {
     $errors = array('message' => 'Database structure is invalid');
     try {
         $db = $this->get('db');
         // Reconnect in case the database was created just now
         $db->reconnect();
         $tables = $db->getTables();
         $expectedTables = array(UserModel::repo()->getTableName(), MessageModel::repo()->getTableName(), DataModel::repo('')->getTableName());
     } catch (Exception $ex) {
         $errors['message'] = 'Database exception: ' . $ex->getMessage();
         return $errors;
     }
     if (count(array_diff($expectedTables, $tables)) !== 0) {
         $errors['message'] = 'Invalid table structure, actual tables: ' . join(', ', $tables) . ', expected tables: ' . join(', ', $expectedTables);
         return $errors;
     }
     return array();
 }
Exemplo n.º 4
0
 public function loginAction()
 {
     $security = $this->get('security');
     $request = $this->get('request');
     $config = $this->get('config');
     // Redirect if already logged in
     if ($this->get('user')->getId()) {
         return $this->redirect('Admin:index');
     }
     $errors = false;
     $username = '';
     if ($request->isPost()) {
         // Get credentials
         $username = $security->escapeString($request->postVar('name'));
         $password = $security->encodePassword($request->postVar('password'));
         // Check if user exists and passwords match
         $userToken = null;
         if ($username == $config->data['superUser'] && $password == $security->encodePassword($config->data['superPass'])) {
             // Super user
             $userToken = array('id' => '-1', 'name' => 'admin', 'roles' => array('ADMIN'));
         } else {
             $userEntry = UserModel::repo()->findOneBy(array('mail' => $username, 'roles' => array('LIKE', '%OPERATOR%')));
             if (isset($userEntry->password)) {
                 if ($password == $userEntry->password) {
                     $userToken = array('id' => $userEntry->id, 'name' => $userEntry->name, 'roles' => $userEntry->roles);
                 }
             }
         }
         // Store user's identity in the session
         if ($userToken) {
             $this->get('auth')->setUser($userToken['id'], $userToken['name'], $userToken['roles']);
             // Redirect to admin's panel
             return $this->redirect('Admin:index');
         }
         $errors = true;
     }
     return $this->render('admin/login.html', array('name' => $username, 'errors' => $errors));
 }
 public function loginAction()
 {
     $security = $this->get('security');
     $request = $this->get('request');
     $config = $this->get('config');
     $logger = $this->get('logger');
     // Redirect if already logged in
     if ($this->get('user')->getId()) {
         return $this->redirect('Admin:index');
     }
     // Log in automatically if administrator user has no password (true only at first use/installation)
     $appSettings = $config->data['appSettings'];
     if (empty($appSettings['installed']) && empty($config->data['superPass'])) {
         $userToken = array('id' => '-1', 'name' => $config->data['superUser'], 'roles' => array('ADMIN'));
         $this->get('auth')->setUser($userToken['id'], $userToken['name'], $userToken['roles']);
         // Redirect to admin's panel
         return $this->redirect('Install:index');
     }
     $errors = false;
     $username = '';
     if ($request->isPost()) {
         // Get credentials
         $username = $security->escapeString($request->postVar('name'));
         $password = $security->encodePassword($request->postVar('password'));
         // Check if user exists and passwords match
         $userToken = null;
         if ($username == $config->data['superUser'] && $password == $security->encodePassword($config->data['superPass'])) {
             // Super user
             $userToken = array('id' => '-1', 'name' => $config->data['superUser'], 'roles' => array('ADMIN'));
         } else {
             $userEntry = UserModel::repo()->findOneBy(array('mail' => $username, 'roles' => array('LIKE', '%OPERATOR%')));
             if (isset($userEntry->password)) {
                 if ($password == $userEntry->password) {
                     $userToken = array('id' => $userEntry->id, 'name' => $userEntry->name, 'roles' => $userEntry->roles);
                 }
             }
         }
         // Store user's identity in the session
         if ($userToken) {
             $this->get('auth')->setUser($userToken['id'], $userToken['name'], $userToken['roles']);
             // Log
             $logger->info('Successful login, user: '******'s panel
             return $this->redirect('Admin:index');
         }
         $errors = true;
         // Log
         $logger->info('Failed login, user: '******'admin/login.html', array('name' => $username, 'errors' => $errors));
 }
 public function getOnlineUsersAction()
 {
     return $this->json(array('success' => true, 'users' => UserModel::repo()->getAllOnline()));
 }
Exemplo n.º 7
0
 public function archiveOutdatedMessages()
 {
     // Mark messages from offline guests as read
     self::$db->query('UPDATE ' . $this->getTableName() . ' m INNER JOIN ' . UserModel::repo()->getTableName() . ' u ON m.from_id = u.id ' . 'SET m.is_new = "n" WHERE u.last_activity < "' . date('Y-m-d H:i:s', time() - UserModel::GUEST_SESSION_TIME) . '"');
 }
Exemplo n.º 8
0
 public function sendAction()
 {
     $request = $this->get('request');
     $validators = $this->get('model_validation');
     // Get the input
     $from = $this->get('user')->getId();
     $to = $request->postVar('to');
     $body = $request->postVar('body');
     $talkId = 0;
     // Validate the input
     $errors = $validators->validateMessage(array('from' => $from, 'to' => $to, 'body' => $body));
     if (count($errors) === 0) {
         // Get the users data (to_user_info is initially set to broadcast info)
         $fromUser = UserModel::repo()->find($from);
         $toUser = UserModel::repo()->find($to);
         if (empty($fromUser) || empty($toUser)) {
             return $this->json(array('success' => false));
         }
         // Create the message
         $msg = new MessageModel(array('from_id' => $from, 'to_id' => $to, 'body' => $body, 'talk_id' => $talkId, 'from_user_info' => $fromUser->getData(), 'to_user_info' => $toUser->getData()));
         $msg->save();
         // Return a successful response
         return $this->json(array('success' => true, 'to' => $to, 'message' => $msg));
     }
     // Return an error response
     return $this->json(array('success' => false, 'errors' => $errors));
 }
Exemplo n.º 9
0
 public function countGuestsOnline()
 {
     $users = UserModel::repo()->findBy(array('roles' => array('LIKE', '%GUEST%')));
     $count = 0;
     if ($users) {
         foreach ($users as $user) {
             $lastActivityTime = strtotime($user->last_activity);
             if (time() - $lastActivityTime <= self::ONLINE_TIME) {
                 $count++;
             }
         }
     }
     return $count;
 }