PHP code example of californiamountainsnake / longmantelegrambot-laravel-api-auth-system

1. Go to this page and download the library: Download californiamountainsnake/longmantelegrambot-laravel-api-auth-system library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

californiamountainsnake / longmantelegrambot-laravel-api-auth-system example snippets



class BaseCommand extends Command {
    use AuthBotAccessUtils;
    use AuthApiUtils;
    use AuthUserUtils;
    
    /**
     * Get user's entity. Just specify return type hint.
     * @return UserEntity|null
     */
    protected function getUserEntity(): ?AuthUserEntity
    {
        return $this->userUtilsGetUserEntity();
    }

    /**
     * Get user's role. Just specify return type hint.
     * @return UserRoleEnum
     */
    protected function getUserRole(): AuthUserRoleEnum
    {
        return $this->userUtilsGetUserRole();
    }

    /**
     * Get user's account type. Just specify return type hint.
     * @return UserAccountTypeEnum
     */
    protected function getUserAccountType(): AuthUserAccountTypeEnum
    {
        return $this->userUtilsGetUserAccountType();
    }
}


class BaseCommand extends Command {
    use AuthBotAccessUtils;
    use AuthApiUtils;
    use AuthUserUtils;
    
    public function preExecute(): ServerResponse
    {
        $this->initTelegramParams();
        $this->reInitUserParams();

        try {
            // If user try to execute a wrong command, the exception will throw.
            $this->assertUserHasAccessToMainRoute($this->getUserEntity());
            
            return parent::preExecute();
        } catch (ApiProxyException $e) {
            // handle the error!
        } catch (UserRoleNotEqualsException $e) {
            // handle the error!
        } catch (UserAccountTypeNotEqualsException $e) {
            // handle the error!
        } catch (\Throwable $t) {
            // A good idea is to handle other exceptions.
        }
    }
}


class MyCommand extends BaseCommand {
    
    public function execute (): ServerResponse {
        $json = $this->callApiNotAuth($this->getMainRoute(), [
            'email' => '[email protected]',
        ])->getContent();
    }
}