public static function sendNewBookingMail($booking, $userId) { $user = User::where('id', $userId)->first(); $date = strftime('%A %e %B %Y, %H.%M (%Z)', $booking->startUts); $twig = UserFrosting::getInstance()->view()->getEnvironment(); $template = $twig->loadTemplate("mail/sendNewBookingMail.twig"); $subject = 'Ny taxibokning'; if ($booking->originCity && $booking->destinationCity) { $subject = 'Ny taxibokning från ' . $booking->originCity . ' till ' . $booking->destinationCity; if ($booking->originCity == $booking->destinationCity) { $subject = 'Ny taxibokning inom ' . $booking->originCity; } } $notification = new Notification($template); $notification->from("*****@*****.**", $user->title, $user->email, $user->title); // future bookings $bookings = Booking::where('user_id', $userId)->where('id', '!=', $booking->id)->where('startUts', '>', time() - 21600)->get(); $htmlRows = array(); $statuses = array('new' => 'Ohanterat', 'accepted' => 'Accepterad', 'rejected' => 'Avvisad'); foreach ($bookings as $key => $futureBooking) { $backgroundColor = $key % 2 == 0 ? '#e9e9e9' : '#ffffff'; $style = "background-color: {$backgroundColor}; font-size: 12px; padding: 10px"; $buttonHtml = ''; if ($futureBooking->status == 'new') { $buttonHtml = '<a href="' . UserFrosting::getInstance()->site->uri['public'] . '/booking/' . $futureBooking->id . '/accept/' . $futureBooking->hash . '" style="background-color: #8ea604; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Acceptera</a><a href="' . UserFrosting::getInstance()->site->uri['public'] . '/booking/' . $futureBooking->id . '/reject/' . $futureBooking->hash . '" style="background-color: #c00000; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Avslå</a>'; //$buttonHtml = '<a href="http://taxibooking.allanth.dk/?action=accept&bookingId=' . $futureBooking->id . '&hash=' . $futureBooking->hash . '&c=' . $client->name . '" style="background-color: #8ea604; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Acceptera</a><a href="http://taxibooking.allanth.dk/?action=reject&bookingId=' . $futureBooking->id . '&hash=' . $futureBooking->hash . '&c=' . $client->name . '" style="background-color: #C00000; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Avslå</a>'; } $htmlRows[] = "\n <tr valign=\"top\">\n <td style=\"{$style}\" colspan=\"2\">Från <strong>" . htmlspecialchars($futureBooking->origin) . "</strong> till <strong>" . htmlspecialchars($futureBooking->destination) . "</strong></td>\n </tr>\n <tr valign=\"top\">\n <td style=\"{$style}\" width=\"60%\">\n Avresedatum: " . htmlspecialchars(strftime('%A %e %B %Y, %H.%M (%Z)', $futureBooking->startUts)) . "<br />\n Namn: " . htmlspecialchars($futureBooking->name) . "<br />\n Email: " . htmlspecialchars($futureBooking->email) . "<br />\n Telefon: " . htmlspecialchars($futureBooking->phone) . "<br /><br />\n Avstånd: " . htmlspecialchars($futureBooking->distance) . "<br />\n Körtid: " . htmlspecialchars($futureBooking->duration) . "<br />\n Pris: " . htmlspecialchars($futureBooking->price) . ":- kr.\n </td>\n <td style=\"{$style}\" width=\"40%\"><span style=\"font-size: 20px\">Tur: " . htmlspecialchars($futureBooking->alphaId) . "</span>\n <br />Status: " . htmlspecialchars($statuses[$futureBooking->status]) . "<br /><br />{$buttonHtml}</td> \n </tr>"; } $futureBookingsHtml = ''; if (count($htmlRows)) { $futureBookingsHtml = "\n <p><strong>Kommende bookings</strong></p>\n <table cellspacing=\"0\">" . implode("", $htmlRows) . " \n </table>\n "; } $notification->addEmailRecipient($user->email, $user->title, ['date' => $date, 'booking' => $booking, 'client' => $user, 'headerLine1' => $user->title, 'headerLine2' => $subject, 'footerLine' => "Skickat " . strftime('%A %e %B %Y, %H.%M (%Z)'), 'subject' => $subject, 'futureBookingsHtml' => $futureBookingsHtml]); $success = NULL; try { $success = $notification->send(); } catch (\phpmailerException $e) { print $e->errorMessage(); $app->halt(500); } return $success; }
/** * Generate an activation token for a user. * * This generates a token to use for activating a new account, resetting a lost password, etc. * @param string $gen specify an existing token that, if we happen to generate the same value, we should regenerate on. * @return string */ public static function generateActivationToken($gen = null) { do { $gen = md5(uniqid(mt_rand(), false)); } while (User::where('secret_token', $gen)->first()); return $gen; }
/** * Process UserFrosting registration. This function is copied form UserFrosting class and modified to register the user first * and then save the Open Authentication details * @return \UserFrosting\User */ public function ufRegister() { // POST: user_name, display_name, email, title, password, passwordc, captcha, spiderbro, csrf_token $post = $this->_app->request->post(); // Get the alert message stream $ms = $this->_app->alerts; // Check the honeypot. 'spiderbro' is not a real field, it is hidden on the main page and must be submitted with its default value for this to be processed. if (!$post['spiderbro'] || $post['spiderbro'] != "http://") { error_log("Possible spam received:" . print_r($this->_app->request->post(), true)); $ms->addMessage("danger", "Aww hellllls no!"); $this->_app->halt(500); // Don't let on about why the request failed ;-) } // Load the request schema $requestSchema = new \Fortress\RequestSchema($this->_app->config('schema.path') . "/forms/register.json"); // Set up Fortress to process the request $rf = new \Fortress\HTTPRequestFortress($ms, $requestSchema, $post); // Security measure: do not allow registering new users until the master account has been created. if (!\UserFrosting\User::find($this->_app->config('user_id_master'))) { $ms->addMessageTranslated("danger", "MASTER_ACCOUNT_NOT_EXISTS"); $this->_app->halt(403); } // Check if registration is currently enabled if (!$this->_app->site->can_register) { $ms->addMessageTranslated("danger", "ACCOUNT_REGISTRATION_DISABLED"); $this->_app->halt(403); } // Prevent the user from registering if he/she is already logged in if (!$this->_app->user->isGuest()) { $ms->addMessageTranslated("danger", "ACCOUNT_REGISTRATION_LOGOUT"); $this->_app->halt(200); } // Sanitize data $rf->sanitize(); // Validate, and halt on validation errors. $error = !$rf->validate(true); // Get the filtered data $data = $rf->data(); // Check captcha, if required if ($this->_app->site->enable_captcha == "1") { if (!$data['captcha'] || md5($data['captcha']) != $_SESSION['userfrosting']['captcha']) { $ms->addMessageTranslated("danger", "CAPTCHA_FAIL"); $error = true; } } // Remove captcha, password confirmation from object data $rf->removeFields(['captcha', 'passwordc']); // Perform desired data transformations. Is this a feature we could add to Fortress? $data['display_name'] = trim($data['display_name']); $data['locale'] = $this->_app->site->default_locale; if ($this->_app->site->require_activation) { $data['flag_verified'] = 0; } else { $data['flag_verified'] = 1; } // Check if username or email already exists if (\UserFrosting\User::where('user_name', $data['user_name'])->first()) { $ms->addMessageTranslated("danger", "ACCOUNT_USERNAME_IN_USE", $data); $error = true; } if (\UserFrosting\User::where('email', $data['email'])->first()) { $ms->addMessageTranslated("danger", "ACCOUNT_EMAIL_IN_USE", $data); $error = true; } // Halt on any validation errors if ($error) { $this->_app->halt(400); } // Get default primary group (is_default = GROUP_DEFAULT_PRIMARY) $primaryGroup = \UserFrosting\Group::where('is_default', GROUP_DEFAULT_PRIMARY)->first(); // Check that a default primary group is actually set if (!$primaryGroup) { $ms->addMessageTranslated("danger", "ACCOUNT_REGISTRATION_BROKEN"); error_log("Account registration is not working because a default primary group has not been set."); $this->_app->halt(500); } $data['primary_group_id'] = $primaryGroup->id; // Set default title for new users $data['title'] = $primaryGroup->new_user_title; // Hash password $data['password'] = \UserFrosting\Authentication::hashPassword($data['password']); // Create the user $user = new \UserFrosting\User($data); // Add user to default groups, including default primary group $defaultGroups = \UserFrosting\Group::where('is_default', GROUP_DEFAULT)->get(); $user->addGroup($primaryGroup->id); foreach ($defaultGroups as $group) { $user->addGroup($group->id); } // Create sign-up event $user->newEventSignUp(); // Store new user to database $user->save(); if ($this->_app->site->require_activation) { // Create verification request event $user->newEventVerificationRequest(); $user->save(); // Re-save with verification event // Create and send verification email $twig = $this->_app->view()->getEnvironment(); $template = $twig->loadTemplate("mail/activate-new.twig"); $notification = new \UserFrosting\Notification($template); $notification->fromWebsite(); // Automatically sets sender and reply-to $notification->addEmailRecipient($user->email, $user->display_name, ["user" => $user]); try { $notification->send(); } catch (\phpmailerException $e) { $ms->addMessageTranslated("danger", "MAIL_ERROR"); error_log('Mailer Error: ' . $e->errorMessage()); //$this->_app->halt(500); } $ms->addMessageTranslated("success", "ACCOUNT_REGISTRATION_COMPLETE_TYPE2"); } else { // No activation required $ms->addMessageTranslated("success", "ACCOUNT_REGISTRATION_COMPLETE_TYPE1"); } // Srinivas : The OAuth function will need the user object, so that it can get the ID to save the OAuth record // Invoking this in OAuth to register using return $user; }