当前位置: 首页>>代码示例>>PHP>>正文


PHP Auth类代码示例

本文整理汇总了PHP中Auth的典型用法代码示例。如果您正苦于以下问题:PHP Auth类的具体用法?PHP Auth怎么用?PHP Auth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Auth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check

 /**
  * When visiting any page on the site, check if the user is already logged in,
  * or they are visiting a page that is allowed when logged out. Otherwise,
  * redirect to the login page. If visiting the login page, check the browser
  * supports cookies.
  */
 public function check()
 {
     $uri = new URI();
     // Skip check when accessing the data services, as it is redundant but would slow the services down.
     // Also no need to login when running the scheduled tasks.
     if ($uri->segment(1) == 'services' || $uri->segment(1) == 'scheduled_tasks') {
         return;
     }
     // check for setup request
     //
     if ($uri->segment(1) == 'setup_check') {
         // get kohana paths
         //
         $ipaths = Kohana::include_paths();
         // check if indicia_setup module folder exists
         //
         clearstatcache();
         foreach ($ipaths as $path) {
             if (preg_match("/indicia_setup/", $path) && file_exists($path)) {
                 return;
             }
         }
     }
     // Always logged in
     $auth = new Auth();
     if (!$auth->logged_in() and !$auth->auto_login() and $uri->segment(1) != 'login' and $uri->segment(1) != 'logout' and $uri->segment(1) != 'new_password' and $uri->segment(1) != 'forgotten_password') {
         $_SESSION['requested_page'] = $uri->string();
         url::redirect('login');
     } else {
         if ($auth->logged_in() and is_null($_SESSION['auth_user']->password) and $uri->segment(1) != 'new_password' and $uri->segment(1) != 'logout' and $uri->segment(1) != 'setup_check') {
             $_SESSION['requested_page'] = $uri->string();
             url::redirect('new_password');
         }
     }
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:41,代码来源:login.php

示例2: authForRole

/**
 * Authentication & authorization middleware for routes
 *
 * Checks if User is signed in & has required privileges. Otherwise redirects to login page
 *
 * @param int $minRole  Minimum required User role
 *
 * @return callable
 */
function authForRole($minRole)
{
    return function () use($minRole) {
        $app = Slim\Slim::getInstance();
        $auth = new Auth();
        $signedIn = $auth->checkSession();
        if (!$signedIn) {
            $app->flash('error', 'Sign in required');
            $app->redirect('/signin');
        } else {
            $user = unserialize($_SESSION['User']);
            switch ($minRole) {
                case User::ADMIN:
                    if (in_array($user['role'], [User::ADMIN])) {
                        return;
                    }
                    break;
                case User::EXTENDED:
                    if (in_array($user['role'], [User::ADMIN, User::EXTENDED])) {
                        return;
                    }
                    break;
                case User::NORMAL:
                    if (in_array($user['role'], [User::ADMIN, User::EXTENDED, User::NORMAL])) {
                        return;
                    }
                    break;
            }
            $app->flash('error', 'You are not authorized to view this page');
            $app->redirect('/signin');
        }
    };
}
开发者ID:lagut-in,项目名称:Slim-Image-Archive,代码行数:42,代码来源:routes.php

示例3: __construct

 public function __construct()
 {
     parent::__construct();
     $this->template->links = array('Home' => 'home', 'Browse' => 'folders', 'Search' => 'search', 'About' => 'about', 'Contact' => 'contact');
     $this->db = Database::instance();
     // makes database object available to all controllers
     $this->session = Session::instance();
     $authentic = new Auth();
     if ($authentic->logged_in() || $authentic->auto_login()) {
         $this->user = $authentic->get_user();
     } else {
         $this->session->set("requested_url", "/" . url::current());
         // this will redirect from the login page back to this page
         url::redirect('/auth/login');
     }
     // if ($authentic->auto_login()) {
     //     $this->user = $authentic->get_user();
     //     url::redirect('/document/view/1');
     // }
     // if (!$authentic->logged_in()) {
     //
     //     $this->session->set("requested_url","/".url::current()); // this will redirect from the login page back to this page
     //     url::redirect('/auth/login');
     // } else {
     //     $this->user = $authentic->get_user(); //now you have access to user information stored in the database
     // }
 }
开发者ID:jokke,项目名称:ORL,代码行数:27,代码来源:website.php

示例4: start

 public function start()
 {
     $authenticator = new Auth();
     if ($authenticator->auth()) {
         $this->startDownload();
     }
 }
开发者ID:backdorus,项目名称:manul,代码行数:7,代码来源:DownloadController.inc.php

示例5: custom_validate

 /**
  * Custom validation for this model - complements the default validate()
  *
  * @param   array  array to validate
  * @param   Auth   instance of Auth class; used for testing purposes
  * @return bool TRUE if validation succeeds, FALSE otherwise
  */
 public static function custom_validate(array &$post, Auth $auth = null)
 {
     // Initalize validation
     $post = Validation::factory($post)->pre_filter('trim', TRUE);
     if ($auth === null) {
         $auth = new Auth();
     }
     $post->add_rules('username', 'required', 'length[3,100]', 'alpha_numeric');
     $post->add_rules('name', 'required', 'length[3,100]');
     $post->add_rules('email', 'required', 'email', 'length[4,64]');
     // If user id is not specified, check if the username already exists
     if (empty($post->user_id)) {
         $post->add_callbacks('username', array('User_Model', 'unique_value_exists'));
         $post->add_callbacks('email', array('User_Model', 'unique_value_exists'));
     }
     // Only check for the password if the user id has been specified
     if (empty($post->user_id)) {
         $post->add_rules('password', 'required', 'length[5,50]', 'alpha_numeric');
     }
     // If Password field is not blank
     if (!empty($post->password) or empty($post->password) and !empty($post->password_again)) {
         $post->add_rules('password', 'required', 'length[5,50]', 'alpha_numeric', 'matches[password_again]');
     }
     $post->add_rules('role', 'required', 'length[3,30]', 'alpha_numeric');
     $post->add_rules('notify', 'between[0,1]');
     if (!$auth->logged_in('superadmin')) {
         $post->add_callbacks('role', array('User_Model', 'prevent_superadmin_modification'));
     }
     // Additional validation checks
     Event::run('ushahidi_action.user_submit_admin', $post);
     // Return
     return $post->validate();
 }
开发者ID:neumicro,项目名称:Ushahidi_Web_Dev,代码行数:40,代码来源:user.php

示例6: Confirm

 /**
  * 
  */
 public function Confirm()
 {
     $auth = new Auth();
     $shop = new ShoppingCart();
     $user = $auth->id();
     $myShop = $shop->all();
     $objDetails = new DetalleCompra();
     $total = 0;
     if (empty($myShop)) {
         return false;
     }
     foreach ($myShop as $key => $val) {
         $total += $val->precio * $val->cantidad;
     }
     $result_insert = $this->create($user, $total);
     if ($result_insert->success) {
         foreach ($myShop as $k => $v) {
             try {
                 $objDetails->create($result_insert->id, $v->id_prod, $v->name, $v->cantidad, $v->precio, $v->talle, $v->color);
                 //$stock = new TempStock();
                 //echo $stock->removeTempStock($user,$v->id_prod,$v->id_talle,$v->id_color,$v->type);
             } catch (Exception $e) {
                 echo $e->getMessage();
             }
         }
         $auth->restPoints($total);
         $auth->sumConsumed($total);
         $shop->removeAll();
         return true;
     }
 }
开发者ID:EzequielDot175,项目名称:mknet,代码行数:34,代码来源:class.compras.php

示例7: add

 public function add(Auth $auth)
 {
     if ($auth === $this) {
         die('Fail add!');
     }
     $this->_authList[$auth->getName()] = $auth;
 }
开发者ID:YidaChen,项目名称:tutorial-php-advenced,代码行数:7,代码来源:Group.php

示例8: login

 /**
  * Gets user authentication token.
  *
  * @param email - required -
  *            The email address of the user.
  * @param password - required -
  *            The password of the user.
  * @return An Auth object. If the call is successful, the authentication token is set.
  * If unsuccessful, the object contains the error code and message thrown by the server.
  */
 public function login($email, $password)
 {
     $parameters = array('email' => $email, 'password' => $password);
     $urld = 'dpi/v1/auth';
     $headers = array('X-Api-Key' => $this->apiKey);
     $this->response = $this->restTransportInstance->sendRequest($urld, $parameters, self::HTTP_POST);
     $responseBody = simplexml_load_string($this->response);
     $returnObject = new Auth();
     if ($responseBody === false) {
         $errorCode = 'N/A';
         $errorMessage = 'The server has encountered an error, please try again.';
         $errorObject = new ErrorStatus($errorCode, $errorMessage);
         $returnObject->setErrorStatus($errorObject);
     } else {
         $errorStatus = $responseBody->errorStatus;
         if (empty($errorStatus)) {
             $authToken = (string) $responseBody->authToken;
             $returnObject->setAuthToken($authToken);
         } else {
             $errorCode = (string) $responseBody->errorStatus->code;
             $errorMessage = (string) $responseBody->errorStatus->message;
             $errorObject = new ErrorStatus($errorCode, $errorMessage);
             $returnObject->setErrorStatus($errorObject);
         }
     }
     return $returnObject;
 }
开发者ID:EdgeCommerce,项目名称:edgecommerce,代码行数:37,代码来源:Authentication.php

示例9: __destruct

    }
    public function __destruct()
    {
        parent::__destruct();
    }
    /**
	 * 转换word文档
	 */
    public function convert()
    {
        $app_id = isset($this->input['custom_appid']) ? trim($this->input['custom_appid']) : '';
        $app_key = isset($this->input['custom_appkey']) ? trim($this->input['custom_appkey']) : '';
        if (empty($app_id) || empty($app_key)) {
            $this->errorOutput(PARAM_WRONG);
        }
        //先验证是否有权限
        $auth = new Auth();
        $auth_info = $auth->getAccessToken($app_id, $app_key);
        if (!$auth_info) {
            $this->errorOutput(NO_AUTH);
        }
        //处理上传的word文档
        $gGlobalConfig['officeconvert'] = array('host' => '10.0.1.59:8080', 'dir' => 'officeConverter/');
        $curl = new curl($gGlobalConfig['officeconvert']['host'], $gGlobalConfig['officeconvert']['dir']);
        $curl->setSubmitType('post');
        $curl->setReturnFormat('str');
        $curl->initPostData();
        $curl->addFile($_FILES);
        $curl->addRequestData('custom_appid', $app_id);
        $curl->addRequestData('custom_appkey', $app_key);
开发者ID:h3len,项目名称:Project,代码行数:30,代码来源:convert.php

示例10: run

 private function run()
 {
     if (!empty($this->parts[0])) {
         $ctrl = $this->parts[0];
         if (file_exists("controllers/" . $ctrl . ".php")) {
             include "controllers/" . $ctrl . ".php";
             if (class_exists($ctrl)) {
                 $ctrl_obj = new $ctrl();
                 if (!empty($this->parts[1])) {
                     $method = $this->parts[1];
                     if (method_exists($ctrl_obj, $method)) {
                         if (!empty($this->parts[2])) {
                             $params = array_slice($this->parts, 2);
                             call_user_func_array(array($ctrl_obj, $method), $params);
                         } else {
                             $ctrl_obj->{$method}();
                         }
                     } else {
                         echo "METHOD NOT FOUND!";
                     }
                 } else {
                     $ctrl_obj->index();
                 }
             } else {
                 echo "CLASS NOT FOUND!";
             }
         } else {
             echo "FILE NOT FOUND!";
         }
     } else {
         include "controllers/auth.php";
         $default_obj = new Auth();
         $default_obj->index();
     }
 }
开发者ID:narekhovsepyan,项目名称:Mvc_custom_framework,代码行数:35,代码来源:routes.php

示例11: methodLogin

 /**
  * This method try to identicate a user
  *
  * @param $params array of options
  * => login_name : mandatory user name
  * => login_password : mandatory user password
  * => other : optionnal values for post action
  *@param $protocol the communication protocol used
  *
  * @return an response ready to be encode
  * => id of the user
  * => name of the user
  * => realname of the user
  * => firstname of the user
  * => session : ID of the session for future call
  **/
 static function methodLogin($params, $protocol)
 {
     if (isset($params['help'])) {
         return array('login_name' => 'string,mandatory', 'login_password' => 'string,mandatory', 'help' => 'bool,optional');
     }
     if (!isset($params['login_name']) || empty($params['login_name'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'login_name');
     }
     if (!isset($params['login_password']) || empty($params['login_password'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'login_password');
     }
     foreach ($params as $name => $value) {
         switch ($name) {
             case 'login_name':
             case 'login_password':
                 break;
             default:
                 // Store to Session, for post login action (retrieve_more_data_from_ldap, p.e.)
                 $_SESSION[$name] = $value;
         }
     }
     $identificat = new Auth();
     if ($identificat->Login($params['login_name'], $params['login_password'], true)) {
         session_write_close();
         return array('id' => Session::getLoginUserID(), 'name' => $_SESSION['glpiname'], 'realname' => $_SESSION['glpirealname'], 'firstname' => $_SESSION['glpifirstname'], 'session' => $_SESSION['valid_id']);
     }
     return self::Error($protocol, WEBSERVICES_ERROR_LOGINFAILED, '', Html::clean($identificat->getErr()));
 }
开发者ID:JULIO8,项目名称:respaldo_glpi,代码行数:44,代码来源:methodsession.class.php

示例12: authenticationCheck

 function authenticationCheck()
 {
     $user = new \DB\SQL\Mapper($this->db, 'user');
     $auth = new \Auth($user, array('id' => 'name', 'pw' => 'password'));
     $loginResult = $auth->basic();
     return $loginResult;
 }
开发者ID:srccn,项目名称:f3,代码行数:7,代码来源:BaseController.php

示例13: login

 /**
  * Connect using the test user
  */
 protected function login()
 {
     $auth = new Auth();
     if (!$auth->Login(TU_USER, TU_PASS, true)) {
         $this->markTestSkipped('No login');
     }
 }
开发者ID:btry,项目名称:glpi,代码行数:10,代码来源:DbTestCase.php

示例14: ShowModifications

function ShowModifications(&$p, $db_table, $db_id)
{
    global $database;
    $m_mod = new Modification($database);
    $m_auth = new Auth($database);
    $mods = $m_mod->byTableID($db_table, $db_id);
    if (!false_or_null($mods)) {
        $data = array();
        foreach ($mods as $mod) {
            $user = $m_auth->Get($mod['r_Auth']);
            $what = '';
            $w = json_decode($mod['What'], true);
            foreach ($w as $dataset) {
                foreach ($dataset as $table => $change) {
                    $what .= $table . ' #' . $change['I'] . '\'s ' . $change['F'] . (isset($change['E']) ? ' » ' . $change['E'] : '');
                }
            }
            $data[] = array($user['username'], $what, $mod['Message'], human_datetime(intval($mod['Timestamp'])));
        }
        $table = new TableHelper(array('table' => "table wide", 'thead' => "tablehead", 'th' => "tablehead", 'td' => "tablecell", 'headings' => array('Who', 'What', ' ', 'When'), 'data' => $data));
        $p->HTML('<div class="formgroup">');
        $p->HTML('<h4>Recent Activity</h4>');
        $p->Table($table);
        $p->HTML('</div>');
    }
}
开发者ID:h3rb,项目名称:page,代码行数:26,代码来源:Modifications.php

示例15: upAction

 /**
  * Registration
  */
 public function upAction()
 {
     if ($this->request->isPost()) {
         $user = new Users();
         $user->login = $this->request->getPost('login', 'string');
         $user->password = $this->request->getPost('password', 'string');
         $passwordVerify = $this->request->getPost('password-verify', 'string');
         if (md5($user->password) !== md5($passwordVerify)) {
             $this->flashSession->error('Пароли не совпадают');
             return;
         }
         if (!$user->create()) {
             $this->flashSession->error(implode("<br/>", $user->getMessages()));
             return;
         }
         $auth = new Auth();
         $authSucceed = $auth->authorize($user);
         if ($authSucceed) {
             $this->response->redirect();
             return;
         }
         $this->dispatcher->forward(['controller' => 'sign', 'action' => 'in']);
         return;
     }
 }
开发者ID:vlad6085,项目名称:projectstorage,代码行数:28,代码来源:SignController.php


注:本文中的Auth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。