Usr provides basic user actions like:
Advanced features:
See the demo.
php composer.phar require nineinchnick/yii2-usr "dev-master"
OR add to composer.json require section "nineinchnick/yii2-usr": "dev-master"
Example config (see Module.php file for full options reference):
$config = [
// .........
'aliases' => [
'@nineinchnick/usr' => '@vendor/nineinchnick/yii2-usr',
],
'modules' => [
'usr' => [
'class' => 'nineinchnick\usr\Module',
],
],
'components' => [
'user' => [
'identityClass' => 'app\models\User',
'loginUrl' => ['usr/login'],
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => YII_DEBUG,
'messageConfig' => [
'from' => 'noreply@yoursite.com',
],
],
// ..........
],
]
Requirements for the identity (User) class are described in next chapter.
To be able to use all features of the Usr module, the identity (User) class must implement some or all of the following interfaces.
This interface allows to create new identities (register) and update existing ones.
This interface allows:
Remember to invalidate the email if it changes in the save() method from the Editable interface.
This interface allows password reset with optional tracking of used passwords. This allows to detect expired passwords and avoid reusing old passwords by users.
See the ExpiredPasswordBehavior description below.
This interface allows finding local identity associated with a remote one (from an external social site) and creating such associations.
This interface allow saving and retrieving a secret used to generate one time passwords. Also, last used password and counter used to generate last password are saved and retrieve to protect against reply attacks.
See the OneTimePasswordFormBehavior description below.
Allows users to upload a profile picture. The example identity uses Gravatar to provide a default picture.
Allows to manage users:
The login action can be extended by attaching custom behaviors to the LoginForm. This is done by configuring the UsrModule.loginFormBehaviors property.
There are two such behaviors provided by yii-usr module:
Validates if current password has expired and forces the users to change it before logging in.
Options:
Two step authentication using one time passwords.
Options:
'loginFormBehaviors' => array(
'expiredPasswordBehavior' => array(
'class' => 'ExpiredPasswordBehavior',
'passwordTimeout' => 10,
),
'oneTimePasswordBehavior' => array(
'class' => 'OneTimePasswordFormBehavior',
'mode' => OneTimePasswordFormBehavior::OTP_TIME,
'required' => true,
'timeout' => 123,
),
// ... other behaviors
),
A sample ExampleUser and ExampleUserUsedPassword models along with database migrations are provided respectively in the 'models' and 'migrations' folders.
They could be used as-is by extending from or copying to be modified to better suit a project.
To use the provided migrations it's best to copy them to your migrations directory and adjust the filenames and classnames to current date and time. Also, they could be modified to remove not needed features.
A simple implementation of a Diceware Passphrase generator is provided to aid users when they need to create a good, long but also easy to remember passphrase.
Install the nineinchnick/diceware
composer package to use it.
Read more at the Diceware Passphrase homepage.
Varios scenarios can be created by enabling or disabling following features:
Implementing those scenarios require some logic outside the scope of this module.
Users can register by themselves. Their accounts are activated instantly or after verifying email.
Users can register, but to allow them to log in an administrator must activate their accounts manually, optionally assigning an authorization profile. Email verification is optional and activation could trigger an email notification.
MIT or BSD