dez-php/phalcon-auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dez-php/phalcon-auth

最新稳定版本:v0.2.3

Composer 安装命令:

composer require dez-php/phalcon-auth

包简介

Auth Component for Phalcon 2 Framework

README 文档

README

Auth Component for Phalcon 2.x Framework

#Usage

Register Auth in dependency injection container

include_once '../vendor/autoload.php';

$container  = new \Phalcon\Di\FactoryDefault();

$container->set('auth', function(){
    
    // Pass session adapter into Auth
    $auth   = new \PhalconDez\Auth\Auth(
        new \PhalconDez\Auth\Adapter\Session()
    );
    
    // Pass empty instance of Credentials Model implement PhalconModel
    $auth->setCredentialsModel(
        new \PhalconDez\Auth\Model\Credentials()
    );
    
    // Pass empty instance of Session Model implement PhalconModel
    $auth->setSessionModel(
        new \PhalconDez\Auth\Model\Session()
    );
    
    // Run initialize
    $auth->initialize();
    
    return $auth;
});

and then fetch auth from container

/** @var \PhalconDez\Auth\Auth $auth */
$auth   = $container->get('auth');

authorization

try{
    $auth->authenticate('test@gmail.com', 'qwerty');
}catch (\Exception $e){
    echo "You have some errors: {$e->getMessage()}";
}

creating new credentials

try{
    $auth->authenticate($email, $password);
}catch (\Exception $e){
    $auth->create($email, $password);
    $container->get('response')->redirect('auth-page');
}

verify password

if($auth->isUser() && $auth->getAdapter()->verifyPassword('qwerty') === true){
    echo 'Password is corrected';
}

check user user authorization

if($auth->isGuest() === true){
    echo 'You are non-authorized user';
}

if($auth->isUser() === true){
    echo 'You are authorized user';
}

get some authorized user data

if($auth->isUser() === true){
    $userModel  = $auth->getUser();
    echo "Hello, {$userModel->getEmail()}. You was registered at {$userModel->getCreatedAt()}";
}

#Issues and pull-request

####I will be glad of your criticism, tasks, bugs and pull-request.

统计信息

  • 总下载量: 179
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-08