Example #1
0
 public static function create($email)
 {
     $subscription = new self(new RM_Compositor(array('subscriptionDate' => time(), 'subscriptionStatus' => self::STATUS_SHOW, 'subscriptionType' => self::TYPE_NOT_ACTIVATED)));
     $subscription->setEmail($email);
     $subscription->save();
     return $subscription;
 }
Example #2
0
 public static function createFromArray(array $getUserInfoResponse)
 {
     $user = new self();
     $user->setEmail($getUserInfoResponse['Login']);
     $user->setKey($getUserInfoResponse['Key']);
     return $user;
 }
Example #3
0
 static function createWithEmail($email, $password)
 {
     $sender = new self();
     $sender->setEmail($email);
     $sender->setPassword($password);
     return $sender;
 }
Example #4
0
 /**
  * @param mixed $email
  * @return self
  */
 public static function fromMixed($email)
 {
     if ($email instanceof Contact) {
         return $email;
     } else {
         $value = new self();
         $value->setEmail($email);
         return $value;
     }
 }
Example #5
0
 public static function getById($id)
 {
     /**
      * @var $userdb \PDO
      */
     global $userdb;
     $stmt = $userdb->prepare("SELECT `id`, `name`, `username`, `email`, `password` FROM jos_users WHERE `id` = :user_id");
     $stmt->bindParam(':user_id', $id);
     $stmt->execute();
     $userData = $stmt->fetch(\PDO::FETCH_ASSOC);
     $user = new self();
     $user->setIsNew(false);
     $user->setId($userData['id']);
     $user->setName($userData['name']);
     $user->setUsername($userData['username']);
     $user->setEmail($userData['email']);
     $user->setPasswordHash($userData['password']);
     return $user;
 }
Example #6
0
 /**
  * Build a customer entity based on a json-decoded customer stdClass
  *
  * @param stdClass $response The customer data
  *
  * @return Syspay_Merchant_Entity_Customer The customer object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $customer = new self();
     $customer->setEmail(isset($response->email) ? $response->email : null);
     $customer->setLanguage(isset($response->language) ? $response->language : null);
     $customer->setIp(isset($response->ip) ? $response->ip : null);
     $customer->setMobile(isset($response->mobile) ? $response->mobile : null);
     $customer->raw = $response;
     return $customer;
 }
Example #7
0
 /**
  * Factory that fills the required fields of the user.
  *
  * @param string $username
  * @param string $password
  * @param string $email
  *
  * @return User
  */
 public static function create($username, $password, $email)
 {
     $user = new self();
     $user->setUsername($username);
     $user->setPassword($password);
     $user->setEmail($email);
     return $user;
 }
Example #8
0
 /**
  * Adds the user to the database. 
  * There are bunch of required parameters required to be passed as $params array:
  * - login: the arbitrary string which will be used as a login for the user. The checks defined in
  * {@link setLogin} method will be performed.
  * - password: user's password. The checks defined in {@link setPassword} will be performed.
  * - email: required parameter to, for example, send confirmation emails. The checks defined in 
  * {@link setEmail} method will be performed.
  *
  * Optionally, the 'state' parameter may be passed, showing the status of newly created user. 
  * If it's omitted, the "not_confirmed" or "active" state will be chosen depending on the 
  * <code>config.user.registration_confirm</code> config parameter. If the value distinguish 
  * from the described ones, make sure that this value could be held by the DB schema of the 'state' column.
  *
  * If <code>config.user.registration_confirm</code> config parameter is set to non-false value, 
  * the one time token will be added for newly created user. This could be used for example to
  * send activation email. Logic behind that should be created separately in the model/controller.
  *
  * Additionally, the profile entry for the new user will be created.
  *
  * Behavior BeforeAddNewUser is defined.
  *
  * @param array parameters for the new user as described above
  * @return User new user object
  * @throws UserException in case of errors
  */
 static function add(array $params)
 {
     if (empty($params['login']) || empty($params['password']) || empty($params['email'])) {
         throw new UserException("Login, password and email must be passed");
     }
     $config = Config::getInstance();
     if (empty($params['state'])) {
         $params['state'] = $config->user->registration_confirm ? "not_confirmed" : "active";
     }
     if (self::findBy('login', $params['login'])) {
         throw new UserException("User with the same login already exists");
     }
     $new_user = new self(null);
     $new_user->setLogin($params['login']);
     $new_user->setPassword($params['password']);
     $new_user->setState($params['state']);
     $new_user->setEmail($params['email']);
     $new_user->trigger("BeforeAddNewUser", array($new_user, &$params));
     $new_user->save();
     $one_time_token = null;
     if ($config->user->registration_confirm) {
         $one_time_token = OneTimeTokenAuth::generateAndAddToken($new_user->getId());
     }
     Profile::addUser($new_user->getId());
     return $new_user;
 }
