コード例 #1
0
ファイル: class.visitor.php プロジェクト: kapai69/fl-ru-damp
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
コード例 #2
0
ファイル: roles.php プロジェクト: netbiel/core
 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     if (!Visitor::instance()->logged_in('admin')) {
         throw new Permission_Exception(new Model_Role());
     }
 }
コード例 #3
0
 static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new Visitor();
     }
     return self::$instance;
 }
コード例 #4
0
ファイル: tags.php プロジェクト: netbiel/core
 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     if (!Visitor::instance()->logged_in('admin')) {
         throw new Permission_Exception(new Model_Tag());
     }
     $this->page_title = __('Tags');
 }
コード例 #5
0
ファイル: tags.php プロジェクト: anqh/anqh
 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     if (!Visitor::instance()->logged_in('admin')) {
         throw new Permission_Exception(new Model_Tag());
     }
     $this->view = View_Page::factory(__('Tags'));
 }
コード例 #6
0
ファイル: exception.php プロジェクト: anqh/anqh
 /**
  * Get a single line of text representing the exception:
  *
  * Error [ Code ]: Message ~ File [ Line ] (#id: username, ip: IP, uri: URI)
  *
  * @param   Exception   $e
  * @return  string
  */
 public static function text(Exception $e)
 {
     if ($user = Visitor::instance()->get_user()) {
         $user_id = $user->id;
         $username = Text::clean($user->username);
     } else {
         $user_id = 0;
         $username = '';
     }
     return sprintf('%s [ %s ]: %s ~ %s [ %d ] (#%d: %s, ip: %s, uri: %s)', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine(), $user_id, $username, Request::$client_ip, Text::clean(Request::current_uri()));
 }
コード例 #7
0
ファイル: invite_hook.php プロジェクト: anqqa/Anqh
 /**
  * Show invite only page if enabled
  */
 public function login()
 {
     $uri = new URI();
     // Redirect to invite page if not logged or signing in
     if (!in_array($uri->string(), array('invite', 'sign/in')) && strpos($uri->string(), 'sign/up') !== 0 && !Visitor::instance()->logged_in()) {
         // Stop execution if ajax, ie. expired session and trying to do ajax call
         if (request::is_ajax()) {
             exit;
         }
         url::redirect('invite');
     }
 }
コード例 #8
0
ファイル: controller.php プロジェクト: netbiel/core
 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     Cache::$default = 'default';
     // Check if this was an interna request or direct
     $this->internal = $this->request !== Request::instance();
     // Ajax request?
     $this->ajax = Request::$is_ajax;
     // Load current user, null if none
     if (self::$user === false) {
         self::$user = Visitor::instance()->get_user();
     }
 }
コード例 #9
0
ファイル: MY_Kohana_Exception.php プロジェクト: anqqa/Anqh
 /**
  * Handle exception
  *
  * @param  Exception  $e
  */
 public static function handle(Exception $e)
 {
     if ($e instanceof Kohana_404_Exception) {
         if (Kohana::config('site.inviteonly') && !Visitor::instance()->get_user()) {
             // Redirect to invite login if invite only and not logged in
             url::redirect('invite');
         } else {
             if (!headers_sent()) {
                 $e->sendHeaders();
             }
             $page = new Error_Controller();
             $page->_404();
         }
     } else {
         return parent::handle($e);
     }
 }
コード例 #10
0
ファイル: online_hook.php プロジェクト: anqqa/Anqh
 /**
  * Save current user to online cache
  */
 public function online()
 {
     // Skip when signing in/out to avoid strange Fatal error
     if (strpos(URI::instance()->string(), 'sign') === 0) {
         return;
     }
     $user = Visitor::instance()->get_user();
     $online = new Online_User_Model($_SESSION['session_id']);
     if (!$online->loaded()) {
         $online->session_id = $_SESSION['session_id'];
     }
     $online->last_activity = $_SESSION['last_activity'];
     $online->user_id = $user ? $user->id : null;
     try {
         $online->save();
     } catch (ORM_Validation_Exception $e) {
     }
 }
