Ejemplo n.º 1
0
 /**
  * Registers a new user account.
  * @return bool
  */
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user->setAttributes(['email' => $this->email, 'username' => $this->username, 'password' => $this->password]);
     return $this->user->register();
 }
 /**
  * Creates a new SocialServiceManager model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new SocialServiceManager();
     if ($model->load(Yii::$app->request->post())) {
         $person = new Person();
         $person->name = $model->name;
         $person->lastname = $model->last_name;
         $person->phone = $model->phone;
         $person->save(false);
         $user = new User();
         $user->username = $model->username;
         $user->password = $model->password;
         $user->email = $model->email;
         $user->person_id = $person->id;
         $user->scenario = 'register';
         if ($user->validate(['username', 'password'])) {
             $user->register();
             $model->user_id = $user->id;
             $model->save(false);
             //assign the role to the user
             $authManager = Yii::$app->getAuthManager();
             $socialServiceMRole = $authManager->getRole('socialServiceManager');
             $authManager->assign($socialServiceMRole, $user->id);
             //set the success message
             Yii::$app->getSession()->setFlash('success', 'Usuario creado con éxito');
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             $model->addErrors($user->errors);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 3
0
 public function testRegister()
 {
     $this->specify('user should be registered', function () {
         $user = new User(['scenario' => 'register']);
         $user->username = '******';
         $user->email = '*****@*****.**';
         $user->password = '******';
         verify($user->register())->true();
         verify($user->username)->equals('tester');
         verify($user->email)->equals('*****@*****.**');
         verify(Yii::$app->getSecurity()->validatePassword('tester', $user->password_hash))->true();
     });
     $this->specify('profile should be created after registration', function () {
         $user = new User(['scenario' => 'register']);
         $user->username = '******';
         $user->email = '*****@*****.**';
         $user->password = '******';
         verify($user->register())->true();
         verify($user->profile->gravatar_email)->equals('*****@*****.**');
     });
 }
Ejemplo n.º 4
0
 public function register()
 {
     return parent::register();
     // do your magic
 }