Example #1
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new Customer();
         $user->created_at = strtotime('now');
         $user->status = Customer::STATUS_ACTIVE;
         $user->firstname = $this->firstname;
         $user->lastname = $this->lastname;
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
Example #2
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     //        $username = Yii::$app->user->identity->username;
     $model = new Customer();
     if ($model->load($data)) {
         $model->created_at = $now;
         $model->dob = strtotime($model->dob);
         //            do {
         //                $path = FileUtils::generatePath($now);
         //            } while (file_exists(Yii::$app->params['images_folder'] . $path));
         //            $model->image_path = $path;
         //            $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         //            $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         //
         //            if (!empty($data['customer-image'])) {
         //                $copyResult = FileUtils::copyImage([
         //                    'imageName' => $model->image,
         //                    'fromFolder' => Yii::$app->params['uploads_folder'],
         //                    'toFolder' => $targetFolder,
         //                    'resize' => [[120, 120], [200, 200]],
         //                    'removeInputImage' => true,
         //                ]);
         //                if ($copyResult['success']) {
         //                    $model->image = $copyResult['imageName'];
         //                }
         //            }
         // User class
         $model->status = parent::STATUS_ACTIVE;
         $model->generateAuthKey();
         $model->setPassword($model->password);
         if ($model->save()) {
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }