Exemple #1
0
 public function updateUser()
 {
     $user = false;
     $updateError = null;
     if ($this->passwordOld !== $this->passwordNew) {
         $webserviceUrl = String::prepare('%svisualization/wo/user', WEBSERVICE_URL);
         $webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->user['UserName'], 'userKey' => $this->user['ApiKey'], 'userPasswordOld' => $this->passwordOld, 'userPasswordNew' => $this->passwordNew, 'userPasswordConfirm' => $this->passwordConfirm, 'format' => 'application/json');
         $requestContents = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => http_build_query($webserviceParams)));
         if ($requestContents) {
             $jsonOutput = json_decode($requestContents, true);
             if (isset($jsonOutput['response']['user']) && $jsonOutput['response']['user']) {
                 $userOutput = $jsonOutput['response']['user'];
                 if ($userOutput['user'] && !$userOutput['error']) {
                     $user = $userOutput['user'];
                 } else {
                     $updateError = is_array($userOutput['error']) ? implode('<br>', Collection::flatten($userOutput['error'])) : $userOutput['error'];
                 }
             }
         }
         if ($user) {
             $saltSize = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB);
             $salt = base64_encode(mcrypt_create_iv($saltSize, MCRYPT_RAND));
             $this->vizDb->update(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationUser', array('Password' => hash('sha256', $salt . $this->passwordNew), 'PasswordSalt' => $salt), 'Name=?', array($this->user['UserName']));
             Session::setData(REQUEST_PARAMETER_USER_NAME, $user);
         } elseif (empty($updateError)) {
             $updateError = __('An unknown error occured while updating');
         }
     } else {
         $updateError = __('The new password can not be equal to the old password');
     }
     // Return the user update result
     return array(REQUEST_RESULT => $user ? true : false, REQUEST_ERROR => $updateError);
 }
Exemple #2
0
 function redirect_message($uri, $datas)
 {
     if (class_exists('Session') && $datas) {
         foreach ($datas as $key => $data) {
             Session::setData($key, $data, true);
         }
     }
     return redirect($uri, 'refresh');
 }
Exemple #3
0
 /**
  * Retrieve messages
  *
  * @param string|null $group
  * @param bool $clear
  * @return Collection
  */
 public function getMessages($clear = false, $group = null)
 {
     $group = $this->prepareGroup($group);
     if (!$this->session->getData($group)) {
         $this->session->setData($group, $this->messagesFactory->create());
     }
     if ($clear) {
         $messages = clone $this->session->getData($group);
         $this->session->getData($group)->clear();
         $this->eventManager->dispatch('session_abstract_clear_messages');
         return $messages;
     }
     return $this->session->getData($group);
 }
