public function testFindUserByEmail() { setUp(); $this->user = $this->em->getRepository('AppBundle:User')->findUserByEmail("*****@*****.**"); $this->assertEquals("*****@*****.**", $this->user->getEmail()); tearDown(); }
/** * @param User $user * @param $request * @throws Exception * @return User */ public function addCustomer(User $user, $request) { $stripeToken = $request->request->get('token'); //register stripe customer if necessary $customer = StripeCustomer::create(["description" => sprintf("UserId %s email %s", $user->getId(), $user->getEmail()), "source" => $stripeToken, "email" => $user->getEmail()]); if (!$customer->id) { throw new Exception("stripe create customer failed"); } $user->setStripeCustomerId($customer->id); return true; }
public function checkUserLabeli(User $user) { $userNom = strtolower($user->getNom()); $userPrenom = strtolower($user->getPrenom()); $userMail = strtolower($user->getEmail()); $labelis = $this->em->getRepository('AppBundle:Labeli')->findAll(); foreach ($labelis as $labeli) { $labeliNom = strtolower($labeli->getNom()); $labeliPrenom = strtolower($labeli->getPrenom()); $labeliMail = strtolower($labeli->getMail()); if ($userNom == $labeliNom && $userPrenom == $labeliPrenom || $userPrenom == $labeliNom && $userNom == $labeliPrenom || $userMail == $labeliMail) { if ($labeli->getHonored() == 1) { $subject = 'Confirmation Invités d\'Honneur LGC'; $template = '::email/honored.html.twig'; } else { $subject = 'Confirmation participant Label[i]'; $template = '::email/labeli.html.twig'; } $user->setPayed(1); $this->em->flush(); $mailUser = $user->getEmail(); $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom('*****@*****.**')->setTo($userMail)->setBody($this->container->get('templating')->render($template), 'text/html'); $this->container->get('mailer')->send($message); $user->setMailPayed(1); $this->em->persist($user); $this->em->flush(); } } }
/** * @Route("/users/:{id}", name="rest_user") * @param User $user * @return array * @View() * @ParamConverter("user",class="AppBundle:User") */ public function getUserAction(User $user) { $em = $this->getDoctrine()->getManager(); $users = $em->getRepository('AppBundle:User')->findAll(); // get data, in this case list of users. return array('user' => array('login' => $user->getUsername(), 'email' => $user->getEmail(), 'adresse' => $user->getAdresse(), 'telephone' => $user->getNumero(), 'sitweb' => $user->getSiteweb())); }
private function canYouDoIt(Comment $comment, User $user) { $commentOwner = $this->doctrine->getRepository('AppBundle:User')->findOneBy(array('email' => $comment->getAuthorEmail())); if (in_array("ROLE_ADMIN", $commentOwner->getRoles()) || $comment->getPost()->getAuthorEmail() !== $user->getEmail()) { return false; } return true; }
public function testSetEmail() { // new entity $user = new User(); // Use the setEmail method $user->setEmail("*****@*****.**"); // Assert the result $this->assertEquals("*****@*****.**", $user->getEmail()); }
public function sendUserBlockedMessage(Request $request, User $user) { $template = 'Emails/User/mail_user_blocked.html.twig'; $emailHtml = $this->renderView($template, array('user' => $user, 'mailer_app_url_prefix' => $this->getParameter('mailer_app_url_prefix'))); $subject = "User bloked."; $from = array($this->getParameter('mailer_fromemail') => $this->getParameter('mailer_fromname')); $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setTo($user->getEmail())->setBody($emailHtml, 'text/html'); $this->get('mailer')->send($message); }
/** * @param User $user * @param $request * @throws * @return User */ public function addCustomer(User $user, $request) { $result = BraintreeCustomer::create(['id' => 'userid-' . $user->getId(), 'email' => $user->getEmail(), "creditCard" => ["number" => $request->request->get("number"), "cvv" => $request->request->get("cvv"), "expirationMonth" => $request->request->get("month"), "expirationYear" => $request->request->get("year")]]); if ($result->success === true) { $user->setBraintreeCustomerId($result->customer->id); } else { throw new Exception("Braintree create customer failed"); } return $result->success; }
/** * Tests if the username property is set, if its not set while setting the email */ public function testSetEmail() { $user = new User(); $this->assertNull($user->getEmail()); $user->setEmail('*****@*****.**'); $this->assertEquals($user->getEmail(), $user->getUsername()); $secondUser = new User(); $secondUser->setUsername('username'); $secondUser->setEmail('*****@*****.**'); $this->assertNotEquals($secondUser->getEmail(), $secondUser->getUsername()); }
public function testBasicGettersSetters() { $user = new User(); $user->setUsername('Toto'); $user->setEmail('*****@*****.**'); $user->setIsActive(false); $user->setPassword('1234'); $this->assertEquals('Toto', $user->getUsername()); $this->assertEquals('*****@*****.**', $user->getEmail()); $this->assertEquals(false, $user->isActive()); $this->assertEquals('1234', $user->getPassword()); }
/** * Transform a Model User to its representation. * * @param User|null $user * * @return UserRepresentation|null */ public function transform($user) { if (!$user) { return; } $representation = new UserRepresentation(); $representation->setId($user->getId()); $representation->setUsername($user->getUsername()); $representation->setEmail($user->getEmail()); $representation->setFirstname($user->getFirstName()); return $representation; }
/** * @param User $user */ public function sendResettingEmailMessage(User $user) { /* Variables used in template */ $confirmationToken = $user->getConfirmationToken(); $username = $user->getUsername(); /* END */ /* Variables used in mail sending function */ $subject = 'Resetowanie hasła'; $email = $user->getEmail(); $renderedTemplate = $this->templating->render('AppBundle:Emails:passwordResetting.html.twig', array('username' => $username, 'confirmationToken' => $confirmationToken)); /* END */ $this->sendEmailMessage($renderedTemplate, $subject, $email); }
public function __construct(User $user) { $this->id = $user->getId(); $this->firstname = $user->getFirstname(); $this->lastname = $user->getLastname(); $this->email = $user->getEmail(); $this->positionLong = $user->getPositionLong(); $this->positionLat = $user->getPositionLat(); $this->positionCity = $user->getPositionCity(); $this->positionDep = $user->getPositionDep(); $this->positionCountry = $user->getPositionCountry(); $this->photo = $user->getPhoto(); }
/** * UserModel constructor. * @param User $user */ public function __construct(User $user) { $this->setId($user->getId()); $this->setUsername($user->getUsername()); $this->setUserFirstName($user->getUserFirstName()); $this->setUserLastName($user->getUserLastName()); $this->setEmail($user->getEmail()); $this->setPassword($user->getPassword()); $this->setApiKey($user->getApiKey()); $role = $this->determineTheBiggestRole($user); if ($role) { $this->setRole(new RoleModel($role)); } }
/** * @Route("/signup") * @Method({"GET", "POST"}) * @Template */ public function signupAction(Request $request) { $form = $this->createForm(new SignupType(), $user = new User()); $form->handleRequest($request); if (!$form->isValid()) { return ['form' => $form->createView()]; } $same = $this->repo('AppBundle:User')->findOneBy(['email' => $user->getEmail()]); if (null !== $same and $same->isConfirmed()) { $form->get('email')->addError(new FormError("Email {$user->getEmail()} is already confirmed")); return ['form' => $form->createView()]; } if (null !== $same) { $this->get('mail')->user($same, 'activate_email', ['link' => $this->generateUrl('app_user_confirm', ['token' => $same->getConfirmationToken()], true)]); $this->addFlash('info', "Confirmation email was successfully resent to {$same->getEmail()}"); return ['form' => $form->createView()]; } $user->regenerateConfirmationToken(); $this->persist($user); $this->flush(); $this->get('mail')->user($user, 'activate_email', ['link' => $this->generateUrl('app_user_confirm', ['token' => $user->getConfirmationToken()], true)]); $this->addFlash('success', "You should receive confirmation email shortly"); return $this->redirect($this->generateUrl('app_user_login')); }
/** * @param User $user * * @throws PersisterException * @throws \Exception */ public function createUser(User $user) { $user->setUsername($user->getEmail()); try { $transaction = new Transaction(); $transaction->setAmount(0); $transaction->setDate(new \DateTime(date("Y-m-d H:i:s"))); $transaction->setOperation('Ouverture du compte'); $transaction->setTotalMoney(0); $user->addTransaction($transaction); $this->userDao->persist($user); } catch (PersisterException $e) { throw $e; } }
/** * Inserts data of authenticated user to User table * if user has already been inserted then this function * updates following db values: display_name, manager_id, title * * @param User $user * @throws \Doctrine\DBAL\DBALException */ public function importAuthenticatedUser(User $user) { $this->getEntityManager()->getConnection()->executeQuery('INSERT OR IGNORE INTO user(username, email, uuid, password, roles) VALUES(:username, :email, :uuid, :password, :roles)', ['username' => $user->getDisplayName(), 'email' => $user->getEmail(), 'uuid' => $user->getUuid(), 'password' => md5(microtime()), 'roles' => '']); }
/** * {@inheritDoc} */ public function getEmail() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getEmail', []); return parent::getEmail(); }
public function loadUserByOAuthUserResponse(UserResponseInterface $response) { $uri = $this->request->getUri(); $isMailru = false; if (strpos($uri, '/login_mailru') !== false) { $isMailru = true; } if ($isMailru === false) { throw new \Exception("Invalid social network login attempt"); } $social = ""; if ($isMailru) { $social = "mailru"; } //check to see if the user is logged in and if she is logged in with the same social network $isLoggedInAlready = $this->session->has('user'); $isLoggedInAlreadyId = $this->session->get('user')['id']; if ($isLoggedInAlready && $this->session->get('user')['social'] == $social) { return $this->loadUserByUsername($isLoggedInAlreadyId); } $social_id = $response->getUsername(); $username = $response->getUsername(); $realName = $response->getRealName(); $email = $response->getEmail(); $avatar = $response->getProfilePicture(); //set data in session. upon logging out we just erase the whole array. $sessionData = array(); $sessionData['social_id'] = $social_id; $sessionData['username'] = $username; $sessionData['realName'] = $realName; $sessionData['email'] = $email; $sessionData['avatar'] = $avatar; $sessionData['social'] = $social; $user = null; if ($isLoggedInAlready) { $user = $this->doctrine->getRepository('AppBundle\\Entity\\User')->findOneById($isLoggedInAlreadyId); } else { if ($isMailru) { $user = $this->doctrine->getRepository('AppBundle\\Entity\\User')->findOneByMid($social_id); } } if ($user == null) { $user = new User(); //change these only the user hasn't been registered before. $user->setUsername($username); $user->setRealname($realName); $user->setAvatar($avatar); } if ($isMailru) { $user->setMid($social_id); } $user->setLastLogin(new \DateTime('now')); $user->setSocial($social); // SET E-MAIL //if all emails are empty, set the first one to this one. if ($user->getEmail() == "") { $user->setEmail($email); } else { //if it really is an e-mail, try putting it in email2 or email3 if ($email != "") { //is the e-mail different than the previous one? if ($email != $user->getEmail()) { //if there an e-mail in email2? no: if ($user->getEmail2() == "") { $user->setEmail2($email); } else { //there is an e-mail in email2 and it's different. fall back to setting the user3 to w/e. if ($user->getEmail2() != $email) { $user->setEmail3($email); } } } } } //save all changes $em = $this->doctrine->getManager(); $em->persist($user); $em->flush(); $id = $user->getId(); //set id $sessionData['id'] = $id; $sessionData['is_admin'] = $this->adminChecker->check($user); $this->session->set('user', $sessionData); return $this->loadUserByUsername($user->getId()); }
/** * Turn this item object into a generic array * * @return array */ public function transform(User $user) { return ['id' => (int) $user->getId(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'lastLogin' => $user->getLastLogin(), 'enabled' => (bool) $user->isEnabled(), 'firstname' => $user->getFirstname(), 'lastname' => $user->getLastname(), 'fullname' => $user->getFullname(), 'displayname' => $user->getDisplayName()]; }
/** * Test is the given response is valid. * * @param Response $response * @param User $user */ private function assertIsValidV2Response(Response $response, User $user) { // Response is OK $this->assertEquals(200, $response->getStatusCode()); $result = $response->getContent(); $content = json_decode($result, true); // All key are presents $keys = array('id', 'username', 'email', 'firstname'); foreach ($keys as $key) { $this->assertArrayHasKey($key, $content); } // There is no extra key foreach ($content as $key => $value) { $this->assertContains($key, $keys); } // all values are valid $this->assertEquals($user->getId(), $content['id']); $this->assertEquals($user->getUsername(), $content['username']); $this->assertEquals($user->getEmail(), $content['email']); $this->assertEquals($user->getFirstName(), $content['firstname']); }
/** * @param User $user * @param $password */ public function send(User $user, $password) { $message = $this->mailer->createMessage()->setSubject('Založení účtu')->setFrom($this->senderMail, $this->senderName)->setTo($user->getEmail())->setBody($this->getMessage($user, $password), 'text/html'); $this->mailer->send($message); }
public function fromUser(User $user) { $userContract = new self(); //Force fetch $user->getMyContacts()->toArray(); $user->getConversations()->toArray(); $user->getContactsWithMe()->toArray(); $userContract->id = $user->getId(); $userContract->tkey = $user->getTkey(); $userContract->avatar = $user->getAvatar(); $userContract->birthday = $user->getBirthday(); $userContract->cdate = $user->getCdate(); $userContract->conversations = $user->getConversations(); $userContract->connections = $user->getConnections(); $userContract->contactsphones = $user->getContactsphones(); $userContract->email = $user->getEmail(); $userContract->fname = $user->getFname(); $userContract->lastUpdate = $user->getLastUpdate(); $userContract->lname = $user->getLname(); $userContract->contactsWithMe = $user->getContactsWithMe(); $user->getMyContacts()->toArray(); $userContract->myContacts = $user->getMyContacts(); $userContract->password = $user->getPassword(); $userContract->phone = $user->getPhone(); $userContract->username = $user->getUsername(); return $userContract; }
private function canonicalizerEmail(User $user) { $email = $user->getEmail(); $user->setEmailCanonical($this->canonicalizer->canonicalize($email)); }
/** * @return mixed */ public function getAuthorEmail() { return $this->author->getEmail(); }
private function processRequest(User $user, ParameterBag $content, $new = true) { if (strcmp($user->getUsername(), $content->get('username')) !== 0) { $user->setUsername($content->get('username')); } if (strcmp($user->getEmail(), $content->get('email')) !== 0) { $user->setEmail($content->get('email')); } if (strlen($content->get('plainPassword')) > 6) { $user->setPlainPassword($content->get('plainPassword')); } // @TODO we should only remove roles lower than the role assigned $user->setRoles([]); $user->addRole($content->get('role')); $validator = $this->get('validator'); return $validator->validate($user, null, [$new ? 'new' : '']); }
/** * Is the given User the author of this Post? * * @param User $user * * @return bool */ public function isAuthor(User $user = null) { return $user->getEmail() == $this->getAuthorEmail(); }
private function setUsername(User $user) { if (!$user->getUsername()) { $user->setUsername($user->getEmail()); } }