Exemplo n.º 1
0
 public static function sendRecover($email)
 {
     User::validateExistingEmail($email, UserFetcher::DB_TABLE);
     $user = UserFetcher::retrieveUsingEmail($email);
     if ($user[UserFetcher::DB_COLUMN_ACTIVE] != 1) {
         throw new Exception("Sorry, you account has been de-activated.");
     }
     $userId = $user[UserFetcher::DB_COLUMN_ID];
     $receiverName = $user[UserFetcher::DB_COLUMN_FIRST_NAME] . " " . $user[UserFetcher::DB_COLUMN_LAST_NAME];
     $genString = User::generateNewPasswordString($userId);
     # First, instantiate the SDK with your API credentials and define your domain.
     $mg = new Mailgun(App::getMailgunKey());
     $domain = App::getMailgunDomain();
     // Load mail template
     $emailVerificationTemplate = file_get_contents(ROOT_PATH . 'mail/templates/verify_recovery.html');
     $verifyAccountRecoveryLink = App::getDomainName() . "/login/set/" . $userId . "/" . $genString;
     try {
         # Now, compose and send the message.
         $mg->sendMessage($domain, ['from' => "SASS App admin@" . App::getHostname(), 'to' => $email, 'subject' => 'SASS Account Recovery', 'text' => 'Your mail does not support html', 'html' => $emailVerificationTemplate, 'recipient-variables' => '{"' . $email . '": {"id":' . $userId . ',"verifyAccountRecoveryLink":"' . $verifyAccountRecoveryLink . '","fullName":"' . $receiverName . '"}}']);
     } catch (Exception $e) {
         throw new Exception("Sorry, we could not send your recovery email. Please contact the secretariat at your earliest\n\t\t\tconvenience or submit a bug issue <a href='" . App::getGithubNewIssueUrl() . "' target='_blank'>here</a>.");
     }
 }
Exemplo n.º 2
0
 public static function generateNewPasswordString($id)
 {
     $unique = uniqid('', true);
     // generate a unique string
     $random = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 10);
     // generate a more random string
     $generatedString = $unique . $random;
     // a random and unique string
     User::validateId($id);
     UserFetcher::updateGenString($id, $generatedString);
     UserFetcher::updateGenStringTimeUpdate($id);
     return $generatedString;
 }