Example #9
0
 /**
  * @param UserResponseInterface $response
  * @return User
  * @throws \InvalidArgumentException
  */
 public static function fromOAuthResponse(UserResponseInterface $response)
 {
     $user = new self();
     $user->setPassword('whatever');
     $user->setEnabled(true);
     switch ($response->getResourceOwner()->getName()) {
         case 'facebook':
             $user->setFacebookId($response->getResponse()['id']);
             $user->setUsername('fb-' . $response->getResponse()['id']);
             $user->setDisplayableName($response->getResponse()['name']);
             if (isset($response->getResponse()['email']) && $response->getResponse()['email']) {
                 $user->setEmail($response->getResponse()['email']);
             } else {
                 $user->setEmail('fb-no-email-' . md5(rand()) . '@example.com');
             }
             $user->setPictureUrl($response->getResponse()['picture']['data']['url']);
             break;
         case 'vkontakte':
             $responseInner = $response->getResponse()['response'][0];
             $user->setVkontakteId($responseInner['uid']);
             $user->setUsername('vk-' . $responseInner['uid']);
             $user->setDisplayableName($responseInner['first_name'] . ' ' . $responseInner['last_name']);
             if ($response->getResponse()['email']) {
                 $user->setEmail($response->getResponse()['email']);
             } else {
                 //in VK user can hide his email, but FOS treats email as mandatory
                 $user->setEmail('vk-hidden-email-' . md5(rand()) . '@example.com');
             }
             $user->setPictureUrl($responseInner['photo_medium']);
             break;
         case 'twitter':
             $user->setTwitterId($response->getResponse()['id']);
             $user->setUsername('twitter-' . $response->getResponse()['id']);
             $user->setDisplayableName($response->getResponse()['name']);
             $user->setEmail('twitter-email-' . md5(rand()) . '@example.com');
             $user->setPictureUrl($response->getResponse()['profile_image_url']);
             break;
         case 'google':
             $user->setGoogleId($response->getResponse()['id']);
             $user->setUsername('google-' . $response->getResponse()['id']);
             $user->setDisplayableName($response->getResponse()['name']);
             $user->setEmail($response->getResponse()['email']);
             $user->setPictureUrl($response->getResponse()['picture']);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Resource owner `%` is not supported', $response->getResourceOwner()->getName()));
     }
     return $user;
 }
Example #10
0
 /**
  * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement $xmlElement)
  * @return CultureFeed_Cdb_Item_Page
  */
 public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
 {
     if (empty($xmlElement->uid)) {
         throw new CultureFeed_Cdb_ParseException('Uid missing for page element');
     }
     if (empty($xmlElement->name)) {
         throw new CultureFeed_Cdb_ParseException('Name missing for page element');
     }
     $page = new self();
     // Set ID + name.
     $page->setId((string) $xmlElement->uid);
     $page->setName((string) $xmlElement->name);
     $page->setOfficialPage(filter_var((string) $xmlElement->officialPage, FILTER_VALIDATE_BOOLEAN));
     // Set categories
     $categories = array();
     if (!empty($xmlElement->categoryIds->categoryId)) {
         foreach ($xmlElement->categoryIds->categoryId as $category) {
             $categories[] = (string) $category;
         }
     }
     $page->setCategories($categories);
     // Set keywords
     $keywords = array();
     if (!empty($xmlElement->keywords->keyword)) {
         foreach ($xmlElement->keywords->keyword as $keyword) {
             $keywords[] = (string) $keyword;
         }
     }
     $page->setKeywords($keywords);
     // Set description.
     if (!empty($xmlElement->description)) {
         $page->setDescription((string) $xmlElement->description);
     }
     // Set the image.
     if (!empty($xmlElement->image)) {
         $page->setImage((string) $xmlElement->image);
     }
     // Set the cover.
     if (!empty($xmlElement->cover)) {
         $page->setCover((string) $xmlElement->cover);
     }
     // Set the visibility.
     if (!empty($xmlElement->visible)) {
         $page->setVisibility((string) $xmlElement->visible);
     }
     // Set address.
     $address = new CultureFeed_Cdb_Data_Address_PhysicalAddress();
     $addressElement = $xmlElement->address;
     $has_address = FALSE;
     if (!empty($addressElement->city)) {
         $address->setCity((string) $addressElement->city);
         $has_address = TRUE;
     }
     if (!empty($addressElement->street)) {
         $address->setStreet((string) $addressElement->street);
         $has_address = TRUE;
     }
     if (!empty($addressElement->zip)) {
         $address->setZip((string) $addressElement->zip);
         $has_address = TRUE;
     }
     if (!empty($addressElement->country)) {
         $address->setCountry((string) $addressElement->country);
         $has_address = TRUE;
     }
     if (!empty($addressElement->lat) && !empty($addressElement->lon)) {
         $coordinates = $addressElement->lat . '-' . $addressElement->lon;
         if ($coordinates != '0.0-0.0') {
             $address->setGeoInformation(new CultureFeed_Cdb_Data_Address_GeoInformation((string) $addressElement->lon, (string) $addressElement->lat));
             $has_address = TRUE;
         }
     }
     if ($has_address) {
         $page->setAddress($address);
     }
     // Set contact info.
     if (!empty($xmlElement->contactInfo->email)) {
         $page->setEmail((string) $xmlElement->contactInfo->email);
     }
     if (!empty($xmlElement->contactInfo->telephone)) {
         $page->setTelephone((string) $xmlElement->contactInfo->telephone);
     }
     // Set links.
     $links = array();
     if (!empty($xmlElement->links)) {
         foreach ($xmlElement->links->children() as $link) {
             $url = (string) $link;
             if (empty($url)) {
                 continue;
             }
             // Make sure http is in front of the url.
             if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
                 $url = 'http://' . $url;
             }
             $links[$link->getName()] = $url;
         }
     }
     $page->setLinks($links);
     // Set the permissions.
     $page->setPermissions(CultureFeed_Cdb_Data_PagePermissions::parseFromCdbXml($xmlElement->permissions));
     // Set tagline.
     $page->setTagline((string) $xmlElement->tagline);
     return $page;
 }