コード例 #11
0
ファイル: base.php プロジェクト: anqh/core
 /**
  * Create new View class.
  */
 public function __construct()
 {
     // Initialize static variables
     if (!self::$_initialized) {
         // Request type
         if (Request::current()->is_ajax()) {
             self::$_request_type = Controller::REQUEST_AJAX;
         } else {
             if (!Request::current()->is_initial()) {
                 self::$_request_type = Controller::REQUEST_INTERNAL;
             }
         }
         // Viewing user
         if (self::$_user = Visitor::instance()->get_user()) {
             self::$_user_id = self::$_user->id;
         }
         self::$_initialized = true;
     }
 }
コード例 #12
0
ファイル: url.php プロジェクト: anqh/anqh
 /**
  * Get URL for user
  *
  * @param   mixed   $user   true for session user
  * @param   string  $action
  * @return  string
  */
 public static function user($user, $action = null)
 {
     static $_visitor;
     if (is_numeric($user) && (int) $user > 0) {
         // User id given
         if ($user = Model_User::find_user($user)) {
             $user = $user->username;
         }
     } else {
         if ($user instanceof Model_User) {
             // Model_User given
             $user = $user->username;
         } else {
             if (is_array($user) && isset($user['username'])) {
                 // Light user array given
                 $user = $user['username'];
             } else {
                 if ($user === true) {
                     // Use session user
                     if ($_visitor === null) {
                         if ($user = Visitor::instance()->get_user()) {
                             $_visitor = $user->username;
                         } else {
                             // No session user available
                             $_visitor = false;
                         }
                     }
                     $user = $_visitor;
                 }
             }
         }
     }
     // Username available
     if (is_string($user)) {
         return Route::url('user', array('username' => urlencode($user), 'action' => $action));
     }
     return null;
 }
コード例 #13
0
ファイル: user.php プロジェクト: anqqa/Anqh
 /**
  * Load one user.
  *
  * @param   mixed  $user  user_id, username, email, User_Model or false for current session
  * @return  User_Model
  */
 public function find_user($id = false)
 {
     static $session = false;
     $user = null;
     $cache = false;
     // Try user models first (User_Model, session)
     if ($id instanceof User_Model) {
         // User_Model
         $user = $id;
     } else {
         if ($id === false) {
             // Current session, fetch only once
             if ($session === false) {
                 $session = Visitor::instance()->get_user();
             }
             $user = $session;
         }
     }
     // Then try others (user_id, email, username_clean)
     if (!$user && $id !== true && !empty($id)) {
         if (is_numeric($id) || empty($id)) {
             $id = (int) $id;
         } else {
             if (valid::email($id)) {
                 $id = mb_strtolower($id);
             } else {
                 $id = utf8::clean($id);
             }
         }
         if (isset(self::$users[$id])) {
             // Found from static cache
             return self::$users[$id];
         } else {
             if ($user = $this->cache->get($this->cache->key('user', $id))) {
                 // Found from cache
                 $user = unserialize($user);
             } else {
                 // Not found from caches, try db
                 if (is_int($id)) {
                     $user = $this->find($id);
                 } else {
                     $user = $this->where(valid::email($id) ? 'email' : 'username_clean', '=', $id)->find();
                 }
                 $cache = true;
             }
         }
     }
     // If user found, add to cache(s)
     if ($user && $user->loaded()) {
         self::$users[$user->id] = self::$users[utf8::clean($user->username)] = self::$users[mb_strtolower($user->email)] = $user;
         if ($cache) {
             $this->cache->set($this->cache->key('user', $user->id), serialize($user), null, self::$cache_max_age);
         }
     }
     return $user;
 }
