/** * * @param usersData $data * @return type */ public function createSignUp($data) { $format = $data->format; if ($format == 'doc') { $body = $this->renderPartial('auth/doc', array(), true); return $this->response->type('json')->goodResponse($body); } $tutModel = new Tutorial(); $propModel = new Properties(); $userModel = new Users(); $user2PropertyModel = new \User2property(); $transaction = $propModel->dbConnection->beginTransaction(); $propertie = $propModel->createNewProperie($data->propertie, $data->PP_TRIAL); $tutModel->save(); $tutorial = $tutModel->id; if ($propertie !== false || $tutorial !== false) { $data->property_id = $propertie; $data->tutorial_id = $tutorial; $user = $userModel->createNewUser((array) $data); if ($user !== false) { $color = 'type1'; $bName = $data->firstname . ' ' . $data->lastname; $user2PropertyModel->unsetAttributes(); $user2PropertyModel->setAttributes(array('userId' => $user, 'propertyId' => $propertie, 'access' => self::OWNER, 'status' => self::STATUS_ACTIVE, 'color' => 'type1', 'bookingName' => $bName)); if ($user2PropertyModel->save()) { $transaction->commit(); $result = true; } else { $transaction->rollback(); $result = false; } } else { $transaction->rollback(); $result = false; } } else { $transaction->rollback(); $result = false; } $view = !$result ? 'signup/error' : 'signup/done'; $body = $this->renderPartial($view, array('format' => $format), true); return $this->response->type('json')->goodResponse($body); }
protected function addProperty($data) { $userId = Yii::app()->user->getState('id'); $propertyModel = new Properties(); $user2PropertyModel = new User2property(); $userModel = new \User(); $propertyModel->unsetAttributes(); $data['edt'] = new CDbExpression('NOW()'); $propertyModel->setAttributes($data); $result = $propertyModel->save(); if (!$result) { return false; } $userName = Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'); $user2PropertyModel->unsetAttributes(); $user2PropertyModel->setAttributes(array('userId' => $userId, 'propertyId' => $propertyModel->getAttribute('id'), 'access' => UserAccessTable::OWNER, 'status' => UserAccessTable::STATUS_ACTIVE, 'color' => 'type1', 'bookingName' => $userName)); $result = $user2PropertyModel->save(); if (!$result) { return false; } $userModel->unsetAttributes(); $oldId = $userModel->findByPk($userId); $oldId = $oldId->attributes['property_id']; $result = $userModel->updateByPk($userId, array('property_id' => $propertyModel->getAttribute('id'))); if (!$result) { return false; } $userControl = new \userControl(); $userControl->update(); $outputArray = array('oldId' => $oldId, 'newId' => $propertyModel->getAttribute('id')); return $outputArray; }
public function actionSaveMember() { if (!Yii::app()->request->isPostRequest) { echo json_encode(array('status' => 0, 'message' => 'Only Post request are allowed.')); die; } if (Yii::app()->user->isGuest) { echo json_encode(array('status' => 0, 'message' => 'Only authorize user can allow this.')); die; } $member = new Member(); $member->setAttributes($_POST); $member->validate(); if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $member->propertyId, UserAccessTable::FULL_ACCESS)) { echo json_encode(array('status' => 0, 'message' => 'You can not do this action.')); die; } $errors = $member->getErrors(); if (count($errors) > 0) { echo json_encode(array('status' => 0, 'errors' => $errors)); die; } //get property $property = Properties::model()->findByPk($member->propertyId); //check new user in database $user = User::model()->findByAttributes(array('email' => $member->email)); if ($user != null) { //system already contains user with some email $eu2p = User2property::model()->with('user')->findByAttributes(array('userId' => $user->getAttribute('id'), 'propertyId' => $member->propertyId)); if ($eu2p != null) { echo json_encode(array('status' => 0, 'message' => 'User already exist.')); die; } $u2p = new User2property(); $u2p->setAttribute('userId', $user->getAttribute('id')); $u2p->setAttribute('bookingName', $member->bookname); $u2p->setAttributes($member->attributes); $u2p->save(); $this->layout = "emailmaster"; $emailBody = $this->render('../emails/emailInviteMember', array('userFullName' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'access' => UserAccessTable::accessLevelToString($member->access)), true); MailHelper::send($emailBody, "SharedKey.com - New Property Added to Your Account", array($user->getAttribute('email'))); $temp = User2property::model()->with('user')->findByPk($u2p->getAttribute('id')); echo json_encode(array('status' => 1, 'member' => $this->createViewItem($temp))); die; } $newUser = new User(); $newUser->setAttributes($member->attributes); $password = PasswordGenerator::generatePassword(); $newUser->setAttribute('password', $password); $newUser->setAttribute('property_id', $member->propertyId); $tutorialModel = new TutorialModel(); $tutorialModel->setAttributes(array('gallery' => 1, 'guest_book' => 1, 'house_rules' => 1, 'key_contacts' => 1, 'mapdirections' => 1, 'notice_board' => 1, 'tourist_info' => 1)); $tutorialModel->save(); $newUser->setAttribute('tutorial_id', $tutorialModel->id); $newUser->setAttribute('status', 1); $newUser->setAttribute('createdDate', new CDbExpression('NOW()')); $newUser->save(); $u2p = new User2property(); $u2p->setAttribute('userId', $newUser->getAttribute('id')); $u2p->setAttribute('bookingName', $member->bookname); $u2p->setAttributes($member->attributes); $u2p->save(); $this->layout = "emailmaster"; $emailBody = $this->render('../emails/emailInviteNewMember', array('userFullName' => $newUser->getAttribute('firstname') . ' ' . $newUser->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'email' => $newUser->getAttribute('email'), 'access' => UserAccessTable::accessLevelToString($member->access), 'password' => $password), true); MailHelper::send($emailBody, "Sharedkey.com - Invitation to " . $property->getAttribute('property_name'), array($newUser->getAttribute('email'))); $temp = User2property::model()->with('user')->findByPk($u2p->getAttribute('id')); echo json_encode(array('status' => 1, 'member' => $this->createViewItem($temp))); die; }