Exemplo n.º 1
0
 public function register()
 {
     $user = new User();
     $user->first_name = $this->first_name;
     $user->last_name = $this->last_name;
     $user->email = $this->email;
     $user->position = $this->position;
     $user->phone = $this->phone;
     $user->password = $this->password;
     $user->username = $this->username;
     $user->role = User::ROLE_EMPL;
     $user->status = User::STATUS_DISABLED;
     $user->additional_contact = $this->additional_contact;
     $user->hash = md5(microtime(true) . rand());
     if (!$user->save()) {
         $this->addError('username', 'Can`t create user ' . serialize($user->getErrors()));
         return false;
     }
     UserHelper::sendEmailConfirmation($user);
     $company = new Company();
     $company->name = $this->name;
     $company->site_url = $this->site_url;
     $company->address = $this->address;
     $company->created_at = new CDbExpression('NOW()');
     $company->updated_at = new CDbExpression('NOW()');
     if (!$company->save()) {
         $this->addError('name', 'Can`t create company ' . serialize($company->getErrors()));
         return false;
     }
     $bind = new UserToCompany();
     $bind->user_id = $user->id;
     $bind->company_id = $company->id;
     if (!$bind->save()) {
         $this->addError('name', 'Can`t bind company ' . serialize($bind->getErrors()));
         return false;
     }
     return true;
 }