コード例 #14
0
ファイル: html.php プロジェクト: anqh/anqh
 /**
  * Returns user link
  *
  * @param   mixed   $user
  * @param   string  $nick
  * @param   array   $attributes
  * @param   string  $url         override url
  * @return  string
  */
 public static function user($user, $nick = null, array $attributes = null, $url = null)
 {
     static $viewer = true;
     // Load current user for friend styling
     if ($viewer === true) {
         $viewer = Visitor::instance()->get_user();
     }
     $class = array('user', 'hoverable');
     if (is_array($user) || $user && ($user = Model_User::find_user_light($user))) {
         if ($user) {
             $nick = $user['username'];
             if ($viewer && $viewer->is_friend($user)) {
                 $class[] = 'friend ';
             }
             switch ($user['gender']) {
                 case 'f':
                     $class[] = 'female';
                     break;
                 case 'm':
                     $class[] = 'male';
                     break;
             }
         }
     }
     $class[] = Arr::get($attributes, 'class');
     $attributes['class'] = trim(implode(' ', $class));
     return empty($nick) ? __('Unknown') : HTML::anchor($url ? $url : URL::user($nick), $nick, $attributes);
 }
コード例 #15
0
ファイル: sign.php プロジェクト: anqh/anqh
 /**
  * Register with code
  *
  * @param  Model_Invitation  $invitation
  * @param  array             $external
  * @param  string            $provider
  */
 public function _join(Model_Invitation $invitation = null, array $external = null, $provider = null)
 {
     $user = new Model_User();
     if ($invitation) {
         $user->email = $invitation->email;
     } else {
         if ($external) {
             $user->email = Arr::get($external, 'email');
             $user->name = Arr::get($external, 'name');
             $user->username = Arr::get($external, 'username', $user->name);
             $user->avatar_url = 'https://graph.facebook.com/' . $external['id'] . '/picture';
             $user->picture = 'https://graph.facebook.com/' . $external['id'] . '/picture?type=large';
             if ($location = Arr::get($external, 'location')) {
                 $user->location = $location->name;
                 $user->city_name = $location->name;
             }
             if ($gender = Arr::get($external, 'gender')) {
                 switch ($gender) {
                     case 'male':
                         $user->gender = 'm';
                         break;
                     case 'female':
                         $user->gender = 'f';
                         break;
                 }
             }
             if ($birthday = Arr::get($external, 'birthday')) {
                 $user->dob = $birthday;
             }
         }
     }
     // Handle post
     $errors = array();
     if ($_POST && !Arr::get($_POST, 'signup')) {
         $post = Arr::extract($_POST, array('username', 'password', 'password_confirm'));
         try {
             $user->username = $post['username'];
             $user->password_kohana = $post['password'];
             $user->created = time();
             $user->save();
             // Delete used invitation
             if ($invitation) {
                 $invitation->delete();
             }
             // Connect accounts
             if ($external && $provider) {
                 $consumer = new OAuth2_Consumer($provider);
                 $token = $consumer->get_token();
                 $external_user_id = $external['id'];
                 if ($token && $external_user_id) {
                     $external = new Model_User_External();
                     $external->set_fields(array('token' => $token['access_token'], 'user_id' => $user->id, 'external_user_id' => $external_user_id, 'created' => time(), 'expires' => time() + (int) $token['expires'], 'provider' => $provider));
                     $external->save();
                 }
             }
             // Login user
             $user->add_role('login');
             Visitor::instance()->login($user, $_POST['password']);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $user->password_kohana = $user->password_confirm = null;
             $errors = $e->array->errors('validation');
         }
     }
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_register($user, $errors, $invitation->code));
 }
コード例 #16
0
ファイル: controller.php プロジェクト: anqh/core
 /**
  * Construct controller.
  */
 public function before()
 {
     if ($this->request->is_ajax()) {
         $this->_request_type = self::REQUEST_AJAX;
         $this->ajax = true;
     } else {
         if (!$this->request->is_initial()) {
             $this->_request_type = self::REQUEST_INTERNAL;
             $this->internal = true;
         }
     }
     // Update history?
     $this->history = $this->history && !$this->ajax;
     // Initialize session
     $this->session = Session::instance();
     // Load current user, null if none
     if (self::$user === false) {
         $visitor = Visitor::instance();
         Controller::$user = $visitor->get_user();
         // If still no user, try auto login
         if (!Controller::$user && $visitor->auto_login()) {
             Controller::$user = $visitor->get_user();
         }
         unset($visitor);
     }
     // Update current online user for initial and ajax requests
     if ($this->_request_type !== self::REQUEST_INTERNAL) {
         Model_User_Online::update(self::$user);
     }
     // Open outside links to a new tab/window
     HTML::$windowed_urls = true;
     // Load template
     if ($this->auto_render) {
         $this->page_id = $this->page_id ? $this->page_id : $this->request->controller();
         // Figure out what format the client wants
         $accept_types = Request::accept_type();
         if (isset($accept_types['*/*'])) {
             // All formats accepted
             $accept_types = $this->_accept_formats;
         } else {
             // Only some formats accepted
             $accept_types = Arr::extract($accept_types, array_keys($this->_accept_formats));
             if (!($accept_types = array_filter($accept_types))) {
                 throw new HTTP_Exception_415('Unsupported accept type');
             }
         }
         $this->_response_format = key($accept_types);
     }
 }
