protected function generateUsername()
    {
        $userNameField = Podium::getInstance()->userNameField;
        if ($userNameField !== null) {
            if (empty(Podium::getInstance()->user->identity->$userNameField)) {
                throw new InvalidConfigException("Non-existing or empty '$userNameField' field!");
            }
            $username = Podium::getInstance()->user->identity->$userNameField;
        } else {
            $try = 0;
            do {
                $username = 'user_' . time() . mt_rand(1000, 9999);
                if ($try++ > 10) {
                    throw new Exception('Failed to generate unique username!');
                }
            } while ((new Query)->from(static::tableName())->where(['username' => $username])->exists());
        }
        $this->username = $username;
    }
protected function generateUsername()
    {
        $userNameField = Podium::getInstance()->userNameField;
        if ($userNameField !== null) {
            if (empty(Podium::getInstance()->user->identity->$userNameField)) {
                throw new InvalidConfigException("Non-existing or empty '$userNameField' field!");
            }
            $username = Podium::getInstance()->user->identity->$userNameField;
        } else {
            $try = 0;
            do {
                $username = 'user_' . time() . mt_rand(1000, 9999);
                if ($try++ > 10) {
                    throw new Exception('Failed to generate unique username!');
                }
            } while ((new Query)->from(static::tableName())->where(['username' => $username])->exists());
        }
        $this->username = $username;
    }
protected function generateUsername ( ) { $ userNameField = Podium :: getInstance ( ) -> userNameField ; if ( $ userNameField !== null ) { if ( empty ( Podium :: getInstance ( ) -> user -> identity -> $ userNameField ) ) { throw new InvalidConfigException ( "Non-existing or empty '$userNameField' field!" ) ; } $ username = Podium :: getInstance ( ) -> user -> identity -> $ userNameField ; } else { $ try = 0 ; do { $ username = 'user_' . time ( ) . mt_rand ( 1000 , 9999 ) ; if ( $ try ++ > 10 ) { throw new Exception ( 'Failed to generate unique username!' ) ; } } while ( ( new Query ) -> from ( static :: tableName ( ) ) -> where ( [ 'username' => $ username ] ) -> exists ( ) ) ; } $ this -> username = $ username ; }
Generates username for inherited account.
@throws Exception
@since 0.7
Generates username for inherited account .