diff --git a/docs/helpful-guides/first-steps.md b/docs/helpful-guides/first-steps.md new file mode 100644 index 0000000..696831d --- /dev/null +++ b/docs/helpful-guides/first-steps.md @@ -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) + + diff --git a/docs/index.md b/docs/index.md index dff4e43..3b55242 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 ------------------------