Example #11
0
 public static function create(array $data)
 {
     $is = false;
     $contact = new self();
     if (isset($data['email'])) {
         $contact->setEmail($data['email']);
         $is = true;
     }
     if (isset($data['phones'])) {
         $contact->setPhones($data['phones']);
         $is = true;
     }
     if (isset($data['email'])) {
         $contact->setEmail($data['email']);
         $is = true;
     }
     if (isset($data['site'])) {
         $contact->setSite($data['site']);
         $is = true;
     }
     if (isset($data['facebook'])) {
         $contact->setFacebook($data['facebook']);
         $is = true;
     }
     if ($is == false) {
         return null;
     }
     return $contact;
 }
Example #12
0
 /**
  * @param \SimpleXMLElement $xmlElement
  * @return User
  */
 public static function parseFromXml(\SimpleXMLElement $xmlElement)
 {
     $user = new self();
     if (!empty($xmlElement->uid)) {
         $user->setUid((string) $xmlElement->uid);
     }
     if (!empty($xmlElement->nick)) {
         $user->setNick((string) $xmlElement->nick);
     }
     if (!empty($xmlElement->email)) {
         $user->setEmail((string) $xmlElement->email);
     }
     return $user;
 }
Example #13
0
 public static function createStudentFromId($id)
 {
     $student = new self();
     $query = "SELECT * FROM TUSERS U JOIN TSTUDENTS S ON U.`User ID` = S.`User ID` WHERE U.`User ID` = {$id}";
     $user = db_select($query);
     $student->setUserId($id);
     $student->setFirstName($user[0]['First Name']);
     $student->setSurname($user[0]['Surname']);
     $student->setPrefferedName($user[0]['Preferred Name']);
     $student->setStudentId($user[0]['Student ID']);
     $student->setEmail($user[0]['Email']);
     $student->setRole($user[0]['Role']);
     $student->setGender($user[0]['Gender']);
     $student->setDateOfBirth($user[0]['DOB']);
     $student->setValidation($user[0]['Validation']);
     return $student;
 }
Example #14
0
 private static function create(FingerPrint $fingerPrint, $id, DateTime $date, $email, $totalItems, $totalOrder, $quantityInstallments, $ip, $origin, CustomerBillingData $customerBillingData, CustomerShippingData $shippingData, Payment $payment, Item $item, Passenger $passenger = null, Connection $connection = null, HotelReservation $hotelReservation = null)
 {
     $instance = new self();
     $instance->setFingerPrint($fingerPrint);
     $instance->setId($id);
     $instance->setDate($date);
     $instance->setEmail($email);
     $instance->setTotalItems($totalItems);
     $instance->setTotalOrder($totalOrder);
     $instance->setQuantityInstallments($quantityInstallments);
     $instance->setIp($ip);
     $instance->setOrigin($origin);
     $instance->setBillingData($customerBillingData);
     $instance->setShippingData($shippingData);
     $instance->addPayment($payment);
     $instance->addItem($item);
     if (null !== $passenger) {
         $instance->addPassenger($passenger);
     }
     if (null !== $connection) {
         $instance->addConnection($connection);
     }
     if (null !== $hotelReservation) {
         $instance->addHotelReservation($hotelReservation);
     }
     return $instance;
 }