Ejemplo n.º 1
0
 /**
  * send recovery password email for given user id
  * so that the user can set new password and enter the system
  * @param  int     $userId
  * @return boolean
  */
 public static function sendResetPasswordMail($userId, $template = 'recover')
 {
     if (!is_numeric($userId) || User::isLoged() && !Security::canEditUser($userId)) {
         return false;
     }
     $mail = '';
     $subject = '';
     switch ($template) {
         case 'invite':
             $mail = System::getEmailTemplate('email_invite');
             $subject = L\get('MailInviteSubject');
             break;
         case 'recover':
             $mail = System::getEmailTemplate('password_recovery_email');
             $subject = L\get('MailRecoverSubject');
             break;
         default:
             return false;
     }
     if (empty($mail)) {
         return false;
     }
     $userData = User::getPreferences($userId);
     $userEmail = User::getEmail($userData);
     if (empty($userEmail)) {
         return false;
     }
     /* generating invite hash and sending mail */
     $hash = User::generateRecoveryHash($userId, $userId . $userEmail . date(DATE_ISO8601));
     $href = Util\getCoreHost() . 'recover/reset-password/?h=' . $hash;
     /* replacing placeholders in template and subject */
     $replacements = array('{projectTitle}' => Config::getProjectName(), '{fullName}' => User::getDisplayName($userData), '{username}' => User::getUsername($userData), '{userEmail}' => $userEmail, '{creatorFullName}' => User::getDisplayName(), '{creatorUsername}' => User::getUsername(), '{creatorEmail}' => User::getEmail(), '{href}' => $href, '{link}' => '<a href="' . $href . '" >' . $href . '</a>');
     $search = array_keys($replacements);
     $replace = array_values($replacements);
     $mail = str_replace($search, $replace, $mail);
     $subject = str_replace($search, $replace, $subject);
     return @System::sendMail($userEmail, $subject, $mail);
 }