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


PHP AuthFactory类代码示例

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


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

示例1: generate_token

 /**
  * @param Member $user
  * @return string
  */
 private static function generate_token($user)
 {
     $iat = time();
     $data = ['iat' => $iat, 'jti' => AuthFactory::generate_token($user), 'iss' => Config::inst()->get('JwtAuth', 'Issuer'), 'expire' => $iat + Config::inst()->get('JwtAuth', 'ExpireTime'), 'userId' => $user->ID];
     $key = self::get_key();
     return self::jwt_encode($data, $key);
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:11,代码来源:JwtAuth.php

示例2: current

 public static function current($request)
 {
     try {
         $token = AuthFactory::get_token($request);
         return self::get_member_from_token($token);
     } catch (\Exception $e) {
         \SS_Log::log($e->getMessage(), \SS_Log::INFO);
     }
     return false;
 }
开发者ID:notthatbad,项目名称:silverstripe-rest-api,代码行数:10,代码来源:TokenAuth.php

示例3: init

 public function init()
 {
     /* Initialize action controller here */
     parent::init();
     $this->auth = AuthFactory::create(AuthFactory::$AGENT, $this->db, $this->_request);
     $this->chatRequestModel = new Chat_Request($this->db);
     $this->chatSessionModel = new Chat_Session($this->db);
     $this->appChatRequestModel = new App_ChatRequest();
     $this->leadModel = new App_Lead();
     $this->agentModel = new App_Agent();
 }
开发者ID:redhattaccoss,项目名称:Leadschat,代码行数:11,代码来源:AgentsController.php

示例4: createSession

 /**
  * @param \Member $user
  * @return ApiSession
  */
 public static function createSession($user)
 {
     $user->logIn();
     /** @var \Member $user */
     $user = \DataObject::get(\Config::inst()->get('BaseRestController', 'Owner'))->byID($user->ID);
     // create session
     $session = ApiSession::create();
     $session->User = $user;
     $session->Token = AuthFactory::generate_token($user);
     return $session;
 }
开发者ID:notthatbad,项目名称:silverstripe-rest-api,代码行数:15,代码来源:HttpAuth.php

示例5: authenticate

 public static function authenticate($email, $password)
 {
     $authenticator = new MemberAuthenticator();
     if ($user = $authenticator->authenticate(['Password' => $password, 'Email' => $email])) {
         // create session
         $session = ApiSession::create();
         $session->User = $user;
         $session->Token = AuthFactory::generate_token($user);
         // save session
         $cache = SS_Cache::factory('rest_cache');
         $cache->save(json_encode(['token' => $session->Token, 'user' => $session->User->ID]), $session->Token);
         return $session;
     }
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:14,代码来源:TokenAuth.php

示例6: authenticate

 public static function authenticate($email, $password)
 {
     // auth
     $authenticator = new \MemberAuthenticator();
     if ($user = $authenticator->authenticate(['Password' => $password, 'Email' => $email])) {
         $user->logIn();
         $user = DataObject::get(Config::inst()->get('BaseRestController', 'Owner'))->byID($user->ID);
         // create session
         $session = ApiSession::create();
         $session->User = $user;
         $session->Token = AuthFactory::generate_token($user);
         return $session;
     }
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:14,代码来源:SimpleAuth.php

示例7: init

 public function init()
 {
     parent::init();
     $this->auth = AuthFactory::create(AuthFactory::$OWNER, $this->db, $this->_request);
     $this->model = new Owner_Owner($this->db);
     $this->model->setRequestObject($this->_request);
     $this->ownerModel = new App_Owner();
     $this->timezoneModel = new App_Timezone();
     $this->timezoneGroupModel = new App_TimezoneGroup();
     $this->businessTypeModel = new App_BusinessType();
     $this->numberOfHitModel = new App_NumberOfHit();
     $this->leadModel = new App_Lead();
     $this->memberModel = new App_Member();
     $this->baseUrlDashboard = $this->baseUrl . "/js/leadschat-dashboard";
 }
开发者ID:redhattaccoss,项目名称:Leadschat,代码行数:15,代码来源:OwnersController.php

示例8: adduser_validate

function adduser_validate(Pieform $form, $values)
{
    global $USER;
    $authobj = AuthFactory::create($values['authinstance']);
    $institution = $authobj->institution;
    // Institutional admins can only set their own institutions' authinstances
    if (!$USER->get('admin') && !$USER->is_institutional_admin($authobj->institution)) {
        $form->set_error('authinstance', get_string('notadminforinstitution', 'admin'));
        return;
    }
    $institution = new Institution($authobj->institution);
    // Don't exceed max user accounts for the institution
    if ($institution->isFull()) {
        $SESSION->add_error_msg(get_string('institutionmaxusersexceeded', 'admin'));
        redirect('/admin/users/add.php');
    }
    $username = $values['username'];
    $firstname = $values['firstname'];
    $lastname = $values['lastname'];
    $email = $values['email'];
    $password = $values['password'];
    if (method_exists($authobj, 'is_username_valid') && !$authobj->is_username_valid($username)) {
        $form->set_error('username', get_string('addusererrorinvalidusername', 'admin'));
        return;
    }
    if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', strtolower($username))) {
        $form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
        return;
    }
    if (!$form->get_error('firstname') && !preg_match('/\\S/', $firstname)) {
        $form->set_error('firstname', $form->i18n('required'));
    }
    if (!$form->get_error('lastname') && !preg_match('/\\S/', $lastname)) {
        $form->set_error('lastname', $form->i18n('required'));
    }
    if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) {
        $form->set_error('email', get_string('emailalreadytaken', 'auth.internal'));
    }
    if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) {
        $form->set_error('password', get_string('passwordinvalidform', 'auth.' . $authobj->type));
        return;
    }
}
开发者ID:Br3nda,项目名称:mahara,代码行数:43,代码来源:add.php

