Esempio n. 1
0
 public function actionInit()
 {
     //roles
     //user admin psychologist school
     $auth = Yii::$app->authManager;
     //$user = $auth->createRole('user');
     $adminUser = new User();
     $adminUser->email = '*****@*****.**';
     $adminUser->setPassword('123456');
     $adminUser->generateAuthKey();
     $adminUser->save();
     $admin = $auth->createRole('admin');
     $auth->add($admin);
     $averageUser = new User();
     $averageUser->email = '*****@*****.**';
     $averageUser->setPassword('123456');
     $averageUser->generateAuthKey();
     $averageUser->save();
     $profile = new Profile();
     $model = new SignupForm();
     $model->first_name = "Юзер";
     $model->last_name = "Юзерович";
     $model->second_name = "Юзеров";
     $profile->initProfile($model, $averageUser->id);
     $user = $auth->createRole('user');
     $auth->add($user);
     /*        $accessAdmin = $auth->createPermission('accessAdmin');
               $accessAdmin->description = 'Access admin';
               $auth->add($accessAdmin);
               $auth->addChild($admin, $accessAdmin);*/
     //$psychologist = $auth->createRole('psychologist');
     /*// add "createPost" permission
             $createPost = $auth->createPermission('createPost');
             $createPost->description = 'Create a post';
             $auth->add($createPost);
     
             // add "updatePost" permission
             $updatePost = $auth->createPermission('updatePost');
             $updatePost->description = 'Update post';
             $auth->add($updatePost);
     
             // add "author" role and give this role the "createPost" permission
             $author = $auth->createRole('author');
             $auth->add($author);
             $auth->addChild($author, $createPost);
     
             // add "admin" role and give this role the "updatePost" permission
             // as well as the permissions of the "author" role
             $admin = $auth->createRole('admin');
             $auth->add($admin);
             $auth->addChild($admin, $updatePost);
             $auth->addChild($admin, $author);
     
             // Assign roles to users. 1 and 2 are IDs returned by IdentityInterface::getId()
             // usually implemented in your User model.
             $auth->assign($author, 2);*/
     $auth->assign($admin, 1);
     $auth->assign($user, 2);
 }
Esempio n. 2
0
 public function actionSignup()
 {
     $model = new SignupForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($user = $model->signup()) {
             $profile = new Profile();
             if ($profile->initProfile($model, $user->id)) {
                 if (Yii::$app->getUser()->login($user)) {
                     return $this->goHome();
                 }
             }
         }
     }
     return $this->render('signup', ['model' => $model]);
 }