src/security/ExternalLoginMember.php
public function requireDefaultRecords()
    {
        parent::requireDefaultRecords();

        $ssLoginUserName = Environment::getEnv('SS_DEFAULT_ADMIN_USERNAME');
        if(!$ssLoginUserName){
            return;
        }

        // Check for default admin user by matching email
        $member = Member::get()->find(
            Member::config()->get('unique_identifier_field'),
            $ssLoginUserName
        );

        // If no member is found at this stage.
        // Find member ID 1
        if(!$member){
            $member = DataObject::get_by_id(Member::class, 1);
        }

        $firstName = 'Default Admin';

        // // If there isn't one then make it
        if(!$member){
            $member = ExternalLoginMember::create();
            $member->FirstName = $firstName;
            $member->Email = $ssLoginUserName;
            $member->write();
            DB::alteration_message("Created admin '$member->Email'", 'created');
        } else {
            if ($member->ClassName != $this->ClassName || $member->Email != $ssLoginUserName) {
                $member->ClassName = $this->ClassName;
                $member->FirstName = $firstName;
                $member->Surname = null;
                $member->Email = $ssLoginUserName;
                $member->TempIDHash = null;
                $member->TempIDExpired = null;
                $member->Password = null;
                $member->write();
                DB::alteration_message("Modified admin '$member->Email'", 'modified');
            }
        }

        // Find or create ADMIN group
        Group::singleton()->requireDefaultRecords();
        $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();

        // Ensure this user is in the admin group
        if(!$member->inGroup($adminGroup)) {
            // Add member to group instead of adding group to member
            // This bypasses the privilege escallation code in Member_GroupSet
            $adminGroup->DirectMembers()->add($member);
        }
    }
public function requireDefaultRecords()
    {
        parent::requireDefaultRecords();

        $ssLoginUserName = Environment::getEnv('SS_DEFAULT_ADMIN_USERNAME');
        if(!$ssLoginUserName){
            return;
        }

        // Check for default admin user by matching email
        $member = Member::get()->find(
            Member::config()->get('unique_identifier_field'),
            $ssLoginUserName
        );

        // If no member is found at this stage.
        // Find member ID 1
        if(!$member){
            $member = DataObject::get_by_id(Member::class, 1);
        }

        $firstName = 'Default Admin';

        // // If there isn't one then make it
        if(!$member){
            $member = ExternalLoginMember::create();
            $member->FirstName = $firstName;
            $member->Email = $ssLoginUserName;
            $member->write();
            DB::alteration_message("Created admin '$member->Email'", 'created');
        } else {
            if ($member->ClassName != $this->ClassName || $member->Email != $ssLoginUserName) {
                $member->ClassName = $this->ClassName;
                $member->FirstName = $firstName;
                $member->Surname = null;
                $member->Email = $ssLoginUserName;
                $member->TempIDHash = null;
                $member->TempIDExpired = null;
                $member->Password = null;
                $member->write();
                DB::alteration_message("Modified admin '$member->Email'", 'modified');
            }
        }

        // Find or create ADMIN group
        Group::singleton()->requireDefaultRecords();
        $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();

        // Ensure this user is in the admin group
        if(!$member->inGroup($adminGroup)) {
            // Add member to group instead of adding group to member
            // This bypasses the privilege escallation code in Member_GroupSet
            $adminGroup->DirectMembers()->add($member);
        }
    }
public function requireDefaultRecords ( ) { parent :: requireDefaultRecords ( ) ; $ ssLoginUserName = Environment :: getEnv ( 'SS_DEFAULT_ADMIN_USERNAME' ) ; if ( ! $ ssLoginUserName ) { return ; } // Check for default admin user by matching email $ member = Member :: get ( ) -> find ( Member :: config ( ) -> get ( 'unique_identifier_field' ) , $ ssLoginUserName ) ; // If no member is found at this stage. // Find member ID 1 if ( ! $ member ) { $ member = DataObject :: get_by_id ( Member :: class , 1 ) ; } $ firstName = 'Default Admin' ; // // If there isn't one then make it if ( ! $ member ) { $ member = ExternalLoginMember :: create ( ) ; $ member -> FirstName = $ firstName ; $ member -> Email = $ ssLoginUserName ; $ member -> write ( ) ; DB :: alteration_message ( "Created admin '$member->Email'" , 'created' ) ; } else { if ( $ member -> ClassName != $ this -> ClassName || $ member -> Email != $ ssLoginUserName ) { $ member -> ClassName = $ this -> ClassName ; $ member -> FirstName = $ firstName ; $ member -> Surname = null ; $ member -> Email = $ ssLoginUserName ; $ member -> TempIDHash = null ; $ member -> TempIDExpired = null ; $ member -> Password = null ; $ member -> write ( ) ; DB :: alteration_message ( "Modified admin '$member->Email'" , 'modified' ) ; } } // Find or create ADMIN group Group :: singleton ( ) -> requireDefaultRecords ( ) ; $ adminGroup = Permission :: get_groups_by_permission ( 'ADMIN' ) -> First ( ) ; // Ensure this user is in the admin group if ( ! $ member -> inGroup ( $ adminGroup ) ) { // Add member to group instead of adding group to member // This bypasses the privilege escallation code in Member_GroupSet $ adminGroup -> DirectMembers ( ) -> add ( $ member ) ; } }
Set up default default admin record
Set up default default admin record