Exemplo n.º 1
0
 public function login()
 {
     if ($this->validate()) {
         $user = $this->user;
         $user->lastLoginAt = DateUtil::getDateTime();
         $user->save();
         return Yii::$app->user->login($user, 0);
     }
     return false;
 }
 public static function createForOrderId($orderId, $payment)
 {
     // Set Attributes
     $user = Yii::$app->user->getIdentity();
     $txn = new PaypalTransaction();
     $txn->createdBy = $user->id;
     $txn->parentId = $orderId;
     $txn->parentType = CartGlobal::TYPE_ORDER;
     $txn->intent = $payment->intent;
     $txn->code = $payment->getId();
     $txn->createdAt = DateUtil::getDateTime();
     $txn->save();
     return $txn;
 }
 function register($googleUser)
 {
     $user = new User();
     $date = DateUtil::getDateTime();
     $user->email = $googleUser->email;
     $user->firstName = $googleUser->given_name;
     $user->lastName = $googleUser->family_name;
     $user->newsletter = 0;
     $user->registeredAt = $date;
     $user->status = User::STATUS_ACTIVE;
     $user->generateVerifyToken();
     $user->generateAuthKey();
     $user->save();
     return $user;
 }
 public static function create($orderId, $code, $type, $mode, $amount, $message)
 {
     // Set Attributes
     $user = Yii::$app->user->getIdentity();
     $transaction = new OrderTransaction();
     $transaction->createdBy = $user->id;
     $transaction->orderId = $orderId;
     $transaction->code = $code;
     $transaction->type = $type;
     $transaction->mode = $mode;
     $transaction->amount = $amount;
     $transaction->description = $message;
     $transaction->createdAt = DateUtil::getDateTime();
     $transaction->save();
     // Return OrderTransaction
     return $transaction;
 }
Exemplo n.º 5
0
 /**
  * The method process the submitted form and save all the form fields except captcha field.
  */
 public function processFormSubmit($form)
 {
     $date = DateUtil::getDateTime();
     $attributes = parent::getFormAttributes();
     $fields = $attributes['fields'];
     $attribs = [];
     $user = Yii::$app->user->getIdentity();
     $formSubmit = new FormSubmit();
     $formSubmit->formId = $form->id;
     $formSubmit->submittedAt = $date;
     if (isset($user)) {
         $formSubmit->submittedBy = $user->id;
     }
     // Collect fields to save in json format
     foreach ($fields as $field) {
         $fieldName = $field->name;
         // Convert CheckBox array to csv
         if ($field->isCheckboxGroup()) {
             $this->{$fieldName} = join(",", $this->{$fieldName});
         }
         if ($field->compress) {
             $attribs[$field->name] = $this->{$fieldName};
         }
     }
     $formSubmit->data = json_encode($attribs);
     // save form submit
     $formSubmit->save();
     // Get Form Submit Id
     $formSubmitId = $formSubmit->id;
     // Save Form Fields
     foreach ($fields as $field) {
         if (!$field->compress) {
             $formSubmitField = new FormSubmitField();
             $formSubmitField->formSubmitId = $formSubmitId;
             $formSubmitField->name = $field->name;
             $fieldName = $field->name;
             $formSubmitField->value = $this->{$fieldName};
             $formSubmitField->save();
         }
     }
     return $formSubmit;
 }
Exemplo n.º 6
0
 /**
  * The method registers website users and set their status to new at start. It also generate verification token.
  * @param RegisterForm $registerForm
  * @return User
  */
 public static function register($registerForm)
 {
     $user = new User();
     $date = DateUtil::getDateTime();
     $user->email = $registerForm->email;
     $user->username = $registerForm->username;
     $user->firstName = $registerForm->firstName;
     $user->lastName = $registerForm->lastName;
     $user->newsletter = $registerForm->newsletter;
     $user->registeredAt = $date;
     $user->status = User::STATUS_NEW;
     $user->generatePassword($registerForm->password);
     $user->generateVerifyToken();
     $user->generateAuthKey();
     $user->save();
     // Add to mailing list
     if ($user->newsletter) {
         NewsletterMemberService::create($user->email, $user->getName());
     }
     return $user;
 }
Exemplo n.º 7
0
 /**
  * @param ModelContent $content
  * @param CmgFile $banner
  * @return Page
  */
 public static function update($content, $publish = false, $banner = null, $video = null)
 {
     // template
     if (isset($content->templateId) && $content->templateId <= 0) {
         unset($content->templateId);
     }
     $contentToUpdate = self::findById($content->id);
     $contentToUpdate->copyForUpdateFrom($content, ['bannerId', 'templateId', 'summary', 'content', 'seoName', 'seoDescription', 'seoKeywords', 'seoRobot']);
     // publish
     if ($publish && !isset($contentToUpdate->publishedAt)) {
         $date = DateUtil::getDateTime();
         $contentToUpdate->publishedAt = $date;
     }
     // banner, video
     if (isset($banner)) {
         FileService::saveImage($banner, ['model' => $contentToUpdate, 'attribute' => 'bannerId']);
     }
     if (isset($video)) {
         FileService::saveImage($video, ['model' => $contentToUpdate, 'attribute' => 'videoId']);
     }
     // Update Content
     $contentToUpdate->update();
     return $contentToUpdate;
 }
Exemplo n.º 8
0
 public function login()
 {
     if ($this->validate()) {
         $user = $this->user;
         if ($this->admin) {
             $user->loadPermissions();
             if (!$user->isPermitted(CoreGlobal::PERM_ADMIN)) {
                 $this->addError("email", Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_ALLOWED));
                 return false;
             }
         }
         $user->lastLoginAt = DateUtil::getDateTime();
         $user->save();
         return Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0);
     }
     return false;
 }
Exemplo n.º 9
0
 /**
  * The method create user.
  * @param User $user
  * @param CmgFile $avatar
  * @return User
  */
 public static function create($user, $avatar = null)
 {
     // Set Attributes
     $user->registeredAt = DateUtil::getDateTime();
     $user->status = User::STATUS_NEW;
     // Generate Tokens
     $user->generateVerifyToken();
     $user->generateAuthKey();
     if (isset($avatar)) {
         // Save Avatar
         FileService::saveImage($avatar, ['model' => $user, 'attribute' => 'avatarId']);
     }
     // Create User
     $user->save();
     // Add to mailing list
     if ($user->newsletter) {
         NewsletterMemberService::create($user->email, $user->getName());
     }
     return $user;
 }