コード例 #17
0
ファイル: website.php プロジェクト: anqqa/Anqh
 /**
  * Construct new page controller
  */
 function __construct()
 {
     parent::__construct();
     // Init page values
     $this->country = Session::instance()->get('country', false);
     // AJAX requests output without template
     if (request::is_ajax()) {
         $this->auto_render = false;
         $this->history = false;
         return;
     }
     // Use profiler only when an admin is logged in
     if ($this->visitor->logged_in('admin')) {
         Profiler::enable();
     }
     // Bind the generic page variables
     $this->template->bind('skin', $this->skin)->bind('skin_imports', $this->skin_imports)->bind('stylesheets', $this->stylesheets)->bind('language', $this->language)->bind('page_width', $this->page_width)->bind('page_main', $this->page_main)->bind('page_id', $this->page_id)->bind('page_class', $this->page_class)->bind('page_title', $this->page_title)->bind('page_subtitle', $this->page_subtitle);
     // Add controller name as default page id
     $this->page_id = Router::$controller;
     // Init page values
     $this->menu = Kohana::config('site.menu');
     $skin_path = 'ui/' . Kohana::config('site.skin') . '/';
     $this->skin = $skin_path . 'skin.less';
     $this->skin_imports = array('ui/layout.less', 'ui/widget.less', 'ui/jquery-ui.css', 'ui/site.css', $skin_path . 'jquery-ui.css');
     $this->page_width = Session::instance()->get('page_width', 'fixed');
     $this->page_main = Session::instance()->get('page_main', 'left');
     //$this->stylesheets = array('ui/' . Kohana::config('site.skin') . '/skin', 'ui/' . Kohana::config('site.skin') . '/jquery-ui');
     $this->breadcrumb = array();
     //html::anchor('/', __('Home')));
     $this->tabs = array();
     // If a country is seleced, add custom stylesheet
     if ($this->country && Kohana::config('site.country_css')) {
         widget::add('head', html::stylesheet('ui/' . utf8::strtolower($this->country) . '/skin'));
     }
     // Generic views
     widget::add('actions', View::factory('generic/actions')->bind('actions', $this->page_actions));
     // widget::add('breadcrumb', View::factory('generic/breadcrumb')->bind('breadcrumb', $this->breadcrumb));
     widget::add('navigation', View::factory('generic/navigation')->bind('items', $this->menu)->bind('selected', $this->page_id));
     widget::add('tabs', View::factory('generic/tabs_top')->bind('tabs', $this->tabs)->bind('selected', $this->tab_id));
     // Header
     widget::add('header', View::factory('generic/header'));
     // Footer
     widget::add('footer', View_Mod::factory('events/events_list', array('mod_id' => 'footer-events-new', 'mod_class' => 'article unit size1of4 cut events', 'mod_title' => __('New events'), 'events' => ORM::factory('event')->order_by('id', 'DESC')->find_all(10))));
     widget::add('footer', View_Mod::factory('forum/topics_list', array('mod_id' => 'footer-topics-active', 'mod_class' => 'article unit size1of4 cut topics', 'mod_title' => __('New posts'), 'topics' => ORM::factory('forum_topic')->order_by('last_post_id', 'DESC')->find_all(10))));
     widget::add('footer', View_Mod::factory('blog/entries_list', array('mod_id' => 'footer-blog-entries', 'mod_class' => 'article unit size1of4 cut blogentries', 'mod_title' => __('New blogs'), 'entries' => ORM::factory('blog_entry')->find_latest(10))));
     // Dock
     $classes = array(html::anchor('set/width/narrow', __('Narrow'), array('onclick' => '$("body").addClass("fixed").removeClass("liquid"); $.get(this.href); return false;')), html::anchor('set/width/wide', __('Wide'), array('onclick' => '$("body").addClass("liquid").removeClass("narrow"); $.get(this.href); return false;')), html::anchor('set/main/left', __('Left'), array('onclick' => '$("body").addClass("left").removeClass("right"); $.get(this.href); return false;')), html::anchor('set/main/right', __('Right'), array('onclick' => '$("body").addClass("right").removeClass("left"); $.get(this.href); return false;')));
     widget::add('dock2', __('Layout: ') . implode(', ', $classes));
     // Language selection
     $available_languages = Kohana::config('locale.languages');
     if (count($available_languages)) {
         $languages = array();
         foreach ($available_languages as $lang => $locale) {
             $languages[] = html::anchor('set/lang/' . $lang, html::chars($locale[2]));
         }
         widget::add('dock2', ' | ' . __('Language: ') . implode(', ', $languages));
     }
     if ($this->user) {
         // Authenticated view
         widget::add('dock', __('[#:id] :user', array(':id' => $this->user->id, ':user' => html::nick($this->user->id, $this->user->username))));
         $new_messages = array();
         if ($this->user->newcomments) {
             $new_messages[] = html::anchor(url::user($this->user), __(':commentsC', array(':comments' => $this->user->newcomments)), array('title' => __('New comments'), 'class' => 'new-comments'));
         }
         if (!empty($new_messages)) {
             widget::add('dock', ' - ' . __('New messages: ') . implode(' ', $new_messages));
         }
         // Logout also from Facebook
         if (FB::enabled() && Visitor::instance()->get_provider()) {
             widget::add('dock', ' - ' . html::anchor('sign/out', FB::icon() . __('Sign out'), array('onclick' => "FB.Connect.logoutAndRedirect('/sign/out'); return false;")));
         } else {
             widget::add('dock', ' - ' . html::anchor('sign/out', __('Sign out')));
         }
         if (Kohana::config('site.inviteonly')) {
             //				widget::add('dock', ' | ' . html::anchor('sign/up', __('Send invite')));
         }
         // Admin functions
         if ($this->visitor->logged_in('admin')) {
             widget::add('dock2', ' | ' . __('Admin: ') . html::anchor('roles', __('Roles')) . ', ' . html::anchor('tags', __('Tags')) . ', ' . html::anchor('#kohana-profiler', __('Profiler'), array('onclick' => '$("#kohana-profiler").toggle();')));
         }
     } else {
         // Non-authenticated view
         $form = form::open('sign/in');
         $form .= form::input('username', null, 'title="' . __('Username') . '"');
         $form .= form::password('password', '', 'title="' . __('Password') . '"');
         $form .= form::submit('submit', __('Sign in'));
         $form .= form::close();
         $form .= html::anchor('/sign/up', __('Sign up'));
         if (FB::enabled()) {
             $form .= ' | ' . FB::fbml_login();
         }
         widget::add('dock', $form);
     }
     // End
     widget::add('end', View::factory('generic/end'));
     // Analytics
     $google_analytics = Kohana::config('site.google_analytics');
     if ($google_analytics) {
         widget::add('head', html::script_source("\nvar _gaq = _gaq || []; _gaq.push(['_setAccount', '" . $google_analytics . "']); _gaq.push(['_trackPageview']);\n(function() {\n\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n\t(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);\n})();\n"));
     }
     // Ads
     $ads = Kohana::config('site.ads');
     if ($ads && $ads['enabled']) {
         foreach ($ads['slots'] as $ad => $slot) {
             widget::add($slot, View::factory('ads/' . $ad));
         }
     }
     // Facebook connect
     if (FB::enabled()) {
         FB::init();
     }
 }
