/** * Load data fixtures with the passed EntityManager * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $user = new User(); $user->setName('Candido')->setEmail('*****@*****.**')->setPassword(123456)->setActive(true); $manager->persist($user); $manager->flush(); }
/** * @inheritdoc */ public function delete(UserModel $user) : UserModel { $user->delete(); $this->em->persist($user); $this->em->flush(); return $user; }
/** * @param string $name * @param string $password * @param string $role * * @return User */ public function create($name, $password, $role) { $user = new User(); $user->setName($name); $user->setPassword($this->passwordHandler->getHash($password)); $user->setRole($role); return $user; }
public function __invoke(User $user) { $escaper = $this->getView()->plugin('escapehtml'); $url = $this->getView()->plugin('url'); $href = $url('user/view', array('id' => $user->getId())); $name = $escaper($user->getFullName()); return sprintf('<a class="user-view" href="%s">%s</a>', $href, $name); }
/** * @param User $user */ public function save(User $user) { if (!$user->getId()) { $user->setId(null); $this->_em->persist($user); } $this->_em->flush($user); }
public function testAction() { $objectManage = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $user = new User(); $user->setFullname('Some greate developer Hat'); $objectManage->persist($user); $objectManage->flush(); return new ViewModel(); }
public function testAddCustomer() { $user = new User(); $user->setAccount(self::ACCOUNT_ID); $parameters = new Parameters(array("firstName" => self::FIRST_NAME, "lastName" => self::LAST_NAME)); $this->request->setPost($parameters); $this->customerService->add($this->request->getPost(), $user); $customers = $this->customerService->getByText(self::LAST_NAME, self::ACCOUNT_ID); $this->assertEquals($customers[0]->getLastName(), self::LAST_NAME); }
public function setRoleAfterRegister(User $user) { if (count($user->getRoles()) == 0) { $user = $this->saveObject($user); $roleLinker = new RoleLinker(); $roleLinker->setUser($user); $roleLinker->setRole($this->getAdminRole()); $this->saveObject($roleLinker); } }
/** * Loader * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $i = 1; $user = ['name' => 'User ' . $i, 'email' => 'user' . $i . '@users.net']; $obj = new UserModel(); $obj->setName($user['name']); $obj->setEmail($user['email']); $manager->persist($obj); $manager->flush(); $this->addReference('user_' . $i, $obj); }
public function send(User $recipient, $subject, $text, array $attachments = array()) { $fromAddress = $this->configManager->need('mail.address'); $fromName = $this->optionManager->need('client.name.short') . ' ' . $this->optionManager->need('service.name.full'); $replyToAddress = $this->optionManager->need('client.contact.email'); $replyToName = $this->optionManager->need('client.name.full'); $toAddress = $recipient->need('email'); $toName = $recipient->need('alias'); $text = sprintf("%s %s,\r\n\r\n%s\r\n\r\n%s,\r\n%s %s\r\n%s", $this->t('Dear'), $toName, $text, $this->t('Sincerely'), $this->t("Your"), $fromName, $this->optionManager->need('service.website')); $this->baseMailService->sendPlain($fromAddress, $fromName, $replyToAddress, $replyToName, $toAddress, $toName, $subject, $text, $attachments); }
/** * @covers \User\GitHub\LoginListener::onRegister */ public function testOnRegisterWithValidEvent() { $user = new User(); $profile = new Hybrid_User_Profile(); $photoUrl = 'http://placehold.it/50x50'; $profile->photoURL = $photoUrl; $profile->profileURL = 'https://github.com/username'; $event = new Event(null, null, ['user' => $user, 'userProfile' => $profile, 'provider' => 'github']); $this->listener->onRegister($event); $this->assertSame('username', $user->getUsername()); $this->assertSame($photoUrl, $user->getPhotoUrl()); }
public function __invoke(User $user, $options, $attributes, $link = false) { /** @var Gravatar $gravatar */ $gravatar = $this->getView()->plugin('gravatar'); $picture = $gravatar($user->getEmail(), $options, $attributes)->getImgTag(); if (!$link) { return $picture; } $url = $this->getView()->plugin('url'); $href = $url('user/view', array('id' => $user->getId())); return sprintf('<a class="user-view" href="%s">%s</a>', $href, $picture); }
public function getData() { if ($this->client->getEmployer()) { $client = $this->client->getEmployer()->getData(); } else { if ($this->client->getFreelancer()) { $client = $this->client->getFreelancer()->getData(); } else { $client = null; } } return ['client' => $client, 'createDate' => $this->createDate, 'payDate' => $this->payDate, 'intrans_no' => $this->intrans_no, 'fapiao_no' => $this->fapiao_no, 'is_deleted' => $this->is_deleted, 'fee' => $this->fee, 'total' => $this->total, 'subtotal' => $this->subtotal, 'bank' => $this->bank->getData(), 'bankuser' => $this->bankuser, 'tasks' => $this->tasks, 'id' => $this->id]; }
public function load(ObjectManager $manager) { $user = new User(); $user->setEmail("*****@*****.**")->setUsername("developer")->setPassword(123456)->setPasswordClue('123456')->setActive(true)->setStatus(false); $manager->persist($user); $user = new User(); $user->setEmail("*****@*****.**")->setUsername("testete")->setPassword(123456)->setPasswordClue('123456')->setActive(true)->setStatus(false); $manager->persist($user); $user = new User(); $user->setEmail("*****@*****.**")->setUsername("testbo")->setPassword(123456)->setPasswordClue('123456')->setActive(true)->setStatus(false); $manager->persist($user); $manager->flush(); }
public function __invoke(User $user) { $view = $this->getView(); $userBookings = $this->bookingManager->getByValidity(array('uid' => $user->need('uid'))); if ($userBookings) { $this->reservationManager->getByBookings($userBookings); $now = new DateTime(); $lowerLimit = clone $now; $lowerLimit->modify('-2 days'); $upperLimit = clone $now; $upperLimit->modify('+28 days'); $html = ''; $html .= '<ul style=\'padding: 0px 16px 0px 28px;\'>'; $bookingsActuallyDisplayed = 0; foreach ($userBookings as $booking) { $reservations = $booking->needExtra('reservations'); $bookingDateTimeStart = null; $bookingDateTimeEnd = null; foreach ($reservations as $reservation) { $tmpDateTimeStart = new DateTime($reservation->need('date') . ' ' . $reservation->need('time_start')); $tmpDateTimeEnd = new DateTime($reservation->need('date') . ' ' . $reservation->need('time_end')); if (is_null($bookingDateTimeStart) || $tmpDateTimeStart < $bookingDateTimeStart) { $bookingDateTimeStart = $tmpDateTimeStart; } if (is_null($bookingDateTimeEnd) || $tmpDateTimeEnd < $bookingDateTimeStart) { $bookingDateTimeEnd = $tmpDateTimeEnd; } } if ($bookingDateTimeEnd >= $lowerLimit && $bookingDateTimeStart <= $upperLimit) { $square = $this->squareManager->get($booking->need('sid')); $squareType = $view->option('subject.square.type'); if ($bookingDateTimeStart < $now) { $html .= sprintf('<li class=\'gray\'><s>%s %s %s</s></li>', $squareType, $view->t($square->need('name')), $view->prettyDate($bookingDateTimeStart)); } else { $html .= sprintf('<li><span class=\'my-highlight\'>%s %s</span> %s</li>', $squareType, $view->t($square->need('name')), $view->prettyDate($bookingDateTimeStart)); } $bookingsActuallyDisplayed++; } } $html .= '</ul>'; if (!$bookingsActuallyDisplayed) { $html = '<div><em>' . $view->t('You have no imminent bookings.') . '</em></div>'; } return $html; } else { return '<div><em>' . sprintf($view->t('You have not booked any %s yet.'), $view->option('subject.square.type.plural')) . '</em></div>'; } }
/** * @param array $options * * @return bool */ public function save(array $options = []) { try { $this->getConnection()->beginTransaction(); parent::save(); if ($profile = $this->getRelation('profile')) { if (!$profile->exists) { $profile->user()->associate($this); } $profile->save(); } if ($tasks = $this->getRelation('tasks')) { foreach ($tasks as $task) { if (!$task->exists) { $task->user()->associate($this); } $task->save(); } } $this->getConnection()->commit(); } catch (\Exception $e) { s($e->getMessage()); s($e->getTraceAsString()); $this->getConnection()->rollBack(); return false; } return true; }
public function createSingle(User $user, Square $square, $quantity, DateTime $dateTimeStart, DateTime $dateTimeEnd, array $bills = array()) { if (!$this->connection->inTransaction()) { $this->connection->beginTransaction(); $transaction = true; } else { $transaction = false; } try { $booking = new Booking(array('uid' => $user->need('uid'), 'sid' => $square->need('sid'), 'status' => 'single', 'status_billing' => 'pending', 'visibility' => 'public', 'quantity' => $quantity)); $this->bookingManager->save($booking); $reservations = $this->reservationManager->createInRange($booking, $dateTimeStart, $dateTimeEnd); $booking->setExtra('reservations', $reservations); $pricing = $this->squarePricingManager->getFinalPricingInRange($dateTimeStart, $dateTimeEnd, $square, $quantity); if ($pricing) { $squareType = $this->optionManager->need('subject.square.type'); $squareName = $this->t($square->need('name')); /** @var $dateRangeHelper DateRange */ $dateRangeHelper = $this->viewHelperManager->get('DateRange'); $description = sprintf('%s %s, %s', $squareType, $squareName, $dateRangeHelper($dateTimeStart, $dateTimeEnd)); $bookingBill = new Bill(array('description' => $description, 'quantity' => $quantity, 'time' => $pricing['seconds'], 'price' => $pricing['price'], 'rate' => $pricing['rate'], 'gross' => $pricing['gross'])); array_unshift($bills, $bookingBill); } if ($bills) { $extraBills = array(); foreach ($bills as $bill) { if (!$bill instanceof Bill) { throw new RuntimeException('Invalid bills array passed'); } $bill->set('bid', $booking->need('bid')); $this->billManager->save($bill); $extraBills[$bill->need('bid')] = $bill; } $booking->setExtra('bills', $extraBills); } if ($transaction) { $this->connection->commit(); } $this->getEventManager()->trigger('create.single', $booking); return $booking; } catch (Exception $e) { if ($transaction) { $this->connection->rollback(); } throw $e; } }
public function create($data) { $entityManager = $this->getEntityManager(); $pdata = array('isActive' => $data['isActive'], 'profileUpdated' => '0', 'city' => $data['city'], 'createdTime' => new \DateTime('now'), 'lastLogin' => new \DateTime('now'), 'email' => $data['email'], 'firstName' => $data['firstName'], 'lastName' => $data['lastName'], 'name' => $data['name'], 'password' => $data['password'], 'phone' => $data['phone'], 'cellphone' => $data['cellphone'], 'gender' => $data['gender'], 'country' => $entityManager->getRepository('User\\Entity\\Country')->findOneBy(array('id' => $data['country']))); $userExist = $entityManager->getRepository('User\\Entity\\User')->findOneBy(array('email' => $data['email'])); if ($userExist) { } else { $user = new User(); $user->createStaff($this, $pdata); $staff = $user->getStaff(); $staff->setType($entityManager->getRepository('User\\Entity\\Roles')->findOneBy(array('id' => $data['type']))); $staff->setClient($this->getCurrentUser()); $staff->setName($data['name']); $staff->save($entityManager); //$staffData = $staff->getData(); return new JsonModel($user->getData()); } return new JsonModel(['error' => 'User Exist', 'email' => $data['email']]); }
/** * @param Entity\User $user * @param $content * @return mixed */ public function forgotPasswordpMail(\User\Entity\User $user, $content) { $transport = $this->getServiceLocator()->get('mail.transport'); $text = new MimePart($content); $text->type = Mime::TYPE_TEXT; $text->charset = "UTF-8"; $html = new MimePart($content); $html->type = Mime::TYPE_HTML; $html->encoding = Mime::ENCODING_BASE64; $html->charset = "UTF-8"; $body = new MimeMessage(); $body->setParts([$text, $html]); /** * @var \Zend\Mail\Message $message */ $message = $this->getServiceLocator()->get('mail.message'); $message->addTo($user->getEmail())->setSubject("Password recovery")->setBody($body); return $transport->send($message); }
/** * @param \User\Entity\User $user * @param $password * @return \User\Entity\Auth */ public function generateEquals(\User\Entity\User $user, $password) { //delete row $auth = $this->getObjectManager()->getRepository('User\\Entity\\Auth')->findOneBy(['userId' => $user->getId(), 'provider' => Auth::PROVIDER_EQUALS]); // ->findOneByUserId($user->getId()); if ($auth) { $this->getObjectManager()->remove($auth); $this->getObjectManager()->flush(); } // new auth row $row = new \User\Entity\Auth(); $row->setUserId($user->getId()); $row->setForeignKey($user->getEmail()); $row->setProvider(self::PROVIDER_EQUALS); $row->setTokenType(self::TYPE_ACCESS); // generate secret $alpha = range('a', 'z'); shuffle($alpha); $secret = array_slice($alpha, 0, rand(5, 15)); $secret = md5($user->getId() . join('', $secret)); $row->setTokenSecret($secret); // encrypt password and save as token $row->setToken(self::encrypt($row, $password)); $user->getAuths()->add($row); $row->setUser($user); $this->getObjectManager()->persist($row); $this->getObjectManager()->flush(); return $row; }
public function create($pdata) { $data = array(); $data['isActive'] = $pdata['isActive']; $data['profileUpdated'] = $pdata['profileUpdated']; $data['city'] = $pdata['city']; $data['currency'] = $pdata['currency']; $data['createdTime'] = new \DateTime('now'); $data['lastLogin'] = new \DateTime('now'); $data['email'] = $pdata['email']; $data['firstName'] = $pdata['firstname']; $data['lastName'] = $pdata['lastname']; $data['username'] = $pdata['username']; $data['password'] = $pdata['password']; $data['phone'] = $pdata['phone']; $data['gender'] = $pdata['gender']; $entityManager = $this->getEntityManager(); $data['country'] = $entityManager->getRepository('User\\Entity\\Country')->findOneBy(array('id' => $pdata['country'])); $userExist = $entityManager->getRepository('User\\Entity\\User')->findOneBy(array('email' => $pdata['email'])); if ($userExist) { return new JsonModel(['success' => 'failed', 'msg' => '']); } else { $user = new User(); $user->setData($data); $user->save($entityManager); $user->createFreelancer($this, $data, $entityManager, $pdata['lang_code']); $freelancer = $user->getFreelancer(); $tmp = array('Resources' => $pdata['resources'], 'DesktopCatTools' => $pdata['desktopcattools'], 'DesktopOperatingSystems' => $pdata['desktopoperatingsystems'], 'InterpretingSpecialisms' => $pdata['interpretingspecialisms'], 'TranslationCatTools' => $pdata['translationcattools'], 'TranslationSpecialisms' => $pdata['translationspecialisms']); $freelancer->updateData($tmp, $entityManager); $freelancer->save($entityManager); $ret_data = $user->getData(); // Set Translation Price foreach ($pdata['translationPrices'] as $k => $v) { $translationPrice = array('user' => $user, 'sourceLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['sourceLanguage']['id'])), 'targetLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['targetLanguage']['id'])), 'price' => $v['price']); $pTranslationPrice = new UserTranslationPrice(); $pTranslationPrice->setData($translationPrice); $pTranslationPrice->save($entityManager); } // Set Desktop Prices foreach ($pdata['desktopPrices'] as $k => $v) { $desktopPrice = array('user' => $user, 'language' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['language']['id'])), 'software' => $entityManager->getRepository('User\\Entity\\DesktopSoftware')->findOneBy(array('id' => $v['language']['id'])), 'priceMac' => $v['priceMac'], 'pricePc' => $v['pricePc'], 'priceHourMac' => $v['priceHourMac'], 'priceHourPc' => $v['priceHourPc']); $pDesktopPrice = new UserDesktopPrice(); $pDesktopPrice->setData($desktopPrice); $pDesktopPrice->save($entityManager); } // Set Interpreting Price foreach ($pdata['interpretingPrices'] as $k => $v) { $interpretingPrice = array('user' => $user, 'sourceLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['sourceLanguage']['id'])), 'targetLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['targetLanguage']['id'])), 'service' => $entityManager->getRepository('User\\Entity\\InterpretingService')->findOneBy(array('id' => $v['service']['id'])), 'priceDay' => $v['priceDay'], 'priceHalfDay' => $v['priceHalfDay']); $pInterpretingPrice = new UserInterpretingPrice(); $pInterpretingPrice->setData($interpretingPrice); $pInterpretingPrice->save($entityManager); } return new JsonModel(['user' => $ret_data, 'success' => 'success']); } return new JsonModel(['success' => 'failed', 'msg' => 'Unknown Error']); }
public function storeAction() { $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $user = new User(); $user->setCreatedAt(new \DateTime(date("Y-m-d H:i:s"))); echo "<pre>"; var_dump($user->getCreatedAt()); die; $user->setusername($this->request->getPost()['username']); $user->setPassword($this->request->getPost()['username']); $user->setCountry($this->request->getPost()['username']); $user->setRole($this->request->getPost()['role']); // $user->setCreatedAt('2015-09-20 11:19:31'); $objectManager->persist($user); $objectManager->flush(); return 1; }
public function __invoke(User $user, $search = null) { $view = $this->getView(); $html = ''; switch ($user->need('status')) { case 'placeholder': $attr = ' class="gray"'; break; default: $attr = null; break; } $html .= sprintf('<tr %s>', $attr); $html .= sprintf('<td>%s</td>', $user->need('uid')); $html .= sprintf('<td>%s</td>', $user->need('alias')); $html .= sprintf('<td>%s</td>', $view->t($user->getStatus())); /* Email col */ $email = $user->get('email'); if ($email) { $email = '<a href="mailto:' . $email . '" class="unlined" style="color: #333; opacity: 1.0;">' . $email . '</a>'; } else { $email = '-'; } $html .= sprintf('<td class="email-col">%s</td>', $email); /* Notes col */ $notes = $user->getMeta('notes'); if ($notes) { if (strlen($notes) > 48) { $notes = substr($notes, 0, 48) . '…'; } $notes = '<span class="small-text">' . $notes . '</span>'; } else { $notes = '-'; } $html .= sprintf('<td class="notes-col">%s</td>', $notes); /* Actions col */ $html .= sprintf('<td class="actions-col no-print"><a href="%s" class="unlined gray symbolic symbolic-edit">%s</a> <a href="%s" class="unlined gray symbolic symbolic-booking">%s</a></td>', $view->url('backend/user/edit', ['uid' => $user->need('uid')], ['query' => ['search' => $search]]), $view->t('Edit'), $view->url('backend/booking', [], ['query' => ['search' => '(uid = ' . $user->need('uid') . ')']]), $view->t('Bookings')); $html .= '</tr>'; return $html; }
/** * @param array $data * @return mixed|void */ public function register($data) { //$bcrypt = new Bcrypt; //loato z radiem $user = new User(); $user->setCreated(date('Y-m-d H:i:s')); $user->setRoleId(1); //$user->setPassword(($bcrypt->create($data->password))); $user->setPassword(sha1($data->password)); $user->setEmail($data->email); $user->setUsername($data->username); $result = $this->userMapper->insert($user); return $result; }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $inputFilter = parent::getInputFilter(); $email = new Input('email'); $email->setRequired(true); $email->setAllowEmpty(false); $objectExists = new ObjectExists(array('object_repository' => $this->objectManager->getRepository(User::getClass()), 'fields' => 'email')); $objectExists->setMessage($this->translator->translate('forgotPassword.email.notExists'), ObjectExists::ERROR_NO_OBJECT_FOUND); $emailAddress = new EmailAddress(); $emailAddress->setMessage($this->translator->translate('forgotPassword.email.invalidFormat'), $emailAddress::INVALID_FORMAT); $email->getValidatorChain()->attach($emailAddress, true)->attach($objectExists); $this->filter->add($email); } return $this->filter; }
/** * Create a new user * * @param array $data * @param \Zend\Form\Form $form * @return bool */ public function create($data, &$form) { $user = new UserEntity(); $em = $this->getEntityManager(); $form->bind($user); $form->setData($data); if (!$form->isValid()) { return false; } $user->setPassword(UserEntity::hashPassword($user->getPassword())); try { $em->persist($user); $em->flush(); $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_USER_CREATED"]); return true; } catch (\Exception $e) { $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_USER_NOT_CREATED"]); return false; } }
/** * @param $commentText * @return \Comment\Entity\Comment * @throws \Doctrine\DBAL\ConnectionException * @throws \Exception */ protected function createComment($commentText) { /** * @var \Doctrine\ORM\EntityManager $objectManager */ $commentData = array('comment' => $commentText, 'entityType' => $this->entityType, 'entityId' => $this->user->getId(), 'user' => $this->getApplicationServiceLocator()->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser()); $objectManager = $this->getApplicationServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $comment = new Comment(); $objectManager->getConnection()->beginTransaction(); try { $hydrator = new DoctrineHydrator($objectManager); $hydrator->hydrate($commentData, $comment); $objectManager->persist($comment); $objectManager->flush(); $objectManager->getConnection()->commit(); $objectManager->clear(); } catch (\Exception $e) { $objectManager->getConnection()->rollback(); throw $e; } return $comment; }
/** * Send request change password email * * @author Stoyan Rangelov * @param \User\Entity\User $user */ public function sendRequestChangePasswordEmail(\User\Entity\User $user, $code) { $from = $this->getSenderEmail(); $to = $user->getLogin(); $subject = "Please change your password"; /*$htmlBody = "Hello <br /> Please change your password via the following link: <br /> <b>{$this->getChangePasswordURL()}/{$code}</b>";*/ $passwordUrl = "{$this->getChangePasswordURL()}/{$code}"; $htmlBody = $this->getChangePasswordEmailTemplate($passwordUrl); $textBody = ""; $htmlPart = new MimePart($htmlBody); $htmlPart->type = "text/html; charset=UTF-8"; $textPart = new MimePart($textBody); $textPart->type = "text/plain; charset=UTF-8"; $body = new MimeMessage(); $body->setParts(array($textPart, $htmlPart)); $message = new Mail\Message(); $message->setFrom($from)->addTo($to)->setSubject($subject); $message->setEncoding("UTF-8"); $message->setBody($body); $transport = new SmtpTransport(); if ($this->getDefaultConfig()['user_module']['using_gmail']) { $transport->setOptions($this->getSMTPOptions()); } $transport->send($message); }
public function getData() { return ['id' => $this->id, 'user' => $this->user->getData(), 'paypal' => $this->paypal, 'alipay' => $this->alipay, 'account' => $this->account, 'address' => $this->address, 'city' => $this->city, 'country' => $this->country, 'name' => $this->name, 'accountNo' => $this->accountNo, 'swift' => $this->swift, 'routingNumber' => $this->routingNumber]; }
/** * {@inheritDoc} */ public function setCreated(\DateTime $created) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCreated', array($created)); return parent::setCreated($created); }