Example #1
0
 public function createCustomer()
 {
     $customer = new self();
     if ($customer->isGuest()) {
         $email = $customer->getEmail();
         $user = UserInfo::getByEmail($email);
         if (!$user) {
             $password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 10);
             $mh = Core::make('helper/mail');
             $mh->addParameter('siteName', Config::get('concrete.site'));
             $navhelper = Core::make('helper/navigation');
             $target = Page::getByPath('/login');
             if ($target) {
                 $link = $navhelper->getLinkToCollection($target, true);
                 if ($link) {
                     $mh->addParameter('link', $link);
                 }
             } else {
                 $mh->addParameter('link', '');
             }
             $valc = Core::make('helper/concrete/validation');
             $min = Config::get('concrete.user.username.minimum');
             $max = Config::get('concrete.user.username.maximum');
             $newusername = preg_replace("/[^A-Za-z0-9_]/", '', strstr($email, '@', true));
             while (!$valc->isUniqueUsername($newusername) || strlen($newusername) < $min) {
                 if (strlen($newusername) >= $max) {
                     $newusername = substr($newusername, 0, $max - 5);
                 }
                 $newusername .= rand(0, 9);
             }
             $user = UserInfo::add(array('uName' => $newusername, 'uEmail' => trim($email), 'uPassword' => $password));
             if (Config::get('concrete.user.registration.email_registration')) {
                 $mh->addParameter('username', trim($email));
             } else {
                 $mh->addParameter('username', $newusername);
             }
             $mh->addParameter('password', $password);
             $email = trim($email);
             $mh->load('new_user', 'vivid_store');
             // login the newly created user
             User::loginByUserID($user->getUserID());
             // new user password email
             $fromEmail = Config::get('vividstore.emailalerts');
             if (!$fromEmail) {
                 $fromEmail = "store@" . $_SERVER['SERVER_NAME'];
             }
             $fromName = Config::get('vividstore.emailalertsname');
             if ($fromName) {
                 $mh->from($fromEmail, $fromName);
             } else {
                 $mh->from($fromEmail);
             }
             $mh->to($email);
             $mh->sendMail();
         } else {
             // we're attempting to create a new user with an email that has already been used
             // earlier validation must have failed at this point, don't fetch the user
             $user = null;
         }
     } else {
         $user = $customer->getUserInfo();
     }
     return $user;
 }
Example #2
0
 public static function addUser($qID, $loc, $ans, $userID, $correct, $points, $color)
 {
     $answer = new self();
     $answer->user_id = $userID;
     $answer->location = $loc;
     $answer->ans = $ans;
     $answer->qID = $qID;
     $answer->color = $color;
     if ($ans == -999) {
         //meaning they didnt submit
         $answer->distanceAway = -999.99;
     } else {
         if (!is_object($correct)) {
             //meaning end of game
             $answer->distanceAway = -999.99;
         } else {
             if (Game::findGame()->type == "geo" || Game::findGame()->type == "pt" || Game::findGame()->type == "places") {
                 $answer->distanceAway = LatLong::findDistance($correct->location, $loc);
             } else {
                 $answer->distanceAway = abs($ans - $correct->value);
             }
         }
     }
     if ($ans > 100000) {
         $answer->distanceAway = round($answer->distanceAway, -5);
     }
     $answer->getUserInfo();
     $answer->updateUser();
     $answer->roundPoints = $points;
     return $answer;
 }