コード例 #1
0
 /**
  * Зарегистрировать
  */
 public function executeCreate(sfWebRequest $request)
 {
     $this->executeSignup();
     $this->form->bind($request->getParameter($this->form->getName()));
     if ($this->form->isValid()) {
         $user = $this->form->save();
         $loginzaData = $this->getUser()->getAttribute('loginza.identity', false, 'loginza');
         // связываем юзера с идентификатором
         $identity = new Identity();
         $identity->setIdentity($loginzaData['identity']);
         $identity->setProvider($loginzaData['provider']);
         $identity->setUser($user);
         $identity->save();
         $this->getUser()->setAttribute('identity.id', $identity->getId());
         // авторизуем
         $this->getUser()->signin($user, true);
     }
     if (!$this->form->hasErrors()) {
         if ($request->isXmlHttpRequest()) {
             return $this->renderText("<script type='text/javascript'>window.location.href='/';</script>");
         } else {
             return $this->redirect('homepage');
         }
     }
     $this->setTemplate('signup');
 }
コード例 #2
0
 public function getSave()
 {
     $id = Input::get('id');
     if ($id) {
         $identity = Identity::find($id);
         $identity->name = Input::get('name');
         $identity->save();
         Session::flash('message', 'The records are updated successfully');
     } else {
         $identity = new Identity();
         $identity->name = Input::get('name');
         $identity->save();
         Session::flash('message', 'The records are inserted successfully');
     }
     return Redirect::to('identity');
 }
コード例 #3
0
ファイル: UserRegistration.php プロジェクト: vasiliy-pdk/aes
 public function run()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         if ($this->data->validate()) {
             $user = new UserAccount();
             $user->setPassword($this->data->password);
             $user->status = UserAccount::STATUS_NEED_ACTIVATION;
             if (!$user->save()) {
                 throw new Exception("User registration failed. Cant save User row. Errors: " . var_export($user->getErrors(), true));
             }
             $identity = new Identity();
             $identity->user_id = $user->id;
             $identity->type = Identity::TYPE_EMAIL;
             $identity->status = Identity::STATUS_NEED_CONFIRMATION;
             $identity->identity = $this->data->email;
             if (!$identity->save()) {
                 throw new Exception("User registration failed. Can't save Identity. Errors: " . var_export($identity->getErrors(), true));
             }
             $profile = new Profile();
             $attributeNames = $profile->attributeNames();
             $attributes = $this->data->getAttributes($attributeNames);
             $profile->setAttributes($attributes, false);
             $profile->user_id = $user->id;
             if (!$profile->save()) {
                 throw new Exception("User registration failed. Can't save Profile. Errors: " . var_export($profile->getErrors(), true));
             }
             $this->afterRecordsCreated($user, $profile, $identity);
         } else {
             throw new Exception("Invalid registration data. Errors: " . var_export($this->data->getErrors(), true));
         }
     } catch (Exception $exc) {
         $transaction->rollback();
         throw $exc;
     }
     $transaction->commit();
     return true;
 }