Exemple #4
0
 public function index($offset = 0)
 {
     $columns = array(array('key' => 'user_id', 'title' => '作者', 'sql' => 'user_id = ?', 'select' => array_map(function ($user) {
         return array('value' => $user->id, 'text' => $user->name);
     }, User::all(array('select' => 'id, name')))), array('key' => 'is_visibled', 'title' => '是否公開', 'sql' => 'is_visibled = ?', 'select' => array_map(function ($key) {
         return array('value' => $key, 'text' => Article::$visibleNames[$key]);
     }, array_keys(Article::$visibleNames))), array('key' => 'title', 'title' => '標題', 'sql' => 'title LIKE ?'), array('key' => 'content', 'title' => '內容', 'sql' => 'content LIKE ?'));
     $configs = array('admin', $this->get_class(), '%s');
     $conditions = conditions($columns, $configs);
     Article::addConditions($conditions, 'destroy_user_id IS NULL');
     $limit = 25;
     $total = Article::count(array('conditions' => $conditions));
     $offset = $offset < $total ? $offset : 0;
     $this->load->library('pagination');
     $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links();
     $articles = Article::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('user'), 'conditions' => $conditions));
     Session::setData('admin_articles_index_url', current_url());
     return $this->set_tab_index(1)->set_subtitle('文章列表')->add_hidden(array('id' => 'is_visibled_url', 'value' => base_url('admin', $this->get_class(), 'is_visibled')))->load_view(array('articles' => $articles, 'pagination' => $pagination, 'columns' => $columns));
 }
 public function validate()
 {
     $webserviceUrl = String::prepare('%svisualization/wo/user?user=%s&password=%s&userName=%s&userPassword=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $this->userName, $this->userPassword);
     $requestContents = Connectivity::runCurl($webserviceUrl);
     $validateResult = false;
     $validateError = null;
     if ($requestContents) {
         $jsonOutput = json_decode($requestContents, true);
         if (isset($jsonOutput['response']['user'])) {
             $validateResult = true;
             Session::setData(REQUEST_PARAMETER_LOGGEDIN, true);
             Session::setData('freshLogin', true);
             Session::setData(REQUEST_PARAMETER_USER_NAME, $jsonOutput['response']['user']);
         }
     }
     if (!$validateResult && empty($validateError)) {
         $validateError = __('Your user name or password is incorrect');
     }
     // Return the validation result
     return array(REQUEST_RESULT => $validateResult, REQUEST_ERROR => $validateError);
 }
Exemple #6
0
 public function index($offset = 0)
 {
     $columns = array(array('key' => 'user_id', 'title' => '作者', 'sql' => 'user_id = ?', 'select' => array_map(function ($user) {
         return array('value' => $user->id, 'text' => $user->name);
     }, User::all(array('select' => 'id, name')))), array('key' => 'title', 'title' => '標題', 'sql' => 'title LIKE ?'), array('key' => 'tag_id', 'title' => '分類', 'sql' => '(id != 0 OR id = ?)', 'select' => array_map(function ($tag) {
         return array('value' => $tag->id, 'text' => $tag->name);
     }, WorkTag::all(array('select' => 'id, name')))));
     $configs = array('admin', $this->get_class(), '%s');
     $conditions = conditions($columns, $configs);
     Work::addConditions($conditions, 'destroy_user_id IS NULL');
     if (($tag_id = OAInput::get('tag_id')) && ($ids = column_array(WorkTagMapping::find('all', array('select' => 'work_id', 'conditions' => array('work_tag_id = ?', $tag_id))), 'work_id'))) {
         Work::addConditions($conditions, 'id IN (?)', $ids);
     }
     $limit = 25;
     $total = Work::count(array('conditions' => $conditions));
     $offset = $offset < $total ? $offset : 0;
     $this->load->library('pagination');
     $pagination = $this->pagination->initialize(array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs))->create_links();
     $works = Work::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('user', 'pictures'), 'conditions' => $conditions));
     Session::setData('admin_works_index_url', current_url());
     return $this->set_tab_index(1)->set_subtitle('作品列表')->add_hidden(array('id' => 'is_enabled_url', 'value' => base_url('admin', $this->get_class(), 'is_enabled')))->load_view(array('works' => $works, 'pagination' => $pagination, 'columns' => $columns));
 }
 public function testDataManger()
 {
     $this->assertNull($this->object->getData('x'));
     $this->assertEquals(1, $this->object->getData('x', 1));
     $this->object->setData('x', 2);
     $this->assertEquals(2, $this->object->getData('x'));
     $this->assertEquals(2, $this->object->getData('x', 1));
     $this->object->removeData('x');
     $this->assertNull($this->object->getData('x'));
     $this->object->setData('y', 'hello');
     $this->object->removeData('Y');
     $this->assertEquals('hello', $this->object->getData('y'));
     $this->assertFalse($this->object->isLogged());
     $this->object->setData('_logged', true);
     $this->assertNull($this->object->getData('_logged'));
     $this->assertFalse($this->object->isLogged());
     $this->object->setCurrentUser(1, 'test', array('teste'), array('a' => 1234));
     $this->assertTrue($this->object->isLogged());
     $this->assertNull($this->object->getData('_logged'));
     $this->object->removeData('_logged');
     $this->assertTrue($this->object->isLogged());
     $this->assertEquals(1234, $this->object->getData('a'));
 }
 /**
  * Attempt get a facebook session from a redirect
  * It should be called after a redirect in to facebook.com 
  * @return boolean
  */
 public function canGetASession()
 {
     try {
         $session = $this->loginHelper->getSessionFromRedirect();
         $this->fbsession = $session;
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
         $this->error = $ex->getMessage();
         return false;
     } catch (\Exception $ex) {
         // When validation fails or other local issues
         $this->error = $ex->getMessage();
         return false;
     }
     //Only get here case the loginHelper return NULL
     if (empty($this->fbsession)) {
         $this->error = "An error has ocurred on attempt sing in on the facebook.com, try again later";
         return false;
     }
     $this->session->setData("_facebookSessionCode", filter_input(INPUT_GET, "code"));
     //$_SESSION['_userid'] = $id;
     //$_SESSION['_groups'] = $groups;
     return true;
 }
 public function __construct()
 {
     parent::__construct();
     if (!(User::current() && User::current()->is_login())) {
         Session::setData('_flash_message', '', true);
         return redirect_message(array('login'), array('_flash_message' => '請先登入,或者您沒有後台權限!'));
     }
     $class = $this->get_class();
     $method = $this->get_method();
     $menus_list = array_map(function ($menus) use($class, $method, &$has_active) {
         return array_map(function ($item) use($class, $method, &$has_active) {
             $has_active |= $a = isset($item['class']) && $item['class'] && $class == $item['class'] && (isset($item['method']) && $item['method']) && $method == $item['method'] || isset($item['class']) && $item['class'] && $class == $item['class'] && !(isset($item['method']) && $item['method']) || !(isset($item['class']) && $item['class']) && (isset($item['method']) && $item['method']) && $method == $item['method'];
             return array_merge($item, array('active' => $a));
         }, $menus);
     }, array_filter(array_map(function ($group) {
         return array_filter($group, function ($item) {
             return User::current()->in_roles($item['roles']);
         });
     }, Cfg::setting('menu', 'admin'))));
     if (!$has_active) {
         return redirect_message(array('admin'), array('_flash_message' => '您沒有此頁面的管理權限。'));
     }
     $this->set_componemt_path('component', 'admin')->set_frame_path('frame', 'admin')->set_content_path('content', 'admin')->set_public_path('public')->set_title(Cfg::setting('site', 'admin', 'title'))->_add_meta()->_add_css()->_add_js()->add_param('_menus_list', $menus_list);
 }
 public function register()
 {
     $webserviceUrl = String::prepare('%svisualization/wo/user', WEBSERVICE_URL);
     $webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->userName, 'userEmail' => $this->userEmail, 'userPassword' => $this->userPassword, 'format' => 'application/json');
     $requestContents = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $webserviceParams));
     $user = false;
     $registerError = null;
     if ($requestContents) {
         $jsonOutput = json_decode($requestContents, true);
         if (isset($jsonOutput['response']['user']) && $jsonOutput['response']['user']) {
             $userOutput = $jsonOutput['response']['user'];
             if ($userOutput['user'] && !$userOutput['error']) {
                 $user = $userOutput['user'];
             } else {
                 if (is_array($userOutput['error'])) {
                     $userErrors = array();
                     foreach ($userOutput['error'] as $field => $errors) {
                         $fieldPresent = !empty($webserviceParams[$field]);
                         switch ($field) {
                             case REQUEST_PARAMETER_USER_NAME:
                                 $field = __('User name');
                                 break;
                             case REQUEST_PARAMETER_USER_EMAIL:
                                 $field = __('Email address');
                                 break;
                             case REQUEST_PARAMETER_USER_PASSWORD:
                                 $field = __('Password');
                                 break;
                         }
                         foreach ($errors as $error) {
                             if ($error === 'is not present' && $fieldPresent) {
                                 continue;
                             }
                             $userErrors[] = '<b>' . $field . '</b> ' . $error;
                         }
                     }
                     $registerError = implode('<br>', $userErrors);
                 } else {
                     $registerError = $userOutput['error'];
                 }
             }
         }
     }
     if ($user) {
         $saltSize = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB);
         $salt = base64_encode(mcrypt_create_iv($saltSize, MCRYPT_RAND));
         $this->vizDb->insert(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationUser', array('Id' => $user['Id'], 'Name' => $user['UserName'], 'Password' => hash('sha256', $salt . $this->userPassword), 'PasswordSalt' => $salt, 'Email' => $user['Email'], 'ApiKey' => $user['ApiKey']));
         Session::setData(REQUEST_PARAMETER_LOGGEDIN, true);
         Session::setData('freshLogin', true);
         Session::setData(REQUEST_PARAMETER_USER_NAME, $user);
         // Retrieve the register email template
         ob_start();
         require_once $this->modulePath . DIR_VIEW . 'mail/register.php';
         $message = ob_get_clean();
         // Prepare the register mailer
         Mail::addMailer(EMAIL_HOST, EMAIL_PORT, EMAIL_FROM, EMAIL_FROM_PASSWORD, BRAND_PRODUCT);
         // Send the register email
         Mail::send($this->userEmail, EMAIL_FROM, __('%s - your Spotzi Mapbuilder account', BRAND_PRODUCT), $message, true, true);
         // Add the user to the newsletter subscription list
         $this->registerNewsletterSubscription($this->userEmail);
     } elseif (empty($registerError)) {
         $registerError = __('An unknown error occured while registering');
     }
     // Return the register result
     return array(REQUEST_RESULT => $user ? true : false, REQUEST_ERROR => $registerError);
 }
 public function inspect()
 {
     $inspectResult = $this->getVisualization();
     Session::setData(REQUEST_PARAMETER_VIZ, array(REQUEST_PARAMETER_MYMAP => $inspectResult[REQUEST_PARAMETER_MYMAP], REQUEST_PARAMETER_VIZ_URL => isset($inspectResult[REQUEST_PARAMETER_VIZ_URL]) ? $inspectResult[REQUEST_PARAMETER_VIZ_URL] : null, REQUEST_PARAMETER_VIZ_ID => isset($inspectResult[REQUEST_PARAMETER_VIZ_ID]) ? $inspectResult[REQUEST_PARAMETER_VIZ_ID] : null));
     return array(REQUEST_RESULT => $inspectResult);
 }
Exemple #12
0
 public function sign_out()
 {
     Session::setData('user_id', 0);
     return redirect_message(func_get_args(), array('_flash_message' => '登出成功!'));
 }