/** * send invitation/password reset to user email and redirect ot view with message * */ public function actionEmailInvitation() { //generate password $password = DbrLib::rand_string(8); //save password $model = $this->loadModel(); $model->password = Yii::app()->controller->module->encrypting($password); $model->save(); //message $subject = Yii::app()->name; $message = 'For access to system please use. <br /> link: ' . Yii::app()->getBaseUrl(true) . '/<br /> username: <b>' . $model->username . '</b>, password:<b> ' . $password . '</b>'; Yii::import('vendor.dbrisinajumi.d2mailer.components.*'); $d2mailer = new d2mailer(); if ($d2mailer->sendMailToUser($model->id, $subject, $message) === false) { $this->redirect(array('view', 'id' => $model->id, 'sent' => 'error')); } else { $this->redirect(array('view', 'id' => $model->id, 'sent' => 'ok')); } // //create message // $swiftMessage = Swift_Message::newInstance($subject); // $swiftMessage->setBody($message, 'text/html'); // $swiftMessage->setFrom(Yii::app()->emailManager->fromEmail, Yii::app()->emailManager->fromName); // $swiftMessage->setTo($model->email, $model->profile->first_name . ' ' . $model->profile->last_name); // // //send // if(Yii::app()->emailManager->deliver($swiftMessage, 'smtp')){ // //redirecto view as ok // $this->redirect(array('view','id'=>$model->id,'sent' => 'ok')); // }else{ // //redirecto view as error // $this->redirect(array('view','id'=>$model->id,'sent' => 'error')); // } }
/** * create user account from person data * @return boolean|array - error */ public function createUser() { $password = DbrLib::rand_string(8); /** * create username */ $firstName = strtolower(self::translitStringToAscii($this->pprs_first_name)); $secondName = strtolower(self::translitStringToAscii($this->pprs_second_name)); $username = $firstName . substr($secondName, 0, 1); $i = 1; while (User::model()->findByAttributes(['username' => $username])) { $i++; if ($i > strlen($secondName)) { $username = $firstName . DbrLib::rand_string(2); } $username = $firstName . substr($secondName, 0, $i); } /** * get email from person contacts */ $contacts = $this->ppcnPersonContacts; $email = ''; foreach ($contacts as $contact) { if ($contact->ppcn_pcnt_type == PcntContactType::TYPE_EMAIL) { $email = trim($contact->ppcn_value); } } /** * create user record */ $user = new User(); $user->username = $username; $user->password = $password; $user->email = $email; $user->status = User::STATUS_ACTIVE; if (!$user->validate()) { return CHtml::errorSummary($user); } $user->save(); /** * create profile record */ $profile = new Profile(); $profile->user_id = $user->id; $profile->first_name = $this->pprs_first_name; $profile->last_name = $this->pprs_second_name; $profile->sys_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); $profile->person_id = $this->primaryKey; $profile->save(); return true; }
<?php $this->widget('TbMenu', array('type' => 'tabs', 'items' => DbrLib::getRangeMenuArray($model->dol_date_range, 'RememberBfrfFuelRefill[bcbd_date_range]')));