added first steps in docs
This commit is contained in:
76
docs/helpful-guides/first-steps.md
Normal file
76
docs/helpful-guides/first-steps.md
Normal file
@ -0,0 +1,76 @@
|
||||
first steps to work with Yii2-usuario
|
||||
=====================================
|
||||
|
||||
After installing the extension and having configured everything, you need setup your application with the all the user related stuff, e.g.
|
||||
|
||||
* creating first users, roles, permissions, ...
|
||||
* assigning permissions and roles to users
|
||||
* extending your controllers with access restrictions
|
||||
* starting user management
|
||||
|
||||
## Creating your first user
|
||||
|
||||
There are several ways to do that:
|
||||
|
||||
* using migrations
|
||||
* using the Command line (-> installation description)
|
||||
|
||||
### Creating the first Administrator during a migration
|
||||
|
||||
This is helpful e.g. when using you Yii2 applicatio with Docker and need to start the Docker Container with basic user settings.
|
||||
|
||||
We will create an ```admin```user with a ```adminisrator``` role.
|
||||
|
||||
Put this in your migration:
|
||||
|
||||
class m... extends Migration
|
||||
{
|
||||
public function safeUp()
|
||||
{
|
||||
$auth = Yii::$app->authManager;
|
||||
|
||||
// create a role named "administrator"
|
||||
$administratorRole = $auth->createRole('administrator');
|
||||
$administratorRole->description = 'Administrator';
|
||||
$auth->add($administratorRole);
|
||||
|
||||
// create user "admin" with password "verysecret"
|
||||
$user = new \Da\User\Model\User([
|
||||
'scenario' => 'create',
|
||||
'email' => "email@example.com",
|
||||
'username' => "admin",
|
||||
'password' => "verysecret" // >6 characters!
|
||||
]);
|
||||
$user->confirmed_at = time();
|
||||
$user->save();
|
||||
|
||||
// assign role to our admin-user
|
||||
$auth->assign($administratorRole, $user->id);
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
$auth = Yii::$app->authManager;
|
||||
|
||||
// delete admin-user and administrator role
|
||||
$administratorRole = $auth->getRole("xw-administrator");
|
||||
$user = \Da\User\Model\User::findOne(['name'=>"admin"]);
|
||||
$auth->revoke($administratorRole, $user->id);
|
||||
$user->delete();
|
||||
}
|
||||
|
||||
## User Management
|
||||
|
||||
Having setup the ```admin``` user you can start using user management at
|
||||
|
||||
http://yourapp/index.php?r=user/admin
|
||||
|
||||
You should be prompted a login screen and the enter ```admin/verysecret```.
|
||||
|
||||
### Recommended Reading
|
||||
|
||||
It is helpful to basically understand how Yii2 does authantication. The you can get in Yii2-usuario more quickly.
|
||||
|
||||
- [The Definitive Guide to Yii 2.0: Authentication](https://www.yiiframework.com/doc/guide/2.0/en/security-authentication)
|
||||
|
||||
|
||||
@ -146,6 +146,11 @@ See also all the possible configuration options available:
|
||||
- [Available Actions](installation/available-actions.md)
|
||||
- [Migration guide from Dektrium tools](installation/migration-guide-from-dektrium-tools.md)
|
||||
|
||||
#### Step 4 - First steps to use Yii2-usuario
|
||||
|
||||
Proceed with [First steps to use Yii2-usuario](helpful-guides/first-steps.md)
|
||||
|
||||
|
||||
Enhancing and Overriding
|
||||
------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user