示例9: delete

 /**
  * @param SS_HTTPRequest $request
  * @return array
  * @throws RestUserException
  */
 public function delete($request)
 {
     // check param for id
     $data = [];
     try {
         if ($id = $request->param('ID')) {
             if ($id != 'me') {
                 throw new RestUserException("No session found", 404);
             }
             AuthFactory::createAuth()->delete($request);
         } else {
             throw new RestUserException("No id specified for deletion", 404);
         }
     } catch (RestUserException $e) {
         throw $e;
     } catch (Exception $e) {
         throw new RestUserException("ApiSession was not found", 404);
     }
     $meta = ['timestamp' => time()];
     $data['meta'] = $meta;
     return $data;
 }
开发者ID:helpfulrobot,项目名称:ntb-silverstripe-rest-api,代码行数:27,代码来源:SessionController.php

示例10: install_site

 /**
  * Installs a site using $CFG->dataroot and $CFG->dbprefix
  * As we are setting up the behat test environment, these settings
  * are replaced by $CFG->behat_dataroot and $CFG->behat_dbprefix
  *
  * @throws SystemException
  * @return void
  */
 public static function install_site()
 {
     if (!defined('BEHAT_UTIL')) {
         throw new SystemException('This method can be only used by Behat CLI tool');
     }
     if (table_exists(new XMLDBTable('config'))) {
         behat_error(BEHAT_EXITCODE_INSTALLED);
     }
     // New dataroot.
     self::reset_dataroot();
     // Determine what we will install
     $upgrades = check_upgrades();
     $upgrades['firstcoredata'] = true;
     $upgrades['localpreinst'] = true;
     $upgrades['lastcoredata'] = true;
     $upgrades['localpostinst'] = true;
     upgrade_mahara($upgrades);
     $userobj = new User();
     $userobj = $userobj->find_by_username('admin');
     $userobj->email = self::$sitedefaultinfo['admin']['email'];
     $userobj->commit();
     // Password changes should be performed by the authfactory
     $authobj = AuthFactory::create($userobj->authinstance);
     $authobj->change_password($userobj, self::$sitedefaultinfo['admin']['password'], true);
     // Set site name
     set_config('sitename', self::$sitedefaultinfo['sitename']);
     // We need to keep the installed dataroot artefact files.
     // So each time we reset the dataroot before running a test, the default files are still installed.
     self::save_original_data_files();
     // Disable some settings that are not wanted on test sites.
     set_config('sendemail', false);
     // Keeps the current version of database and dataroot.
     self::store_versions_hash();
     // Stores the database contents for fast reset.
     self::store_database_state();
 }