コード例 #18
0
ファイル: user.php プロジェクト: netbiel/core
 /**
  * Load one user.
  *
  * @static
  * @param   mixed  $user  id, username, email, Model_User, user array or false for current session
  * @return  Model_User  or null
  */
 public static function find_user($id = false)
 {
     static $session = false;
     $user = null;
     $cache = false;
     // Try user models first (User_Model, session)
     if ($id instanceof Model_User) {
         // Model_User
         $user = $id;
     } else {
         if ($id === false) {
             // Current session, fetch only once
             if ($session === false) {
                 $session = Visitor::instance()->get_user();
             }
             $user = $session;
         }
     }
     // Then try others (user_id, email, username_clean)
     if (!$user && $id !== true && !empty($id)) {
         if (is_numeric($id) || empty($id)) {
             $id = (int) $id;
         } else {
             if (is_array($id)) {
                 $id = (int) $id['id'];
             } else {
                 if (Validate::email($id)) {
                     $id = mb_strtolower($id);
                 } else {
                     $id = Text::clean($id);
                 }
             }
         }
         if (isset(self::$_users[$id])) {
             // Found from static cache
             return self::$_users[$id];
         } else {
             if ($user = Cache::instance()->get_('user_' . $id)) {
                 // Found from cache
                 $user = unserialize($user);
             } else {
                 // Not found from caches, try db
                 if (is_int($id)) {
                     $user = Jelly::select('user', $id);
                 } else {
                     $user = Jelly::select('user')->where(Validate::email($id) ? 'email' : 'username_clean', '=', $id)->limit(1)->execute();
                 }
                 $cache = true;
             }
         }
     }
     // If user found, add to cache(s)
     if ($user && $user->loaded()) {
         self::$_users[$user->id] = self::$_users[Text::clean($user->username)] = self::$_users[mb_strtolower($user->email)] = $user;
         if ($cache) {
             Cache::instance()->set_('user_' . $user->id, serialize($user), 3600);
         }
     } else {
         $user = null;
     }
     return $user;
 }
コード例 #19
0
ファイル: MY_Controller.php プロジェクト: anqqa/Anqh
 /**
  * Template loading and setup routine.
  */
 public function __construct()
 {
     parent::__construct();
     // Get loaded modules
     $this->modules = Kohana_Config::instance()->get('core.modules');
     // Initialize libraries
     $this->cache = Cache::instance();
     $this->input = Input::instance();
     $this->uri = URI::instance();
     $this->visitor = Visitor::instance();
     // Validate CSRF token
     if (isset($_REQUEST['csrf'])) {
         $this->valid_csrf = csrf::valid($_REQUEST['csrf']);
     }
     // Load current user for easy controller access, null if not logged
     $this->user =& $this->visitor->get_user();
     // Build the page
     $this->template = View::factory($this->template);
     // Display the template immediately after the controller method?
     if ($this->auto_render === true) {
         Event::add('system.post_controller', array($this, '_display'));
     }
 }
