예제 #1
0
 public function post_signIn()
 {
     Header::json();
     $email = $this->request->post('email', FILTER_VALIDATE_EMAIL);
     $password = $this->request->post('password');
     $rememberEmail = $this->request->post('remember_email', FILTER_VALIDATE_BOOLEAN);
     if (!$email || !$password) {
         die('{ "ok" : false, "msg" : "Invalid login" }');
     }
     try {
         $user = $this->orm->support_user();
         $user->select('id_support_user, name, sex');
         $user->where('email', $email);
         $user->and('password', md5($password));
         $user->and('active', 1);
         $row = $user->fetch();
         if ($row) {
             $row->update(array('online' => 0, 'last_activity' => new NotORM_Literal('NOW()')));
             unset($_SESSION['client_user']);
             $_SESSION['support_user'] = array('id_user' => $row['id_support_user'], 'name' => $row['name'], 'sex' => $row['sex']);
             if ($rememberEmail) {
                 $timeCookie = time() + 60 * 60 * 24 * 20;
                 # 20 days
                 setcookie('email', $email, $timeCookie, null, $_SERVER['HTTP_HOST']);
             } else {
                 $timeCookie = time() - 60 * 60 * 24;
                 # Delete
                 setcookie('email', $email, $timeCookie, null, $_SERVER['HTTP_HOST']);
             }
             print '{ "ok" : true }';
         } else {
             print '{ "ok" : false, "msg" : "Invalid login" }';
         }
     } catch (Exception $e) {
         print '{ "ok" : false, "msg" : "Error occurred" }';
     }
 }
예제 #2
0
 public function post_editUser()
 {
     Header::json();
     try {
         $idSupportUser = $this->request->post('id_support_user', FILTER_VALIDATE_INT);
         $name = $this->request->post('name');
         $email = $this->request->post('email', FILTER_VALIDATE_EMAIL);
         $sex = $this->request->post('sex');
         $password = $this->request->post('password');
         $active = $this->request->post('active', FILTER_VALIDATE_BOOLEAN);
         $accessMaintainUser = $this->request->post('access_maintain_user', FILTER_VALIDATE_BOOLEAN);
         $accessSupportStatus = $this->request->post('access_support_status', FILTER_VALIDATE_BOOLEAN);
         # Check whether the e-mail already exists
         # ------------------------------------------------------------------
         $supportUser = $this->orm->support_user();
         $supportUser->where('email', $email);
         $supportUser->and('id_support_user <> ?', $idSupportUser);
         if ($supportUser->count('*') > 0) {
             exit('{ "ok" : false, "msg" : "E-mail already exists" }');
         }
         $this->orm->transaction = 'begin';
         $this->orm->support_user[$idSupportUser]->update(array('name' => $name, 'email' => $email, 'sex' => $sex, 'password' => empty($password) ? new NotORM_Literal('password') : md5($password), 'active' => $active));
         $this->orm->support_user_access()->where('id_support_user', $idSupportUser)->update(array('maintain_user' => $accessMaintainUser, 'support_status' => $accessSupportStatus));
         $this->orm->transaction = 'commit';
         print '{ "ok" : true }';
     } catch (Exception $e) {
         print '{ "ok" : false, "msg" : "Error occurred" }';
     }
 }
예제 #3
0
 public function post_evaluateSupport()
 {
     Header::json();
     try {
         $rate = $this->request->post('rate', FILTER_VALIDATE_INT);
         $this->orm->chat[$_SESSION['chat_evaluate']['id_chat']]->update(array('rate' => $rate));
         unset($_SESSION['chat_evaluate']);
         print '{ "ok" : true }';
     } catch (Exception $e) {
         print '{ "ok" : false, "msg" : "Error occurred" }';
     }
 }
예제 #4
0
 public function post_information()
 {
     Header::json();
     try {
         $email = $this->request->post('email', FILTER_VALIDATE_EMAIL);
         $clientUser = $this->orm->client_user();
         $clientUser->select('name, sex');
         $clientUser->where('email', $email);
         $clientUser = $clientUser->fetch();
         if (!$clientUser) {
             exit('{ "ok" : false }');
         }
         print json_encode(array('ok' => true, 'name' => $clientUser['name'], 'sex' => $clientUser['sex']));
     } catch (Exception $e) {
         print '{ "ok" : false }';
     }
 }
예제 #5
0
 public function post_checkSupportInactivity()
 {
     Header::json();
     try {
         $timeLimit = $this->orm->param[array('name' => 'SET_OFFLINE_IN')]['value'];
         $supportUser = $this->orm->support_user();
         $supportUser->where('online', 1);
         $supportUser->and('TIMESTAMPDIFF(MINUTE, last_activity, NOW()) > ?', $timeLimit);
         $supportUser->update(array('typing' => 0, 'online' => 0));
         print '{ "ok" : true }';
     } catch (Exception $e) {
         print '{ "ok" : false }';
     }
 }