开发者ID:sarahjcotton,项目名称:mahara,代码行数:44,代码来源:util.php

示例11: accountprefs_submit

function accountprefs_submit(Pieform $form, $values)
{
    global $USER;
    $authobj = AuthFactory::create($USER->authinstance);
    db_begin();
    if (isset($values['password1']) && $values['password1'] !== '') {
        global $authclass;
        $password = $authobj->change_password($USER, $values['password1']);
        $USER->password = $password;
        $USER->passwordchange = 0;
        $USER->commit();
    }
    // use this as looping through values is not safe.
    $expectedprefs = expected_account_preferences();
    foreach (array_keys($expectedprefs) as $pref) {
        if (isset($values[$pref])) {
            $USER->set_account_preference($pref, $values[$pref]);
        }
    }
    $returndata = array();
    if (isset($values['username']) && $values['username'] != $USER->get('username')) {
        $USER->username = $values['username'];
        $USER->commit();
        $returndata['username'] = $values['username'];
    }
    db_commit();
    $returndata['message'] = get_string('prefssaved', 'account');
    $form->json_reply(PIEFORM_OK, $returndata);
}
开发者ID:Br3nda,项目名称:mahara,代码行数:29,代码来源:index.php

示例12: create_registered_user

 function create_registered_user($profilefields = array())
 {
     global $registration, $SESSION, $USER;
     require_once get_config('libroot') . 'user.php';
     db_begin();
     // Move the user record to the usr table from the registration table
     $registrationid = $registration->id;
     unset($registration->id);
     unset($registration->expiry);
     if ($expirytime = get_config('defaultregistrationexpirylifetime')) {
         $registration->expiry = db_format_timestamp(time() + $expirytime);
     }
     $registration->lastlogin = db_format_timestamp(time());
     $authinstance = get_record('auth_instance', 'institution', $registration->institution, 'authname', $registration->authtype ? $registration->authtype : 'internal');
     if (false == $authinstance) {
         throw new ConfigException('No ' . ($registration->authtype ? $registration->authtype : 'internal') . ' auth instance for institution');
     }
     if (!empty($registration->extra)) {
         // Additional user settings were added during confirmation
         $extrafields = unserialize($registration->extra);
     }
     $user = new User();
     $user->active = 1;
     $user->authinstance = $authinstance->id;
     $user->firstname = $registration->firstname;
     $user->lastname = $registration->lastname;
     $user->email = $registration->email;
     $user->username = get_new_username($user->firstname . $user->lastname);
     $user->passwordchange = 1;
     // Points that indicate the user is a "new user" who should be restricted from spammy activities.
     // We count these down when they do good things; when they have 0 they're no longer a "new user"
     if (is_using_probation()) {
         $user->probation = get_config('probationstartingpoints');
     } else {
         $user->probation = 0;
     }
     if ($registration->institution != 'mahara') {
         if (count_records_select('institution', "name != 'mahara'") == 1 || $registration->pending == 2) {
             if (get_config_plugin('artefact', 'file', 'institutionaloverride')) {
                 $user->quota = get_field('institution', 'defaultquota', 'name', $registration->institution);
             }
         }
     }
     create_user($user, $profilefields);
     // If the institution is 'mahara' then don't do anything
     if ($registration->institution != 'mahara') {
         $institutions = get_records_select_array('institution', "name != 'mahara'");
         // If there is only one available, join it without requiring approval
         if (count($institutions) == 1) {
             $user->join_institution($registration->institution);
         } else {
             if ($registration->pending == 2) {
                 if (get_config('requireregistrationconfirm') || get_field('institution', 'registerconfirm', 'name', $registration->institution)) {
                     $user->join_institution($registration->institution);
                 }
             } else {
                 if ($registration->authtype && $registration->authtype != 'internal') {
                     $auth = AuthFactory::create($authinstance->id);
                     if ($auth->weautocreateusers) {
                         $user->join_institution($registration->institution);
                     } else {
                         $user->add_institution_request($registration->institution);
                     }
                 } else {
                     $user->add_institution_request($registration->institution);
                 }
             }
         }
         if (!empty($extrafields->institutionstaff)) {
             // If the user isn't a member yet, this does nothing, but that's okay, it'll
             // only be set after successful confirmation.
             set_field('usr_institution', 'staff', 1, 'usr', $user->id, 'institution', $registration->institution);
         }
     }
     if (!empty($registration->lang) && $registration->lang != 'default') {
         set_account_preference($user->id, 'lang', $registration->lang);
     }
     // Delete the old registration record
     delete_records('usr_registration', 'id', $registrationid);
     db_commit();
     // Log the user in and send them to the homepage
     $USER = new LiveUser();
     $USER->reanimate($user->id, $authinstance->id);
     if (function_exists('local_post_register')) {
         local_post_register($registration);
     }
     $SESSION->add_ok_msg(get_string('registrationcomplete', 'mahara', get_config('sitename')));
     $SESSION->set('resetusername', true);
     redirect();
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:90,代码来源:register.php

示例13: create_user2_for_update

 /**
  * Create test users from one place to share between update
  * and favourites
  */
 function create_user2_for_update()
 {
     //can run this test only if test usernames don't exist
     foreach (array('veryimprobabletestusername2', 'veryimprobabletestusername2_updated') as $username) {
         $existinguser = get_record('usr', 'username', $username);
         if (!empty($existinguser)) {
             delete_user($existinguser->id);
         }
     }
     $user2 = new stdClass();
     $user2->authinstance = $this->authinstance->id;
     $user2->username = 'veryimprobabletestusername2';
     if ($dbuser2 = get_record('usr', 'username', $user2->username)) {
         return $dbuser2;
     }
     $user2->password = 'testpassword2';
     $user2->firstname = 'testfirstname2';
     $user2->lastname = 'testlastname2';
     $user2->email = 'testemail1@hogwarts.school.nz';
     $profilefields = new StdClass();
     db_begin();
     $userid = create_user($user2, $profilefields, $this->institution, $this->authinstance);
     db_commit();
     $dbuser2 = get_record('usr', 'username', $user2->username);
     $this->assertTrue($dbuser2 instanceof stdClass);
     $userobj = new User();
     $userobj = $userobj->find_by_id($dbuser2->id);
     $authobj_tmp = AuthFactory::create($dbuser2->authinstance);
     $authobj_tmp->change_password($userobj, $dbuser2->password, false);
     $this->created_users[] = $dbuser2->id;
     $dbuser2 = get_record('usr', 'username', $user2->username);
     return $dbuser2;
 }
开发者ID:rboyatt,项目名称:mahara,代码行数:37,代码来源:WebServiceTestBase.class.php

示例14: login

 public function login($email)
 {
     // This will do one of 3 things
     // 1 - If a user has an account, log them in
     // 2 - If a user doesn't have an account, and there is an auth method (which also has weautocreate), create acc and login
     // 3 - If a user doesn't have an account, and there is more than one auth method, show a registration page
     $sql = "SELECT\n                    a.id, i.name AS institutionname\n                FROM\n                    {auth_instance} a\n                JOIN\n                    {institution} i ON a.institution = i.name\n                WHERE\n                    a.authname = 'browserid' AND\n                    i.suspended = 0";
     $authinstances = get_records_sql_array($sql, array());
     if (!$authinstances) {
         throw new ConfigException(get_string('browseridnotenabled', 'auth.browserid'));
     }
     $autocreate = array();
     // Remember the authinstances that are happy to create users
     foreach ($authinstances as $authinstance) {
         $auth = AuthFactory::create($authinstance->id);
         $institutionjoin = '';
         $institutionwhere = '';
         $sqlvalues = array($email);
         if ($authinstance->institutionname != 'mahara') {
             // Make sure that user is in the right institution
             $institutionjoin = 'JOIN {usr_institution} ui ON ui.usr = u.id';
             $institutionwhere = 'AND ui.institution = ?';
             $sqlvalues[] = $authinstance->institutionname;
         }
         $sql = "SELECT\n                        u.*,\n                        " . db_format_tsfield('u.expiry', 'expiry') . ",\n                        " . db_format_tsfield('u.lastlogin', 'lastlogin') . ",\n                        " . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ",\n                        " . db_format_tsfield('u.lastaccess', 'lastaccess') . ",\n                        " . db_format_tsfield('u.suspendedctime', 'suspendedctime') . ",\n                        " . db_format_tsfield('u.ctime', 'ctime') . "\n                    FROM\n                        {usr} u\n                    JOIN\n                        {artefact_internal_profile_email} a ON a.owner = u.id\n                    {$institutionjoin}\n                    WHERE\n                        a.verified = 1 AND\n                        a.email = ?\n                    {$institutionwhere}";
         $user = get_record_sql($sql, $sqlvalues);
         if (!$user) {
             if ($auth->weautocreateusers) {
                 if ($authinstance->institutionname == 'mahara') {
                     array_unshift($autocreate, $auth);
                     // Try "No Instititution" first when creating users below
                 } else {
                     $autocreate[] = $auth;
                 }
             }
             continue;
             // skip to the next auth_instance
         }
         if (is_site_closed($user->admin)) {
             return false;
         }
         ensure_user_account_is_active($user);
         $this->authenticate($user, $auth->instanceid);
         return true;
     }
     foreach ($autocreate as $auth) {
         if (!($user = $auth->create_new_user($email))) {
             continue;
         }
         $this->authenticate($user, $auth->instanceid);
         return;
     }
     // Autocreation failed; try registration.
     list($form, $registerconfirm) = auth_generate_registration_form('register', 'browserid', '/register.php');
     if (!$form) {
         throw new AuthUnknownUserException(get_string('emailnotfound', 'auth.browserid', $email));
     }
     if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) {
         throw new AuthUnknownUserException(get_string('emailalreadytaken', 'auth.internal', $email));
     }
     $form['elements']['email'] = array('type' => 'hidden', 'value' => $email);
     $form['elements']['authtype'] = array('type' => 'hidden', 'value' => 'browserid');
     list($formhtml, $js) = auth_generate_registration_form_js($form, $registerconfirm);
     $registerdescription = get_string('registerwelcome');
     if ($registerterms = get_config('registerterms')) {
         $registerdescription .= ' ' . get_string('registeragreeterms');
     }
     $registerdescription .= ' ' . get_string('registerprivacy');
     $smarty = smarty();
     $smarty->assign('register_form', $formhtml);
     $smarty->assign('registerdescription', $registerdescription);
     if ($registerterms) {
         $smarty->assign('termsandconditions', get_site_page_content('termsandconditions'));
     }
     $smarty->assign('PAGEHEADING', get_string('register', 'auth.browserid'));
     $smarty->assign('INLINEJAVASCRIPT', $js);
     $smarty->display('register.tpl');
     die;
 }