コード例 #20
0
ファイル: user.php プロジェクト: anqh/anqh
 /**
  * Action: settings
  */
 public function action_settings()
 {
     $this->history = false;
     $user = $this->_get_user();
     Permission::required($user, Model_User::PERMISSION_UPDATE);
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         // Login information
         if ($user->username !== Arr::get($_POST, 'username') || $user->email !== UTF8::strtolower(Arr::get($_POST, 'email')) || Arr::get($_POST, 'password')) {
             $visitor = Visitor::instance();
             $old_password = Arr::get($_POST, 'current_password');
             $new_password = Arr::get($_POST, 'password');
             $validation = Validation::factory(array('current_password' => $old_password));
             $validation->rule('current_password', 'not_empty');
             if (!$visitor->check_password($old_password) && Visitor::generate_password($user->password_kohana) !== $old_password) {
                 $validation->rule('current_password', 'equals', array(':validation', __('current password')));
             } else {
                 if ($new_password) {
                     // Change password only if correct old one given
                     $user->password_kohana = $new_password;
                 }
             }
             $user->username = Arr::get($_POST, 'username');
             $user->email = Arr::get($_POST, 'email');
         }
         $user->set_fields(Arr::intersect($_POST, Model_User::$editable_fields));
         // Settings
         $name_visiblity = Arr::get($_POST, 'name_visibility');
         if (in_array($name_visiblity, array(Model_User::NAME_HIDDEN, Model_User::NAME_VISIBLE))) {
             $user->setting('user.name', $name_visiblity);
         }
         $dob_visiblity = Arr::get($_POST, 'dob_visibility');
         if (in_array($dob_visiblity, array(Model_User::DOB_DATEONLY, Model_User::DOB_HIDDEN, Model_User::DOB_VISIBLE))) {
             $user->setting('user.dob', $dob_visiblity);
         }
         // Clear default image id if Facebook image is set
         if (Arr::get($_POST, 'picture')) {
             $user->default_image_id = null;
         }
         $user->modified = time();
         try {
             $user->save(isset($validation) ? $validation : null);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         }
     }
     // Build page
     $this->view = self::_set_page($user);
     $this->view->add(View_Page::COLUMN_TOP, $this->section_settings($user, $errors));
 }
コード例 #21
0
ファイル: MY_html.php プロジェクト: anqqa/Anqh
 /**
  * Returns user link
  *
  * @param	  mixed   $user  User_Model, uid or username
  * @param	  string  $nick
  * @param   string  $class
  * @return  string
  */
 public static function user($user, $nick = null, $class = null)
 {
     static $viewer;
     // Load current user for friend styling
     if (is_null($viewer)) {
         $viewer = Visitor::instance()->get_user();
         if (!$viewer) {
             $viewer = false;
         }
     }
     $class = $class ? array($class, 'user') : array('user');
     if ($user instanceof User_Model || $user && ($user = ORM::factory('user')->find_user($user))) {
         $nick = $user->username;
         if ($viewer && $viewer->is_friend($user)) {
             $class[] = 'friend';
         }
         if ($user->gender) {
             $class[] = $user->gender == 'f' ? 'female' : 'male';
         }
     }
     return empty($nick) ? __('Unknown') : html::anchor(url::user($nick), $nick, array('class' => implode(' ', $class)));
 }
コード例 #22
0
ファイル: html.php プロジェクト: netbiel/core
 /**
  * Returns user link
  *
  * @param   mixed   $user  Model_User, uid or username
  * @param   string  $nick
  * @param   array   $attributes
  * @return  string
  */
 public static function user($user, $nick = null, array $attributes = null)
 {
     static $viewer = false;
     // Load current user for friend styling
     if ($viewer === false) {
         $viewer = Visitor::instance()->get_user();
     }
     $class = array('user', 'hoverable');
     if ($user instanceof Model_user || $user && ($user = Model_User::find_user($user))) {
         if ($user->loaded()) {
             $nick = $user->username;
             if ($viewer && $viewer->is_friend($user)) {
                 $class[] = 'friend ';
             }
             if ($user->gender) {
                 $class[] = $user->gender == 'f' ? 'female ' : 'male ';
             }
         }
     }
     $class[] = Arr::get($attributes, 'class');
     $attributes['class'] = trim(implode(' ', $class));
     return empty($nick) ? __('Unknown') : HTML::anchor(URL::user($nick), $nick, $attributes);
 }
コード例 #23
0
ファイル: Modeler_ORM.php プロジェクト: anqqa/Anqh
 /**
  * Check if the user is owner of current model, e.g. topic author
  *
  * @param  int|User_Model  $user  current user on null
  */
 public function is_author($user = null)
 {
     // Check if we even have the author id
     if ($this->loaded() && isset($this->table_columns['author_id'])) {
         $author_id = $this->author_id;
     } else {
         return false;
     }
     if (empty($user)) {
         // No user given, use logged in user
         $user = Visitor::instance()->get_user();
         return isset($user->id) && $author_id === $user->id;
     } else {
         if (is_int($user)) {
             // User id given
             return $author_id === $user;
         } else {
             if ($user instanceof User_Model) {
                 // User Model given
                 return $author_id === $user->id;
             }
         }
     }
     return false;
 }
コード例 #24
0
ファイル: Visitor.php プロジェクト: anqqa/Anqh
 /**
  * Log out a user by removing the related session variables.
  *
  * @param   boolean  $destroy  completely destroy the session
  * @return  boolean
  */
 public function logout($destroy = false)
 {
     // Delete the autologin cookie to prevent re-login
     if (cookie::get($this->config['cookie_name'])) {
         cookie::delete($this->config['cookie_name']);
     }
     // Logout 3rd party?
     if (FB::enabled() && Visitor::instance()->get_provider()) {
         $this->session->delete($this->config['session_key'] . '_provider');
         try {
             FB::instance()->expire_session();
         } catch (Exception $e) {
         }
     }
     // Destroy the session completely?
     if ($destroy === true) {
         $this->session->destroy();
     } else {
         // Remove the user from the session
         $this->session->delete($this->config['session_key']);
         // Regenerate session_id
         $this->session->regenerate();
     }
     // Double check
     return !$this->logged_in();
 }
コード例 #25
0
ファイル: sign.php プロジェクト: anqh/core
 /**
  * Register with code
  *
  * @param  Model_Invitation  $invitation
  */
 public function _join(Model_Invitation $invitation)
 {
     $user = new Model_User();
     $user->email = $invitation->email;
     // Handle post
     $errors = array();
     if ($_POST && !Arr::get($_POST, 'signup')) {
         $post = Arr::extract($_POST, array('username', 'password', 'password_confirm'));
         $validation = new Validation($post);
         $validation->rule('password_confirm', 'matches', array(':validation', 'password', 'password_confirm'));
         try {
             $user->username = $post['username'];
             $user->password = $post['password'];
             $user->created = time();
             $user->save($validation);
             // Delete used invitation
             $invitation->delete();
             // Login user
             $user->add_role('login');
             Visitor::instance()->login($user, $_POST['password']);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $user->password = $user->password_confirm = null;
             $errors = $e->array->errors('validation');
         }
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_register($user, $errors, $invitation->code));
 }
コード例 #26
0
ファイル: sign.php プロジェクト: anqqa/Anqh
 /**
  * Sign up
  *
  * @param  string  $code
  */
 public function up($code = false)
 {
     $this->history = false;
     $this->page_title = __('Sign up');
     // Check invitation code
     if ($code) {
         $invitation = new Invitation_Model($code);
         if ($invitation->email) {
             // Valid invitation code found, sign up form
             $this->_join($invitation);
         } else {
             // Invite only hook
             if (Kohana::config('site.inviteonly')) {
                 url::redirect('/');
                 return;
             }
             $this->_invite($code);
         }
         return;
     }
     // Invite only hook
     if (Kohana::config('site.inviteonly') && !Visitor::instance()->logged_in()) {
         url::redirect('/');
         return;
     }
     // Check if we got the code from the form
     if (!$code && request::method() == 'post') {
         $code = $this->input->post('code');
         if ($code) {
             url::redirect('/sign/up/' . $code);
             return;
         }
     }
     $this->_invite();
 }
コード例 #27
0
ファイル: oauth.php プロジェクト: anqh/anqh
 /**
  * Try to login external user.
  *
  * @param   Model_User_External  $external
  * @param   string               $token
  * @return  boolean
  */
 protected function _login(Model_User_External $external = null, $token = null)
 {
     if (!$external) {
         $external = new Model_User_External($token);
     }
     if ($external->loaded() && $external->provider === $this->consumer->get_provider()) {
         return Visitor::instance()->external_login($external);
     }
     return false;
 }