first commit
This commit is contained in:
43
lib/User/Bootstrap.php
Normal file
43
lib/User/Bootstrap.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace Da\User;
|
||||
|
||||
use Da\User\Helper\AuthHelper;
|
||||
use Da\User\Query\AccountQuery;
|
||||
use Da\User\Query\ProfileQuery;
|
||||
use Da\User\Query\TokenQuery;
|
||||
use Da\User\Query\UserQuery;
|
||||
use yii\base\Application;
|
||||
use yii\base\BootstrapInterface;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
*
|
||||
* Bootstrap.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:13
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class Bootstrap implements BootstrapInterface
|
||||
{
|
||||
public function bootstrap($app)
|
||||
{
|
||||
if($app->hasModule('user') && $app->getModule('user') instanceof Module) {
|
||||
|
||||
// configure yii's container
|
||||
$this->setContainer();
|
||||
}
|
||||
}
|
||||
|
||||
protected function setContainer()
|
||||
{
|
||||
// helpers
|
||||
Yii::$container->set(AuthHelper::class);
|
||||
|
||||
// active query classes
|
||||
Yii::$container->set(AccountQuery::class);
|
||||
Yii::$container->set(ProfileQuery::class);
|
||||
Yii::$container->set(TokenQuery::class);
|
||||
Yii::$container->set(UserQuery::class);
|
||||
}
|
||||
}
|
||||
33
lib/User/Helper/AuthHelper.php
Normal file
33
lib/User/Helper/AuthHelper.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Da\User\Helper;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
*
|
||||
* RoleHelper.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:11
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class AuthHelper
|
||||
{
|
||||
/**
|
||||
* Checks whether
|
||||
*
|
||||
* @param $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRole($userId, $role)
|
||||
{
|
||||
if (Yii::$app->authManager) {
|
||||
$roles = array_keys(Yii::$app->authManager->getRolesByUser($userId));
|
||||
|
||||
return in_array($role, $roles, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
53
lib/User/Model/User.php
Normal file
53
lib/User/Model/User.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Da\User\Model;
|
||||
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\web\IdentityInterface;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* User ActiveRecord model.
|
||||
*
|
||||
* @property bool $isAdmin
|
||||
* @property bool $isBlocked
|
||||
* @property bool $isConfirmed
|
||||
*
|
||||
* Database fields:
|
||||
* @property integer $id
|
||||
* @property string $username
|
||||
* @property string $email
|
||||
* @property string $password_hash
|
||||
* @property string $auth_key
|
||||
* @property integer $registration_ip
|
||||
* @property integer $confirmed_at
|
||||
* @property integer $blocked_at
|
||||
* @property integer $created_at
|
||||
* @property integer $updated_at
|
||||
*
|
||||
* Defined relations:
|
||||
* @property Account[] $accounts
|
||||
* @property Profile $profile
|
||||
*/
|
||||
class User extends ActiveRecord implements IdentityInterface
|
||||
{
|
||||
/** @var string Plain password. Used for model validation. */
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* @return bool whether is blocked or not.
|
||||
*/
|
||||
public function getIsBlocked()
|
||||
{
|
||||
return $this->blocked_at !== null;
|
||||
}
|
||||
|
||||
public function getIsAdmin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function hasRole($role)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
50
lib/User/Module.php
Normal file
50
lib/User/Module.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Da\User;
|
||||
|
||||
/**
|
||||
*
|
||||
* Module.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:15
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class Module extends \yii\base\Module
|
||||
{
|
||||
public $token
|
||||
/**
|
||||
* @var int the time before a recovery token is invalid. Defaults to 6 hours.
|
||||
*/
|
||||
public $tokenRecoveryWithin = 21600;
|
||||
/**
|
||||
* @var array a list of admin usernames
|
||||
*/
|
||||
public $administrators = [];
|
||||
/**
|
||||
* @var string the administrator permission name
|
||||
*/
|
||||
public $administratorPermissionName;
|
||||
/**
|
||||
* @var array the class map used by the module.
|
||||
*
|
||||
* @see Bootstrap
|
||||
*/
|
||||
public $classmap = [];
|
||||
/**
|
||||
* @var string the route prefix
|
||||
*/
|
||||
public $prefix = 'user';
|
||||
|
||||
/**
|
||||
* @var array the url rules (routes)
|
||||
*/
|
||||
public $routes = [
|
||||
'<id:\d+>' => 'profile/show',
|
||||
'<action:(login|logout)>' => 'security/<action>',
|
||||
'<action:(register|resend)>' => 'registration/<action>',
|
||||
'confirm/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'registration/confirm',
|
||||
'forgot' => 'recovery/request',
|
||||
'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset',
|
||||
'settings/<action:\w+>' => 'settings/<action>'
|
||||
];
|
||||
}
|
||||
15
lib/User/Query/AccountQuery.php
Normal file
15
lib/User/Query/AccountQuery.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Da\User\Query;
|
||||
|
||||
/**
|
||||
*
|
||||
* AccountQuery.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:23
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class AccountQuery
|
||||
{
|
||||
|
||||
}
|
||||
15
lib/User/Query/ProfileQuery.php
Normal file
15
lib/User/Query/ProfileQuery.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Da\User\Query;
|
||||
|
||||
/**
|
||||
*
|
||||
* ProfileQuery.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:23
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class ProfileQuery
|
||||
{
|
||||
|
||||
}
|
||||
15
lib/User/Query/TokenQuery.php
Normal file
15
lib/User/Query/TokenQuery.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Da\User\Query;
|
||||
|
||||
/**
|
||||
*
|
||||
* TokenQuery.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:23
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class TokenQuery
|
||||
{
|
||||
|
||||
}
|
||||
15
lib/User/Query/UserQuery.php
Normal file
15
lib/User/Query/UserQuery.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Da\User\Query;
|
||||
|
||||
/**
|
||||
*
|
||||
* UserQuery.php
|
||||
*
|
||||
* Date: 3/12/16
|
||||
* Time: 15:22
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class UserQuery
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user