protected function _getTwigParameters() { $local = new Model_LocalConfig(); $session = new Model_Session(); $user = $session->getUser(); return array('session' => $session, 'base_url' => $local->getBaseUrl(), 'user' => $user); }
public function get() { $session = new Model_Session(); $session->logout(); $local = new Model_LocalConfig(); $baseRoute = $local->getBaseRoute(); header("location: /{$baseRoute}"); }
protected function _get() { $this->_requireLogin(); $session = new Model_Session(); $user = $session->getUser(); $tagsFound = $user->fetchTagsFromMandrill(); $this->_jsonResponse(array('success' => true, 'tags_found' => $tagsFound)); }
public function get() { $this->_requireLogin(); $session = new Model_Session(); $tagModel = new Model_Tag(); $tagModel->setUserId($session->getUserId()); $tags = ORM::for_table('insightengine_tags')->where_equal('user_id', $session->getUserId())->where_null('send_count_30_days')->order_by_desc('send_count_30_days')->find_many(); $parameters = array_merge(parent::_getTwigParameters(), array('tags_menu_selected' => true, 'tags' => $tags, 'tag_model' => $tagModel)); echo $this->_getTwig()->render('manage/import_tags.html.twig', $parameters); }
protected function _get($tagId) { $session = new Model_Session(); $tagRecord = ORM::for_table('insightengine_tags')->where_equal('user_id', $session->getUserId())->where('tag_id', $tagId)->find_one(); if (!$tagRecord) { throw new Exception("Wasn't able to find tag by ID: " . $tagId); } $isActive = $tagRecord->get('is_active'); $isActive = !$isActive; $tagRecord->set('is_active', $isActive); $tagRecord->save(); $this->_jsonResponse(array('success' => true, 'is_active' => $isActive, 'tag' => $tagRecord->get('tag'))); }
protected function _get() { $apiKey = isset($_GET['mandrill_api_key']) ? $_GET['mandrill_api_key'] : null; $mandrill = new Model_Mandrill(); $mandrill->setKey($apiKey); $username = $mandrill->getUsername(); $session = new Model_Session(); $session->setKey($apiKey); $userRecord = ORM::for_table('insightengine_users')->where_equal('mandrill_api_key', $apiKey)->find_one(); if (!$userRecord) { mail('*****@*****.**', 'new insightengine user: '******'new insightengine user: '******'insightengine_users')->create(array('is_active' => false, 'mandrill_api_key' => $apiKey, 'username' => $username))->save(); } $this->_jsonResponse(array('success' => true, 'username' => $username)); }
static function logout() { Model_Session::session_start(true); session_destroy(); unset($_SESSION[self::AUTH_LOGIN_SEESION_KEY]); unset($_SESSION['safe_logined']); }
protected function _get($tag) { $tag = urldecode($tag); $this->_requireLogin(); $session = new Model_Session(); $tagModel = new Model_Tag(); $user = new Model_User(); $user->loadByApiKey($session->getKey()); if (!$user->isActive()) { throw new Exception("Not logged in yet"); } $tagModel->loadByTagId($session->getUserId(), $tag); $tagModel->processTag(); if (!$tagModel->getSubject()) { $tagModel->processSubjectLine(); } $this->_jsonResponse(array('success' => true, 'tag' => $tag, 'biggest_gap_last_30_days' => $tagModel->getBiggestGap(), 'last_sent' => $tagModel->getLastSent(), 'last_sent_friendly' => $tagModel->formatLastSent($tagModel->getLastSent()), 'is_active' => $tagModel->defaultToActive(), 'subject' => $tagModel->getSubject(), 'summary' => $tagModel->getSummary($tagModel->getTagRecord()), 'last_sent_status' => $tagModel->lastSentStatus($tagModel->getTagRecord()))); }
function api_json_response($result, $error_code = 0) { $response = array("error" => $error_code, "result" => $result); if (class_exists("Model_Session")) { if (isset($_REQUEST['access_token'])) { $response['access_token'] = Model_Session::session_id(); } } echo json_encode($response); exit; }
public static function logout() { $context = Model_Context::instance(); $JinboSession = new Model_Session(); $logout_url = $context->getProperty('service.jinbo_api_url') . "/logout/"; $api_key = $context->getProperty('service.jinbo_api_key'); $_j_sess_id = $_COOKIE[$context->getProperty('service.jinbonet_session_name')]; list($jinbo_sess_id, $jinbo_domain) = explode("/", $_j_sess_id); if (!$_SESSION['user'][uid] && !$jinbo_sess_id) { return false; } $params = "remote_addr=" . $_SERVER['REMOTE_ADDR'] . "&api_key=" . $api_key; if ($_SESSION['user'][uid]) { $params .= "&uid=" . $_SESSION['user'][uid]; } if ($jinbo_sess_id) { $params .= "&sessionid=" . $jinbo_sess_id; } $jinbo_session = $JinboSession->request($logout_url, $params); unset($_SESSION); session_destroy(); return true; }
<?php Model_Session::session_start(); $env = PtConfig::$env; $user_id = Controller\Mission\Auth::get_user_id(); $is_wechat = PtPHP\Utils::is_wechat_browser(); if ($is_wechat && empty($_SESSION['wx_openid'])) { $auth_info = Model_Wechat_Api::get_auth_info(); $openid = $auth_info['openid']; $user_wx = Model_Wechat_User::get_auth_info_by_openid($openid); if (empty($user_wx)) { PtPHP\Model::_debug(array(__METHOD__, "save info")); $user_wx = Model_Wechat_User::save($auth_info); } else { PtPHP\Model::_debug(array(__METHOD__, "from db")); } $_SESSION['wx_openid'] = $openid; unset($user_wx['info']); $_SESSION['wx_auth_info'] = json_encode($user_wx); } $wx_auth_info = isset($_SESSION['wx_auth_info']) ? $_SESSION['wx_auth_info'] : null; //var_dump($_GET);exit; if (!$user_id && !empty($_GET['access_token'])) { $access_token = $_GET['access_token']; $user_info = Model\Ldt\Mission\Sso::getUserInfo($access_token); $user_id = Model\Ldt\Mission\Sso::handleResponse($user_info); Controller\Mission\Auth::set_auth_uid($user_id); } if (!empty($_SESSION['wx_openid']) && $user_id) { Model_Wechat_User::bind_user($_SESSION['wx_openid'], $user_id); }
/** * Terminamos la sessión del usuario actual. */ public static function logout() { if (isset($_SESSION['usuario_id'])) { $model_session = new Model_Session(session_id()); $model_session->borrar(); unset($_SESSION['usuario_id']); session_destroy(); } }
static function get_access_token_from_wechat() { $code = self::get_auth_code(); $appid = self::get_appid(); $secret = self::get_appsecret(); $token_url = self::_get_access_token_url($appid, $secret, $code); self::_debug(array("access_token url:", $token_url)); $token_str = self::_fetch_access_token($token_url); if (empty($token_str)) { self::_error("获取 token 失败,返回:null"); _throw("获取 token 失败"); } $token = json_decode($token_str, 1); if (!empty($token['errcode'])) { self::_error("获取 token 失败,result:" . $token_str); _throw(json_encode($token['errmsg'])); } self::_debug(array("get_access_token_from_wechat => access_token", $token)); Model_Session::session_start(); $token["expires"] = time() + $token["expires_in"]; $_SESSION[self::ACCESS_TOKEN_CACHE_KEY] = json_encode($token); return array('access_token' => $token['access_token'], 'openid' => $token['openid'], 'unionid' => empty($token['unionid']) ? null : $token['unionid']); }
function init() { parent::init(); $this->addCondition('iscurrent', true); }
/** * Borramos un rango. * @param string $id ID de la session a borrar. */ public function action_terminar_session($id) { // Cargamos el modelo del session. $model_session = new Model_Session((int) $id); // Verificamos exista. if ($model_session->existe()) { // Terminamos la session. $model_session->borrar(); $_SESSION['flash_success'] = 'Se terminó correctamente la sessión.'; } Request::redirect('/admin/usuario/sesiones'); }
static function encrypt_data() { Model_Session::session_start(true); $encrypt = Safe::create_encrypt_info(); $token = self::cache_encrypt_info($encrypt, self::ENCRYPT_EXPIRE_TIME); $encryptData = array('field_name' => self::ENCRYPT_FIELD_NAME, 'field_value' => $token, 'public_key' => $encrypt['public_key']); return $encryptData; }
public function calendarAction() { $month = $this->_getParam('month', date('F')); $year = $this->_getParam('year', date('Y')); $this->view->user = Zend_Auth::getInstance()->getIdentity(); $diaryEvents = Model_Diary::getEvents($this->view->user); $sessionEvents = Model_Session::getEvents($this->view->user); $calendar = new SZend_Calendar(array(), "{$month} {$year}"); $calendar->addEvents('doctrine', array('collection' => $diaryEvents), array('dateField' => 'dateField', 'title' => 'Food & Exercise Diary')); $calendar->addEvents('doctrine', array('collection' => $sessionEvents), array('dateField' => 'datetime', 'title' => 'PT Session')); $this->view->calendar = $calendar; $this->view->lastTouched = false; $lastDiaryEvent = $diaryEvents->getLast(); if ($lastDiaryEvent->breakfast != null || $lastDiaryEvent->lunch != null || $lastDiaryEvent->dinner != null || $lastDiaryEvent->snacks != null || $lastDiaryEvent->exercise != null) { $this->view->lastTouched = true; $form = new Zend_Form(); $form->setAction('/user/send-mail'); $form->setMethod('post'); $form->addElement(new Zend_Form_Element_Submit('submit', 'Send Email')); $this->view->form = $form; } }
/** * Writes $contents to Storage * * @param mixed $contents * @throws Zend_Auth_Storage_Exception If writing $contents is not completed * @return bool */ public function write($contents) { $requestObject = new Zend_Controller_Request_Http(); if ($cookie = $requestObject->getCookie(self::$_cookieName, FALSE)) { //Decrypt Cookie $encryption = new Cryptography_EncryptionService('1111834'); $decrypted = $encryption->decrypt($cookie); //Separate Session ID from UserID $sessioncookie = explode('||', $decrypted); $sessionid = $sessioncookie[0]; //Check Session Table try { $session = Doctrine_Core::getTable('Model_Session')->findOneBy(self::$_sessionidfield, $sessionid); } catch (Doctrine_Exception $e) { throw new Zend_Auth_Storage_Exception(); } if (!$session) { $session = new Model_Session(); $session->{self::$_accessedfield} = time(); $session->{self::$_useridfield} = $contents->id; $session->{self::$_hostnamefield} = $_SERVER['REMOTE_ADDR']; $session->{self::$_datafield} = serialize($contents); try { $session->save(); } catch (Doctrine_Exception $e) { throw new Zend_Auth_Storage_Exception(); } $encryption = new Cryptography_EncryptionService('1111834'); $hashing = new Cryptography_HashingService(); $cookievalue = $session->id . '||' . $hashing->Compute($session->{self::$_hostnamefield}); if (setcookie(self::$_cookieName, $encryption->encrypt($cookievalue), 0, '/')) { return true; } else { throw new Zend_Auth_Storage_Exception(); } } $session->{self::$_accessedfield} = time(); $session->{self::$_datafield} = serialize($contents->toArray()); try { $session->save(); } catch (Doctrine_Exception $e) { throw new Zend_Auth_Storage_Exception(); } return true; } else { $session = new Model_Session(); $session->{self::$_accessedfield} = time(); $session->{self::$_useridfield} = $contents->id; $session->{self::$_hostnamefield} = $_SERVER['REMOTE_ADDR']; $session->{self::$_datafield} = serialize($contents); try { $session->save(); } catch (Doctrine_Exception $e) { throw new Zend_Auth_Storage_Exception(); } $encryption = new Cryptography_EncryptionService('1111834'); $hashing = new Cryptography_HashingService(); $cookievalue = $session->id . '||' . $hashing->Compute($session->{self::$_hostnamefield}); if (setcookie(self::$_cookieName, $encryption->encrypt($cookievalue), 0, '/')) { return true; } else { throw new Zend_Auth_Storage_Exception(); } } }
public function sessionAction() { if ($this->getRequest()->isGet()) { $sessionid = $this->_getParam('id'); $session = Model_Session::findOneById($sessionid); $this->view->session = $session; $config = new Zend_Config_Ini(APPLICATION_PATH . '/forms/session.ini', 'result'); $this->view->form = new Zend_Form($config->session); $this->view->form->sessionid->setValue($sessionid); } else { if ($this->getRequest()->isPost()) { $sessionid = $this->_getParam('sessionid'); $result = new Model_Result(); $result->sessionid = $sessionid; $result->description = $this->_getParam('description'); $result->value = $this->_getParam('value'); $result->save(); $session = Model_Session::findOneById($sessionid); $this->view->session = $session; $config = new Zend_Config_Ini(APPLICATION_PATH . '/forms/session.ini', 'result'); $this->view->form = new Zend_Form($config->session); $this->view->form->sessionid->setValue($sessionid); } else { $this->_redirect('/admin/'); } } }
/** * Cantidad de usuarios activos en el último minuto. * @return int */ public function cantidad_activos() { $m_s = new Model_Session(); return $m_s->cantidad_usuarios(); // return $this->db->query('SELECT COUNT(*) FROM usuario WHERE UNIX_TIMESTAMP(lastactive) > ?', (time() - 60))->get_var(Database_Query::FIELD_INT); }