本文整理汇总了PHP中Auth::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::instance方法的具体用法?PHP Auth::instance怎么用?PHP Auth::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auth
的用法示例。
在下文中一共展示了Auth::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
parent::__construct();
// Load profiler
if (Kohana::config('config.enable_profiler')) {
$this->profiler = new Profiler();
}
$this->auth = Auth::instance();
$this->db = Database::instance();
// Are we logged in? if not, do we have an auto-login cookie?
if (!$this->auth->logged_in()) {
// Try to login with 'remember me' token
if (!$this->auth->auto_login()) {
// Login user in via HTTP AUTH
$this->auth->http_auth_login();
}
}
// Get session information
$this->user = Auth::instance()->get_user();
// Check private deployment access
$controller_whitelist = array('login', 'riverid', 'api', 'frontlinesms', 'smssync', 'nexmo');
if (Kohana::config('settings.private_deployment')) {
if (!$this->auth->logged_in('login') and !in_array(Router::$controller, $controller_whitelist)) {
// Redirect to login form
url::redirect('login');
}
}
// Set default content-type header
header('Content-type: text/html; charset=UTF-8');
}
示例2: action_signout
public function action_signout()
{
#Sign out the user
Auth::instance()->logout();
#redirect to the user account and then the signin page if logout worked as expected
Request::instance()->redirect('/admin/site/index');
}
示例3: setTrackerListCount
public function setTrackerListCount()
{
$auth = Auth::instance();
$loggedInEmpNumber = $auth->getEmployeeNumber();
$searchParameter = array('limit' => null, 'employeeId' => $loggedInEmpNumber);
$this->trackListCount = $this->getPerformanceTrackerService()->getPerformanceTrackListCountByEmployee($searchParameter);
}
示例4: delete
public function delete($id = NULL)
{
if (Auth::instance()->get_user()->id == $this->id || Auth::instance()->get_user()->id == $id) {
return;
}
parent::delete($id);
}
示例5: __construct
public function __construct()
{
if (!Auth::instance()->logged_in('admin')) {
Event::run('system.404');
}
parent::__construct();
}
示例6: render
public function render()
{
$view = View::factory('feed/' . $this->type . '_' . $this->action)->bind('lecture', $lecture)->bind('user', $user)->bind('span', $span)->bind('role', $role)->bind('feed_id', $feed_id)->bind('comments', $comments)->bind('url', $url);
if ($this->action == 'add') {
$lecture = ORM::factory('lecture', $this->respective_id);
if ($this->check_deleted($lecture)) {
return View::factory('feed/unavaliable')->render();
}
} else {
if ($this->action == 'canceled') {
$lecture = Model_Lecture::get_lecture_from_event($this->respective_id);
$event = ORM::factory('event', $this->respective_id);
if ($this->check_deleted($lecture)) {
return View::factory('feed/unavaliable')->render();
}
$view->bind('event', $event);
}
}
$user = ORM::factory('user', $this->actor_id);
$span = Date::fuzzy_span($this->time);
$feed_id = $this->id;
$curr_user = Auth::instance()->get_user();
$role = $curr_user->role()->name;
$comment = ORM::factory('feedcomment');
$comment->where('feed_id', '=', $feed_id)->order_by('date', 'DESC');
$comments = $comment->find_all();
$url = Url::site('profile/view/id/');
return $view->render();
}
示例7: action_index
public function action_index()
{
if (!Auth::instance()->logged_in() && isset($_POST['login'])) {
$user = ORM::factory('User');
$status = Auth::instance()->login($_POST['username'], $_POST['password'], true);
if ($status) {
HTTP::redirect('/');
}
}
if (Auth::instance()->logged_in() && isset($_POST['logout'])) {
Auth::instance()->logout();
}
if (!Auth::instance()->logged_in()) {
Guestid::factory()->get_id();
}
$templateData['title'] = 'Главная.';
$templateData['description'] = '';
$template = View::factory('template')->set('templateData', $templateData);
$content = View::factory("catalog");
$content->get = $_GET;
$content->shopArr = Model::factory('Shop')->getShop();
$root_page = "index";
$template->root_page = $root_page;
$template->content = $content;
$this->response->body($template);
}
示例8: getBestUser
public static function getBestUser()
{
if (self::$bestUserRun) {
return self::$bestUser;
}
$user = null;
$segments = URL::getItems();
foreach ($segments as $uname) {
if (!in_array($uname, self::$skipNames)) {
if (is_numeric($uname)) {
$user = ORM::factory("user", $uname);
} else {
$user = ORM::factory("user")->where('vanity_url', '=', $uname)->find();
}
if ($user && $user->loaded()) {
break;
}
}
}
if (empty($user) || !$user->loaded()) {
$user = Auth::instance()->get_user();
}
if (empty($user) || !$user->loaded()) {
$user = new stdClass();
$user->loaded = function () {
return false;
};
}
self::$bestUserRun = true;
self::$bestUser = $user;
return $user;
}
示例9: action_index
public function action_index()
{
$message = false;
$user = false;
if (Arr::get($_POST, 'hidden') == 'form_sent') {
if (Auth::instance()->login(Arr::get($_POST, 'username'), Arr::get($_POST, 'password'), Arr::get($_POST, 'remember'))) {
$user = Auth::instance()->get_user();
Session::instance()->set('username', $user->name . ' ' . $user->surname)->set('language', $user->language)->set('listsize', $user->listsize);
}
}
if (Auth::instance()->logged_in()) {
$user = Auth::instance()->get_user();
Session::instance()->set('username', $user->name . ' ' . $user->surname)->set('language', $user->language)->set('listsize', $user->listsize);
try {
$server_config = $user->object->as_array();
$fb_config = array('type' => 'pdo', 'connection' => array('dsn' => 'firebird:dbname=' . $server_config['config_server'] . ':' . $server_config['config_bdfile'], 'username' => $server_config['config_bduser'], 'password' => $server_config['config_bdpass']));
Session::instance()->set('fb_config', $fb_config);
$fb = Database::instance('fb', $fb_config);
//$fb->connect();
$this->request->redirect('/admin/');
} catch (Database_Exception $e) {
$message = __('error.connection_db');
Auth::instance()->logout();
}
}
$this->request->response = View::factory('login', array('message' => $message));
}
示例10: before
public function before()
{
parent::before();
// The user is already logged in
if (Auth::instance()->logged_in())
{
Request::instance()->redirect('');
}
// Load the configuration for this provider
$config = Kohana::config('oauth.'.$this->provider);
// Create a consumer from the config
$this->consumer = OAuth_Consumer::factory($config);
// Load the provider
$this->provider = OAuth_Provider::factory($this->provider);
if ($token = Cookie::get($this->cookie))
{
// Get the token from storage
$this->token = unserialize($token);
}
}
示例11: action_index
/**
* View the marksheet of a student by passing a user_id in get
* so will be accessible only to the admin and teacher
* if no user is passed, a filter will be applied to check if
* its the current user trying to view his/her own marksheet or
* if its the parant trying to view the marksheet of their pupil
*/
public function action_index()
{
$relevant_user = Acl::instance()->relevant_user();
if (!$relevant_user) {
echo 'Not allowed';
exit;
}
$user = Auth::instance()->get_user();
$course_ids = $user->courses->find_all()->as_array(NULL, 'id');
if ($course_ids) {
$exams = ORM::factory('exam');
$exams->where('course_id', 'IN', $course_ids)->group_by('examgroup_id');
$exams = $exams->find_all()->as_array(NULL, 'examgroup_id');
if ($exams) {
$examgroups = ORM::factory('examgroup');
$examgroups->where('publish', '=', '1');
$examgroups->where('id', 'IN', $exams)->group_by('id');
$examgroups = $examgroups->find_all();
} else {
$examgroups = "";
}
} else {
$examgroups = "";
}
$view = View::factory('examresult/index')->bind('examgroup', $examgroups);
$this->content = $view;
}
示例12: before
public function before()
{
parent::before();
$auth = \Auth::instance('SimpleAuth');
if (\Input::get('logout')) {
$auth->logout();
\Response::redirect(\Uri::base(false) . 'admin/login');
}
$uri = explode('/', \Uri::string());
if ($auth->check()) {
if (count($uri) < 3 && (empty($uri[1]) || $uri[1] == 'login')) {
\Response::redirect(\Uri::base(false) . 'admin/list');
}
// Load admin Config for List View and default to first tab
$this->data['tabs'] = $this->template->tabs = \Config::get('admin.tabs');
$this->data['table'] = $this->param('item', '');
// get item from URI
if (!$this->data['table']) {
list($this->data['table']) = array_slice(array_keys($this->data['tabs']), 0, 1);
}
$this->template->table = $this->data['table'];
} elseif (count($uri) > 1 && $uri[1] != 'login') {
\Response::redirect(\Uri::base(false) . 'admin/login');
}
if ($this->auto_render === true) {
// set up defaults
$this->template->body = '';
}
return true;
}
示例13: action_login
public function action_login()
{
// Already logged in
Auth::check() and Response::redirect('admin');
$val = Validation::forge();
if (Input::method() == 'POST') {
$val->add('email', 'ユーザ名')->add_rule('required');
$val->add('password', 'パスワード')->add_rule('required');
if ($val->run()) {
$auth = Auth::instance();
// check the credentials. This assumes that you have the previous table created
if (Auth::check() or $auth->login(Input::post('email'), Input::post('password'))) {
// credentials ok, go right in
if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
$current_user = Model\Auth_User::find_by_username(Auth::get_screen_name());
} else {
$current_user = Model_User::find_by_username(Auth::get_screen_name());
}
Session::set_flash('success', e('ようこそ、' . $current_user->username . 'さん'));
Response::redirect('admin');
} else {
$this->template->set_global('login_error', '失敗しました');
}
}
}
$this->template->title = 'ログイン';
$this->template->content = View::forge('admin/login', array('val' => $val), false);
}
示例14: preExecute
public function preExecute()
{
$sessionVariableManager = new DatabaseSessionManager();
$sessionVariableManager->setSessionVariables(array('orangehrm_user' => Auth::instance()->getLoggedInUserId()));
$sessionVariableManager->registerVarables();
$this->setOperationName(OrangeActionHelper::getActionDescriptor($this->getModuleName(), $this->getActionName()));
}
示例15: before
/**
* Automatically executed before the widget action. Can be used to set
* class properties, do authorization checks, and execute other custom code.
*
* @return void
*/
public function before()
{
// get all categories
if ($this->categories != FALSE) {
$this->cat_items = Model_Category::get_as_array();
$this->cat_order_items = Model_Category::get_multidimensional();
}
// get all locations
if ($this->locations != FALSE) {
$this->loc_items = Model_Location::get_as_array();
$this->loc_order_items = Model_Location::get_multidimensional();
}
if ($this->price != FALSE) {
$this->price = TRUE;
}
// user
if (Auth::instance()->logged_in()) {
//subscriber
// check if user is already subscribed
$user_id = Auth::instance()->get_user()->id_user;
$obj_subscriber = new Model_Subscribe();
$subscriber = $obj_subscriber->where('id_user', '=', $user_id)->limit(1)->find();
if ($subscriber->loaded()) {
$this->subscriber = TRUE;
}
//if user logged in pass email and id
$this->user_email = Auth::instance()->get_user()->email;
$this->user_id = $user_id;
} else {
$this->user_id = 0;
}
//min - max price selected
$this->min_price = $this->min_price;
$this->max_price = $this->max_price;
}