Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new BoxomaticUser();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['BoxomaticUser'])) {
         $model->scenario = 'changePassword';
         $model->attributes = $_POST['BoxomaticUser'];
         if (isset($_POST['BoxomaticUser']['password'])) {
             $model->password = $_POST['BoxomaticUser']['password'];
         }
         if ($model->save()) {
             if (isset($_POST['role'])) {
                 $model->setRole($_POST['role']);
             }
             if (isset($_POST['role']) && $_POST['role'] == 'customer') {
                 if (empty($model->user_id)) {
                     $Customer = new Customer();
                 } else {
                     $Customer = Customer::model()->findByPk($model->user_id);
                 }
                 $Customer->attributes = $_POST['Customer'];
                 $Customer->save();
                 $CustLoc = new UserLocation();
                 $CustLoc->user_id = $Customer->user_id;
                 $CustLoc->location_id = $Customer->location_id;
                 $CustLoc->address = $model->user_address;
                 $CustLoc->address2 = $model->user_address2;
                 $CustLoc->suburb = $model->user_suburb;
                 $CustLoc->state = $model->user_state;
                 $CustLoc->postcode = $model->user_postcode;
                 $CustLoc->phone = !empty($model->user_phone) ? $model->user_phone : $model->user_mobile;
                 $CustLoc->save();
                 $model->user_id = $Customer->user_id;
                 $model->update(array('user_id'));
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $custLocDataProvider = new CActiveDataProvider('UserLocation');
     $this->render('create', array('model' => $model, 'custLocDataProvider' => $custLocDataProvider));
 }
Ejemplo n.º 2
0
 public function actionRegister()
 {
     $BoxoCart = new BoxoCart();
     $Customer = new BoxomaticUser();
     $vars = array();
     if (isset($_POST['BoxomaticUser'])) {
         $Customer->attributes = $_POST['BoxomaticUser'];
         $Customer->scenario = 'register';
         if ($Customer->save()) {
             if (!$Customer->Location->is_pickup) {
                 $UserLoc = new UserLocation();
                 $UserLoc->user_id = $Customer->id;
                 $UserLoc->location_id = $Customer->location_id;
                 $UserLoc->address = $Customer->user_address;
                 $UserLoc->address2 = $Customer->user_address2;
                 $UserLoc->suburb = $Customer->user_suburb;
                 $UserLoc->state = $Customer->user_state;
                 $UserLoc->postcode = $Customer->user_postcode;
                 $UserLoc->phone = !empty($Customer->user_phone) ? $Customer->user_phone : $Customer->user_mobile;
                 $UserLoc->save(false);
                 $Customer->user_location_id = $UserLoc->customer_location_id;
             }
             $Auth = Yii::app()->authManager;
             $Auth->assign('customer', $Customer->id);
             $adminEmail = SnapUtil::config('boxomatic/adminEmail');
             $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName');
             //Send email
             $message = new YiiMailMessage('Welcome to ' . Yii::app()->name);
             $message->view = 'welcome';
             $message->setBody(array('User' => $Customer, 'newPassword' => $_POST['BoxomaticUser']['password']), 'text/html');
             $message->addTo($adminEmail);
             $message->addTo($Customer->email);
             $message->setFrom(array($adminEmail => $adminEmailFromName));
             if (!@Yii::app()->mail->send($message)) {
                 $mailError = true;
             }
             $identity = new UserIdentity($Customer->email, $_POST['BoxomaticUser']['password']);
             $identity->authenticate();
             Yii::app()->user->login($identity);
             BoxomaticUser::model()->updateByPk($identity->id, array('last_login_time' => new CDbExpression('NOW()')));
             $this->redirect(array('shop/checkout'));
         }
     } else {
         $Customer->location_id = $BoxoCart->location_id;
     }
     $Customer->password = '';
     $Customer->password_repeat = '';
     $vars['model'] = $Customer;
     // $this->render('register',array('model'=>$Customer));
     $this->render('register', $vars);
 }