public function __construct() { // -- Set the UserID // ----------------- list($driver, $user_id) = \Auth::get_user_id(); $this->_userID = (int) $user_id; }
/** * before_insert observer event method */ public function _event_before_insert() { // assign the user id that lasted updated this record if (!$this->user_id) { $this->user_id = ($this->user_id = \Auth::get_user_id()) ? $this->user_id[1] : 0; } }
/** * 記事編集フィールドセット * * @access public * @return Fieldsetオブジェクト */ public static function article_edit($id) { $article = \DB::select('*')->from('topics')->where('topic_id', $id)->and_where('type_id', 1)->and_where('id', \Auth::get_user_id()[1])->execute()->as_array(); $image = \DB::select('*')->from('topics_pictures')->where('topic_id', $id)->and_where('response_id', null)->execute()->count(); $form = \Fieldset::forge('article_regist_form'); $form->form()->set_attribute('class', 'form form-horizontal'); $form->add('id', '', array('type' => 'hidden', 'value' => $id))->add_rule('required')->add_rule('valid_string', array('numeric')); $form->add('title', 'タイトル', array('class' => 'form-control', 'required', 'value' => $article[0]['title']))->add_rule('required')->add_rule('min_length', 1)->add_rule('max_length', 100); $form->add('body', '内容', array('type' => 'textarea', 'rows' => 20, 'class' => 'form-control', 'required', 'value' => $article[0]['topic_body']))->add_rule('required')->add_rule('min_length', 2)->add_rule('max_length', 5000); $form->add('image', '画像ファイル', array('type' => 'file')); if ($image > 0) { $form->add('change_image', '', array('type' => 'checkbox', 'value' => 'true', 'options' => array(0 => '保存済みの画像を使用する')))->set_template("<div class=\"form-group\">\n\n\t\t\t\t\t\t\t\t\t\t<div class=\"col-sm-2 control-label\">\n\n\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t<div class=\"col-sm-10 checkbox {error_class}\">\n\t\t\t\t\t\t\t\t\t\t\t<label>\n\t\t\t\t\t\t\t\t\t\t\t\t{fields}\n\n\t\t\t\t\t\t\t\t\t\t\t\t{field}\n\n\t\t\t\t\t\t\t\t\t\t\t\t{fields}\n\t\t\t\t\t\t\t\t\t\t\t\t保存済みの画像を使用する\n\t\t\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t\t\t<span>{description}</span>{error_msg}\n\n\t\t\t\t\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t\t\t\t</div>\n"); } $result = \DB::select('category_id', 'category')->from('categories')->execute()->as_array(); foreach ($result as $item) { $options[$item['category_id']] = $item['category']; } $form->add('category', 'カテゴリー', array('type' => 'select', 'options' => $options, 'class' => 'form-control', 'required', 'value' => $article[0]['category_id']))->add_rule('required'); // $form->add('tag','タグ',array('class'=>'form-control','list'=>'tag-auto','placeholder'=>'例)中華,ランチ')) // ->add_rule('min_length',1) // ->add_rule('max_length',100); $form->add('readonly', '', array('type' => 'checkbox', 'value' => !$article[0]['readonly'], 'options' => array(0 => '')))->set_template("<div class=\"form-group\">\n\n\t\t\t\t\t\t\t<div class=\"col-sm-2 control-label\">\n\t\t\t\t\t\t\t\t<label>\n\t\t\t\t\t\t\t\t\tコメントの可否\n\t\t\t\t\t\t\t\t\t<span class=\"require\">*</span>\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class=\"col-sm-10 checkbox {error_class}\">\n\t\t\t\t\t\t\t\t<label>\n\t\t\t\t\t\t\t\t\t{fields}\n\n\t\t\t\t\t\t\t\t\t{field}\n\n\t\t\t\t\t\t\t\t\t{fields}\n\t\t\t\t\t\t\t\t\t※記事へのコメントを許可しない場合をチェックを外して下さい。\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t<span>{description}</span>{error_msg}\n\n\t\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t</div>\n"); $form->form()->add_csrf(); $form->add('submit', '', array('type' => 'submit', 'value' => '投稿', 'class' => 'btn btn-primary')); return $form; }
public function __construct($referralID = 0) { if ((int) $referralID <= 0) { return; } // -- Set the Referral ID // ---------------------- $this->_referralID = $referralID; //-- Set the database model // ------------------------ Referrals_model::forge($this->_referralID); list($driver, $user_id) = \Auth::get_user_id(); $this->_user_id = $user_id; // -- Load the referral up // ----------------------- $loadResult = $this->load(); // -- Set the Email template location // ---------------------------------- $this->_emailTemplateDir = PKGPATH . 'crm/subpackage/referrals/view/email/'; if (is_null($loadResult)) { return null; } else { return $this; } }
public static function getTypeaheadList($col) { if (Auth::check() === false) { return json_encode(array()); } $user_id = Auth::get_user_id(); $res = DB::select($col)->from('posts')->where('user_id', '=', $user_id[1])->group_by($col)->execute()->as_array(); return json_encode(\Arr::pluck($res, $col)); }
static function log($category, $message) { require_once THRIFT_ROOT . '/Thrift.php'; require_once THRIFT_ROOT . '/protocol/TBinaryProtocol.php'; require_once THRIFT_ROOT . '/transport/TSocket.php'; require_once THRIFT_ROOT . '/transport/TFramedTransport.php'; require_once THRIFT_ROOT . '/packages/scribe/scribe.php'; switch ($category) { case 'general': case 'accounts': case 'actions': case 'status': case 'security': case 'debug': case 'history': case 'regulation': case 'specials': break; default: fatal(); } if (!is_string($message)) { if (is_array($message)) { if (!isset($message['ts'])) { $message['ts'] = time(); } if (!isset($message['client_ip'])) { $message['client_ip'] = Utils::get_client_ip(); } if (!isset($message['user_id']) && Auth::is_logged()) { $message['user_id'] = Auth::get_user_id(); } if (!isset($message['user_name']) && Auth::is_logged()) { $message['user_name'] = Auth::get_user_name(); } $oauth_client_id = Auth::get_oauth_client_id(); if (!isset($message['oauth_client_id']) && !empty($oauth_client_id)) { $message['oauth_client_id'] = $oauth_client_id; } } $message = json_encode($message); } try { $log_entry = new \LogEntry(array('category' => $category, 'message' => $message)); $messages = array($log_entry); $socket = new \TSocket(SCRIBE_HOST, SCRIBE_PORT, FALSE); $transport = new \TFramedTransport($socket); $protocol = new \TBinaryProtocolAccelerated($transport, FALSE, FALSE); $client = new \scribeClient($protocol, $protocol); $transport->open(); $client->send_log($messages); $transport->close(); } catch (\TException $e) { return FALSE; } return TRUE; }
public function before() { parent::before(); // Without this line, templating won't work! if (\Auth::check()) { # Set user info list(, $userid) = \Auth::get_user_id(); $this->template->set_global('auth', ['user' => ['screen_name' => \Auth::get_screen_name(), 'group' => \Auth::group()->get_name()]], false); } }
public function before() { parent::before(); if (Auth::check()) { $user_id = Auth::get_user_id()[1]; $this->user = Model_User::find($user_id); if ($this->user->group_id == 100) { $this->auth_status = true; } } }
/** * Sets the CreatedBy property to the current user id * * @param Model Model object subject of this observer method */ public function before_insert(Orm\Model $obj) { if ($obj instanceof Orm\Model_Temporal) { if ($obj->{$obj->temporal_property('end_column')} !== $obj->temporal_property('max_timestamp')) { return false; } } if ($user_id = \Auth::get_user_id()) { $obj->{$this->_property} = $user_id[1]; } }
public function before() { parent::before(); $this->viewer_info = array(); if (!Auth::check()) { Response::redirect('members'); // login画面に戻る。 } else { $this->viewer_info['name'] = Auth::get_screen_name(); $this->viewer_info['uid'] = Auth::get_user_id(); } }
public function before() { // Lets render the template parent::before(); // Check to see if the config exsists if (file_exists(APPPATH . 'config/production/db.php') === false) { Response::Redirect('install'); } if (DBUtil::field_exists('urls', array('cached_preview')) === false && file_exists(APPPATH . 'classes/controller/upgrade.php')) { Response::Redirect(Uri::Create('upgrade')); } $real_base_url = Config::get('base_url'); Config::set('base_url', str_replace('public/', '', $real_base_url)); $base_url = Settings::get('different_short_url'); if (empty($base_url) === false) { View::set_global(array('base_url' => $base_url), false, false); } if (trim(Uri::Base(), '/') == Settings::get('different_short_url')) { if (count(Uri::Segments()) == 2) { $route = Uri::to_assoc(); if (isset($route) === true && $route['core'] == '404') { // We are good! } else { Response::Redirect(Settings::Get('base_url')); } } else { Response::Redirect(Settings::Get('base_url')); } } $data = null; if (Auth::Check()) { $user_id = Auth::get_user_id(); static::$user_id = $user_id[1]; $data['api_key'] = Auth::get('api_key'); if (empty($data['api_key']) === true) { if (empty($data['api_key']) === true) { $data['api_key'] = preg_replace('/\\+|\\/|\\=|\\?/', '', \Auth::instance()->hash_password(\Str::random()) . static::$user_id); // invalidate the hash \Auth::update_user(array('api_key' => $data['api_key']), Auth::get('username')); } } } // Lets set the default title , you can change it when calling the view $this->template->title = ucwords(str_replace('controller_', '', strtolower($this->request->route->controller))); try { Module::load('image'); $this->template->image_js = true; } catch (Exception $e) { } // Lets get the header and footer and set a variable to use within the template $this->template->footer = View::forge('core/footer', $data); $this->template->header = View::forge('core/header'); }
public function before() { parent::before(); if (!Auth::check()) { return $this->responseJson('nologin', true); } $this->fleamarket = Model_Fleamarket::find(Input::param('fleamarket_id')); if (!$this->fleamarket) { return $this->responseJson('nodata', true); } $this->input = array('user_id' => Auth::get_user_id(), 'fleamarket_id' => Input::param('fleamarket_id')); $this->favorite = Model_Favorite::query()->where($this->input)->get_one(); }
public static function saveCorrespondence($ppiClientID = 0, $claimID = 0, $stageID = 0, $statusID = 0, $dispositionID, $notes = null) { // -- Save a new correspondance // ---------------------------- $result = 0; list($driver, $user_id) = \Auth::get_user_id(); $result = \DB::query("INSERT INTO\n " . static::$crmPpiCorrespondence . "\n (\n id\n ,ppi_client_id\n ,claim_id\n ,stage_id\n ,status_id\n ,user_id\n ,disposition_id\n ,date\n ,notes\n )\n VALUES\n (\n NULL\n ," . (int) $ppiClientID . " \n ," . (int) $claimID . "\n ," . (int) $stageID . "\n ," . (int) $statusID . "\n ," . $user_id . "\n ," . (int) $dispositionID . "\n ,NOW()\n ," . (isset($notes) ? \DB::quote($notes) : "''") . "\n )\n ", \DB::insert())->execute(); if ($result > 0) { return true; } else { return false; } }
public function action_view($id = null) { is_null($id) and Response::redirect('job'); $data['job'] = \Model\Job::find($id); $data['actions'] = ['back' => ['label' => 'Back', 'url' => '/']]; if (\Auth::check()) { list(, $userid) = \Auth::get_user_id(); // check if the job has been saved by the current user $data['favorite'] = \Model\Favorite::find('all', array('where' => array(array('user_id', $userid), array('job_id', $id)))); } $this->template->title = "Jobs"; $this->template->content = View::forge('job/_details.twig', $data); }
/** * Sets the UpdatedBy property to the current user id * * @param Model Model object subject of this observer method */ public function before_update(Orm\Model $obj) { // If there are any relations loop through and check if any of them have been changed $relation_changed = false; foreach ($this->_relations as $relation) { if ($this->relation_changed($obj, $relation)) { $relation_changed = true; break; } } if (($obj->is_changed() or $relation_changed) and $user_id = \Auth::get_user_id()) { $obj->{$this->_property} = $user_id[1]; } }
public function response() { $error_code = $this->getMessage(); $error_list = Lang::load('error/user', $error_code); if (!isset($error_list[$error_code])) { $error_code = \Model_Error::ER00001; } $error_message = $error_list[$error_code]; $params = array('error_code' => $error_code, 'error_message' => $error_message, 'line' => $this->getLine(), 'file' => $this->getFile(), 'url' => Uri::main(), 'input' => print_r(Input::all(), true), 'real_ip' => Input::real_ip(), 'user_agent' => Input::user_agent(), 'user_id' => Auth::get_user_id(), 'occurred_at' => date('Y/m/d H:i:s')); $email = new Model_Email(); $email->sendMailByParams('error', $params); $response = \Request::forge('errors/index', false)->execute($params)->response(); return $response; }
public function action_logout() { $login_log = new Model_Users_Log_Login(); list($driver, $user_id) = Auth::get_user_id(); $login_log->user_id = $user_id; $login_log->status = 0; $login_log->login_time = strtotime('NOW'); $login_log->attempted_login = ''; $login_log->ip_address = $_SERVER['REMOTE_ADDR']; $login_log->save(); Auth::logout(); Session::set_flash('success', 'You have logged out!'); Response::redirect('/'); }
public function before() { parent::before(); if (Auth::check()) { $user_id = Auth::get_user_id()[1]; $this->user = Model_User::find($user_id); if ($this->user->group_id == 1) { $this->auth_status = true; if ($this->user->timezone != "") { $timezone = Config::get("timezone.timezone"); if (isset($timezone[$this->user->timezone])) { date_default_timezone_set($timezone[$this->user->timezone]); } } } } }
public function action_disposition() { $this->template->title = "PPI Disposition Report"; if (\Auth::has_access('reports.all_centers')) { $center = \Input::post('center'); $view_all = TRUE; } else { $view_all = FALSE; list($driver, $user_id) = \Auth::get_user_id(); $this_user = \Model_User::find($user_id); $center = $this_user->call_center_id; } $all_call_centers = \Model_Call_Center::find('all'); $hourlyStatsReport = array('Referrals' => \Crm\Reports\Model_Ppi::perPeriod('referral', $center, \Input::post('startdate'), \Input::post('enddate')), 'Pack Outs' => \Crm\Reports\Model_Ppi::perPeriod('packOut', $center, \Input::post('startdate'), \Input::post('enddate')), 'Pack In' => \Crm\Reports\Model_Ppi::perPeriod('packIn', $center, \Input::post('startdate'), \Input::post('enddate'))); $quickView = array(array('No Contacts' => count(\Crm\Reports\Model_Ppi::simpleStats('noContact', $center, \Input::post('startdate'), \Input::post('enddate'))), 'Referrals' => count(\Crm\Reports\Model_Ppi::simpleStats('referral', $center, \Input::post('startdate'), \Input::post('enddate'))), 'Pack Outs' => count(\Crm\Reports\Model_Ppi::simpleStats('packOut', $center, \Input::post('startdate'), \Input::post('enddate'))), 'Pack Ins' => count(\Crm\Reports\Model_Ppi::packIns($center, \Input::post('startdate'), \Input::post('enddate'))))); $report = Report\Create::forge(array('hourlyStats' => array('reportResults' => $hourlyStatsReport, 'displayType' => 'chart'), 'noContacts' => array('reportResults' => \Crm\Reports\Model_Ppi::simpleStats('noContact', $center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'referrals' => array('reportResults' => \Crm\Reports\Model_Ppi::simpleStats('referral', $center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'packOuts' => array('reportResults' => \Crm\Reports\Model_Ppi::simpleStats('packOut', $center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'packIns' => array('reportResults' => \Crm\Reports\Model_Ppi::packIns($center, \Input::post('startdate'), \Input::post('enddate')), 'options' => array('class' => 'zebra-striped datatable')), 'quickView' => array('reportResults' => $quickView, 'options' => array('direction' => 'vertical'))), 3600); $this->template->content = View::forge(static::$_viewPath . 'ppi/disposition.php', array('reports' => $report->generate(), 'all_call_centers' => $all_call_centers, 'center' => $center, 'start_date' => \Input::post('startdate'), 'end_date' => \Input::post('enddate'), 'view_all' => $view_all)); }
public function action_index() { if (!Auth::check()) { Response::redirect('/'); } $view = View::forge('userpage/index'); $view->tweets = Model_Tweet::find('all'); // postで入ってきたらツイートの投稿 if (Input::method() === 'POST') { $tweet = new Model_Tweet(); $tweet->user_id = Auth::get_user_id()[1]; $tweet->retweet_id = 0; $tweet->content = Input::post('content'); $tweet->save(); Response::redirect('/'); } return $view; }
/** * The basic welcome message * * @access public * @return Response */ public function action_index() { list($driver, $user_id) = Auth::get_user_id(); $this_user = Model_User::find($user_id); $latest_news_q = Model_News::query()->where('call_center_id', $this_user->call_center_id)->or_where('call_center_id', 0)->order_by('created_at', 'DESC'); if ($latest_news_q->count() > 0) { $latest_news = $latest_news_q->get(); } else { $latest_news = null; } $invalid_logins_q = Model_Users_Log_Login::query()->where('user_id', $user_id)->where('status', 2)->order_by('login_time', 'DESC'); if ($invalid_logins_q->count() > 0) { $invalid_logins = $invalid_logins_q->get(); } else { $invalid_logins = null; } $this->template->title = 'Projects » Index'; $this->template->content = View::forge('welcome/index', array('invalid_logins' => $invalid_logins, 'latest_news' => $latest_news))->auto_filter(FALSE); }
public function __construct() { parent::__construct(); $user_id = '-'; if (Auth::is_logged() === TRUE) { $user_id = Auth::get_user_id(); assert($user_id !== '-'); } assert(strchr($user_id, "\r") === FALSE); assert(strchr($user_id, "\n") === FALSE); assert(trim($user_id) === $user_id); if (headers_sent() === FALSE) { header('X-Content-Type-Options: nosniff'); header('X-Frame-Options: deny'); header('X-Content-Security-Policy: ' . 'allow ' . STATIC_URL . ';' . 'options inline-script eval-script;' . 'script-src ' . STATIC_URL . ' ' . 'object-src ' . DYNAMIC_URL . ' ' . STATIC_URL . ';' . 'img-src *;' . 'frame-src none;' . 'frame-ancestors none;' . 'xhr-src self ' . DYNAMIC_URL . ' ' . STATIC_URL . ' ' . COMET_URL . ';'); header('Vary: X-User-ID'); header('X-User-ID: ' . $user_id); if (!empty($_SERVER) && !empty($_SERVER['SERVER_ADDR'])) { header('X-Backend: ' . substr(md5($_SERVER['SERVER_ADDR']), 0, 4)); } } if (empty($_SERVER['PROD'])) { $this->setDebugging(TRUE); $this->setForceCompile(TRUE); } else { $this->setDebugging(FALSE); } $this->setErrorReporting(E_ALL & ~(E_USER_NOTICE | E_NOTICE)); $this->setCaching(FALSE); $this->setTemplateDir(APP_SMARTY_TEMPLATES_DIR); $this->setCompileDir(APP_SMARTY_COMPILE_DIR); $this->setConfigDir(APP_SMARTY_CONFIG_DIR); $this->addPluginsDir(APP_SMARTY_PLUGINS_DIR); $this->config_vars['STATIC_URL'] = htmlspecialchars(STATIC_URL); $this->config_vars['DYNAMIC_URL'] = htmlspecialchars(DYNAMIC_URL); $this->config_vars['JS_VERSION'] = htmlspecialchars(JS_VERSION); $this->config_vars['CSS_VERSION'] = htmlspecialchars(CSS_VERSION); $this->config_vars['IMAGES_VERSION'] = htmlspecialchars(IMAGES_VERSION); $this->config_vars['DEBUG_MODE'] = (bool) (!empty($_COOKIE['debug'])); $this->assign('current_uri', Utils::get_current_uri()); return $this; }
public function before() { parent::before(); \Session::set("current_page", \Uri::string()); $segments = implode(\Uri::segments()); if (Auth::check() || $segments == 'userlogin') { list($driver, $user_id) = Auth::get_user_id(); $this->current_user = Model_User::find($user_id); } else { if ($segments != 'userlogin') { Session::set("lastpage", implode("/", \Uri::segments())); } $this->current_user = null; Response::redirect('user/login'); } if ($segments != 'userlogin') { View::set_global('group_name', Auth_Group_SimpleGroup::instance()->get_name($this->current_user->group)); View::set_global('current_user', $this->current_user); } }
public function before() { parent::before(); // Check Auth Access if (\Auth::check()) { /* * Get the current user id and email address * */ list(, $userId) = Auth::get_user_id(); $this->user = Model_User::find($userId); } isset($this->title) ? $this->title : ($this->title = "Rodas Net"); $this->template->title = $this->title; // Load translation \Lang::load('application'); // If ajax or content_only, set a theme with an empty layout if (\Input::is_ajax()) { return parent::before(); } }
public function before() { $this->template = $this->newIntranet() ? "templates/layout" : "template"; \Session::set("current_page", \Uri::string()); $segments = implode(\Uri::segments()); if (\Auth::check() || $segments == 'userlogin') { list($driver, $user_id) = \Auth::get_user_id(); $this->current_user = \Model_User::find($user_id); } else { if ($segments != 'userlogin') { \Session::set("lastpage", implode("/", \Uri::segments())); } $this->current_user = null; \Response::redirect('user/login'); } if ($segments != 'userlogin') { \View::set_global('group_name', \Auth_Group_SimpleGroup::instance()->get_name($this->current_user->group)); \View::set_global('current_user', $this->current_user); } parent::before(); // Remove when login implemented }
public function createCallback($callbackOn = null, $type = null) { // -- Create a Call back for the selected Referral // ----------------------------------------------- // 1) Check that a there isn't a callback already set for that date & time // ----------------------------------------------------------------------- $callbackExists = \Referrals_callback_model::duplicationCheck($callbackOn); if ($callbackExists > 0) { // -- A callback was found, load it up to show the Agent // ----------------------------------------------------- \Log::error("Callback already exists, don't know what to do with it!", "Crm_Referrals_Callback_Class"); } else { // -- No callback found, so create it // ---------------------------------- $callbackID = 0; list($driver, $user_id) = \Auth::get_user_id(); $thisUser = \Model_User::find($user_id); // User ID, Center ID, Callback Date/Time, Type 'A' = All and 'P' = Personal $callbackID = \Referrals_callback_model::createCallback($user_id, $thisUser->call_center_id, $callbackOn, $type); return $callbackID; } }
public function action_add($id = null) { if ($id) { $job = \Model\Job::find($id); list(, $userid) = \Auth::get_user_id(); if ($job and $userid) { $favorite = \Model\Favorite::find('first', array('where' => array(array('user_id', $userid), array('job_id', $id)))); if ($favorite) { $favorite->delete(); unset($favorite); \Session::set_flash('success', 'The job has been removed from your favorites.'); \Response::redirect('/job/view/' . $job->id . ''); } $props = array('user_id' => $userid, 'job_id' => $id); $favorite = new \Model\Favorite($props); try { $favorite->save(); } catch (Exception $e) { \Session::set_flash('error', 'Job already saved'); \Response::redirect('/job/view/' . $job->id . ''); } \Session::set_flash('success', 'Job #' . $job->id . ' has been added to your favorites.'); \Response::redirect('/job/view/' . $job->id . ''); } else { if ($job == null) { \Session::set_flash('error', 'This job doesn\'t exist.'); \Response::redirect('/'); } else { if ($userid == null) { \Session::set_flash('error', 'You must be logged in in order to add a job to your favorite'); \Response::redirect('/'); } } } } else { \Response::redirect('/'); } }
public function before() { parent::before(); list(, $this->user_id) = Auth::get_user_id(); }
//TODO: REMOVE THIS LINE BEFORE SITE GOES LIVE /****************** DEBUG LINE *********************/ $_GET['pagedebug'] = 'true'; /********************* END ********************/ //Establish session session_start(); //------- COMMON VARIABLES $page = new Page(); $auth = new Auth($db); //Checks Auth at object creation $user = NULL; $page->assign('logged_in', $auth->is_logged_in()); $page->assign('redirect_url', encode_decode_redirect_url($_SERVER['REQUEST_URI'])); $page->load_javascript_include('jquery-1.6.4.min.js'); if ($auth->is_logged_in()) { $user_id = $auth->get_user_id(); $user = new User($user_id); $page->assign('username', $user->get_username()); $page->assign('user_id', $user_id); } //Query logging $db->enable_query_logging(FALSE); $page_debugging = FALSE; if (isset($_GET['pagedebug']) && $_GET['pagedebug'] == 'true' && $auth->is_moderator()) { ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); $page_debugging = TRUE; $db->enable_query_logging(TRUE); //Logs queries for debugging puroses. $db->enable_query_backtracing(TRUE); //Provides location and line numbers for the logging.
/** * Create new user * * @param string * @param string * @param string must contain valid email address * @param int group id * @param Array * @return bool */ public function create_user($username, $password, $email, $group = 1, array $profile_fields = array()) { // prep the password $password = trim($password); // and validate the email address $email = filter_var(trim($email), FILTER_VALIDATE_EMAIL); // bail out if we're missing username, password or email address if (empty($username) or empty($password) or empty($email)) { throw new \SimpleUserUpdateException('Username, password or email address is not given, or email address is invalid', 1); } // check if we already have an account with this email address or username $duplicate = \Model\Auth_User::query()->select(\Config::get('ormauth.table_columns', array()))->where('username', '=', $username)->or_where('email', '=', $email)->get_one(); // did we find one? if ($duplicate) { // bail out with an exception if (strtolower($email) == strtolower($duplicate->email)) { throw new \SimpleUserUpdateException('Email address already exists', 2); } else { throw new \SimpleUserUpdateException('Username already exists', 3); } } // do we have a logged-in user? if ($currentuser = \Auth::get_user_id()) { $currentuser = $currentuser[1]; } else { $currentuser = 0; } // create the new user record $user = \Model\Auth_User::forge(array('username' => (string) $username, 'password' => $this->hash_password((string) $password), 'email' => $email, 'group_id' => (int) $group, 'last_login' => 0, 'previous_login' => 0, 'login_hash' => '', 'user_id' => $currentuser, 'created_at' => \Date::forge()->get_timestamp(), 'updated_at' => 0)); // we don't use profile fields, store the data in the metadata table instead foreach ($profile_fields as $field => $value) { $user->metadata[] = \Model\Auth_Metadata::forge(array('key' => $field, 'value' => $value)); } // save the new user record try { $result = $user->save(); } catch (\Exception $e) { $result = false; } // and the id of the created user, or false if creation failed return $result ? $user->id : false; }