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


PHP Security::default_admin_username方法代码示例

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


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

示例1: authenticate_member

 /**
  * Attempt to find and authenticate member if possible from the given data.
  *
  * @param array $data
  * @param Form $form
  * @param bool &$success Success flag
  * @return Member Found member, regardless of successful login
  * @see MemberAuthenticator::authenticate_member()
  */
 protected static function authenticate_member($data, $form, &$success)
 {
     // Default success to false
     $success = false;
     // Attempt to identify by temporary ID
     $member = null;
     $email = null;
     if (!empty($data['tempid'])) {
         // Find user by tempid, in case they are re-validating an existing session
         $member = Member::member_from_tempid($data['tempid']);
         if ($member) {
             $email = $member->Email;
         }
     }
     // Otherwise, get email from posted value instead
     if (!$member && !empty($data['Email'])) {
         $email = $data['Email'];
     }
     // Check default login (see Security::setDefaultAdmin()) the standard way and the "extension"-way :-)
     $asDefaultAdmin = $email === Security::default_admin_username();
     if ($asDefaultAdmin || isset($GLOBALS['_DEFAULT_ADMINS']) && array_key_exists($email, $GLOBALS['_DEFAULT_ADMINS'])) {
         // If logging is as default admin, ensure record is setup correctly
         $member = Member::default_admin();
         $success = Security::check_default_admin($email, $data['Password']);
         // If not already true check if one of the extra admins match
         if (!$success) {
             $success = $GLOBALS['_DEFAULT_ADMINS'][$email] == $data['Password'];
         }
         if ($success) {
             return $member;
         }
     }
     // Attempt to identify user by email
     if (!$member && $email) {
         // Find user by email
         $member = Member::get()->filter(Member::config()->unique_identifier_field, $email)->first();
     }
     // Validate against member if possible
     if ($member && !$asDefaultAdmin) {
         $result = $member->checkPassword($data['Password']);
         $success = $result->valid();
     } else {
         $result = new ValidationResult(false, _t('Member.ERRORWRONGCRED'));
     }
     // Emit failure to member and form (if available)
     if (!$success) {
         if ($member) {
             $member->registerFailedLogin();
         }
         if ($form) {
             $form->sessionMessage($result->message(), 'bad');
         }
     } else {
         if ($member) {
             $member->registerSuccessfulLogin();
         }
     }
     return $member;
 }
开发者ID:helpfulrobot,项目名称:level51-more-admins,代码行数:68,代码来源:MoreAdminsAuthenticator.php

示例2: testDefaultAdmin

 public function testDefaultAdmin()
 {
     $adminMembers = Permission::get_members_by_permission('ADMIN');
     $this->assertEquals(0, $adminMembers->count());
     $admin = Member::default_admin();
     $this->assertInstanceOf('Member', $admin);
     $this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
     $this->assertEquals($admin->Email, Security::default_admin_username());
     $this->assertNull($admin->Password);
 }
开发者ID:nickbooties,项目名称:silverstripe-framework,代码行数:10,代码来源:SecurityDefaultAdminTest.php

示例3: isDefaultAdmin

 /**
  * Check if this user is the currently configured default admin
  *
  * @return bool
  */
 public function isDefaultAdmin()
 {
     return Security::has_default_admin() && $this->Email === Security::default_admin_username();
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:9,代码来源:Member.php

示例4: default_admin

 /**
  * Get the default admin record if it exists, or creates it otherwise if enabled
  *
  * @return Member
  */
 public static function default_admin()
 {
     // Check if set
     if (!Security::has_default_admin()) {
         return null;
     }
     // Find or create ADMIN group
     singleton('Group')->requireDefaultRecords();
     $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
     // Find member
     $admin = Member::get()->filter('Email', Security::default_admin_username())->first();
     if (!$admin) {
         // 'Password' is not set to avoid creating
         // persistent logins in the database. See Security::setDefaultAdmin().
         // Set 'Email' to identify this as the default admin
         $admin = Member::create();
         $admin->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
         $admin->Email = Security::default_admin_username();
         $admin->write();
     }
     // Ensure this user is in the admin group
     if (!$admin->inGroup($adminGroup)) {
         $admin->Groups()->add($adminGroup);
     }
     return $admin;
 }
开发者ID:8secs,项目名称:cocina,代码行数:31,代码来源:Member.php

示例5: testDefaultAdmin

 /**
  * Test that the default admin can be authenticated
  */
 public function testDefaultAdmin()
 {
     // Make form
     $controller = new Security();
     $form = new Form($controller, 'Form', new FieldList(), new FieldList());
     // Test correct login
     $result = MemberAuthenticator::authenticate(array('Email' => 'admin', 'Password' => 'password'), $form);
     $this->assertNotEmpty($result);
     $this->assertEquals($result->Email, Security::default_admin_username());
     $this->assertEmpty($form->Message());
     // Test incorrect login
     $form->clearMessage();
     $result = MemberAuthenticator::authenticate(array('Email' => 'admin', 'Password' => 'notmypassword'), $form);
     $this->assertEmpty($result);
     $this->assertEquals('The provided details don't seem to be correct. Please try again.', $form->Message());
     $this->assertEquals('bad', $form->MessageType());
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:20,代码来源:MemberAuthenticatorTest.php


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