开发者ID:sarahjcotton,项目名称:mahara,代码行数:79,代码来源:lib.php

示例15: get_string

$settings->options = $options;
$settings->info = get_string('cliinstallerdescription', 'admin');
$cli->setup($settings);
// Check whether we need to do anything
if (table_exists(new XMLDBTable('config'))) {
    cli::cli_exit(get_string('maharainstalled', 'admin'), false);
}
// Check initial password and e-mail address before we install
try {
    $adminpassword = $cli->get_cli_param('adminpassword');
    $adminemail = $cli->get_cli_param('adminemail');
} catch (ParameterException $e) {
    cli::cli_exit($e->getMessage(), true);
}
// Determine what we will install
$upgrades = check_upgrades();
$upgrades['firstcoredata'] = true;
$upgrades['localpreinst'] = true;
$upgrades['lastcoredata'] = true;
$upgrades['localpostinst'] = true;
// Actually perform the installation
log_info(get_string('cliinstallingmahara', 'admin'));
upgrade_mahara($upgrades);
// Set initial password and e-mail address
$userobj = new User();
$userobj = $userobj->find_by_username('admin');
$userobj->email = $adminemail;
$userobj->commit();
// Password changes should be performed by the authfactory
$authobj = AuthFactory::create($userobj->authinstance);
$authobj->change_password($userobj, $adminpassword, true);
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:31,代码来源:install.php


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