Commit 5a23d7f5 authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '1107-contact-and-donation-form-error' into 'development'

Resolve "Contact and donation Form error"

Closes #1107

See merge request !1828
parents 2f348141 5f68c624
......@@ -155,7 +155,7 @@ class RequestFetcher extends Command
Log::error($error);
}
if ($responseCode !== 200) {
if ($responseCode !== 200 && $responseCode !== 201) {
Log::debug($resulthash);
Log::debug("Got responsecode " . $responseCode . " fetching \"" . curl_getinfo($info["handle"], CURLINFO_EFFECTIVE_URL) . "\n");
} else {
......
......@@ -2,9 +2,9 @@
namespace App\Http\Controllers;
use App\Mail\Kontakt;
use App\Mail\Sprachdatei;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use Illuminate\Http\Response;
use LaravelLocalization;
use Mail;
......@@ -58,31 +58,81 @@ class MailController extends Controller
$messageType = "error";
$returnMessage = trans('kontakt.error.1');
} else {
# Wir versenden die Mail des Benutzers an uns:
$mailto = "support@metager.org";
if (LaravelLocalization::getCurrentLocale() === "de") {
$mailto = "support+46521@metager.de";
}
$message = $request->input('message');
$subject = $request->input('subject');
$files = [];
# Wir versenden die Mail des Benutzers an uns:
$postdata = [
"alert" => true,
"autorespond" => true,
"source" => "API",
"name" => $name,
"email" => $replyTo,
"subject" => $subject,
"ip" => $request->ip(),
"deptId" => 5,
"message" => "data:text/plain;charset=utf-8, $message",
"attachments" => []
];
if($request->has("attachments") && is_array($request->file("attachments"))){
$files = $request->file("attachments");
}
foreach($request->file("attachments") as $attachment){
$postdata["attachments"][] = [
$attachment->getClientOriginalName() => "data:" . $attachment->getMimeType() . ";base64," . base64_encode(file_get_contents($attachment->getRealPath()))
];
}
}
Mail::to($mailto)
->send(new Kontakt($name, $replyTo, $subject, $message, $files));
if (LaravelLocalization::getCurrentLocale() === "de") {
$postdata["deptId"] = 1;
}
$returnMessage = trans('kontakt.success.1');
$messageType = "success";
$postdata = json_encode($postdata);
$resulthash = md5($subject . $message);
$mission = [
"resulthash" => $resulthash,
"url" => env("TICKET_URL", "https://metager.de"),
"useragent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
"username" => null,
"password" => null,
"headers" => [
"X-API-Key" => env("TICKET_APIKEY", ""),
"Content-Type" => "application/json",
"Content-Length" => strlen($postdata)
],
"cacheDuration" => 0,
"name" => "Ticket",
"curlopts" => [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_LOW_SPEED_TIME => 20,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 20
]
];
$mission = json_encode($mission);
Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission);
// Fetch the result
$answer = Redis::blpop($resulthash, 20);
// Fehlerfall
if(empty($answer) || (is_array($answer) && sizeof($answer) === 2 && $answer[1] === "no-result")){
$messageType = "error";
$returnMessage = trans('kontakt.error.2', ["email" => env("MAIL_USERNAME", "support+46521@metager.de")]);
}else{
$returnMessage = trans('kontakt.success.1', ["email" => $replyTo]);
$messageType = "success";
}
}
return view('kontakt.kontakt')
->with('title', 'Kontakt')
->with('js', ['lib.js'])
->with($messageType, $returnMessage);
}
public function donation(Request $request)
......@@ -173,11 +223,65 @@ class MailController extends Controller
$message .= "\r\nNachricht: " . $nachricht;
try {
Mail::to("spenden@suma-ev.de")
->send(new \App\Mail\Spende($email, $message, $name));
$postdata = [
"alert" => true,
"autorespond" => true,
"source" => "API",
"name" => $name,
"email" => $email,
"subject" => "MetaGer - Spende",
"ip" => $request->ip(),
"deptId" => 4,
"message" => "data:text/plain;charset=utf-8, $message",
];
if (LaravelLocalization::getCurrentLocale() === "de") {
$postdata["deptId"] = 4;
}
$messageType = "success";
$messageToUser = "Herzlichen Dank!! Wir haben Ihre Spendenbenachrichtigung erhalten.";
if($email === "anonymous@suma-ev.de"){
$postdata["autorespond"] = false;
}
$postdata = json_encode($postdata);
$resulthash = md5($message);
$mission = [
"resulthash" => $resulthash,
"url" => env("TICKET_URL", "https://metager.de"),
"useragent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
"username" => null,
"password" => null,
"headers" => [
"X-API-Key" => env("TICKET_APIKEY", ""),
"Content-Type" => "application/json",
"Content-Length" => strlen($postdata)
],
"cacheDuration" => 0,
"name" => "Ticket",
"curlopts" => [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_LOW_SPEED_TIME => 20,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 20
]
];
$mission = json_encode($mission);
Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission);
// Fetch the result
$answer = Redis::blpop($resulthash, 20);
// Fehlerfall
if(empty($answer) || (is_array($answer) && sizeof($answer) === 2 && $answer[1] === "no-result")){
$messageType = "error";
$messageToUser = "Beim Senden Ihrer Spendenbenachrichtigung ist ein Fehler auf unserer Seite aufgetreten. Bitte schicken Sie eine E-Mail an: dominik@suma-ev.de, damit wir uns darum kümmern können.";
}else{
$messageToUser = "Herzlichen Dank!! Wir haben Ihre Spendenbenachrichtigung erhalten.";
$messageType = "success";
}
} catch (\Swift_TransportException $e) {
Log::error($e->getMessage());
$messageType = "error";
......
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Kontakt extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($name, $from, $subject, $message, $attachments)
{
$this->name = $name;
$this->reply = $from;
$this->subject = $subject;
$this->message = $message;
$this->attachedFiles = $attachments;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$mail = $this->from($this->reply, $this->name)
->subject($this->subject)
->text('kontakt.mail')
->with('messageText', $this->message);
foreach($this->attachedFiles as $attachment){
$mail->attachData(file_get_contents($attachment->getRealPath()), $attachment->getClientOriginalName());
}
return $mail;
}
}
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Spende extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($from, $message, $name)
{
$this->subject = "MetaGer - Spende";
$this->reply = $from;
$this->message = $message;
$this->name = $name;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from($this->reply, $this->name)
->subject($this->subject)
->text('kontakt.mail')
->with('messageText', $this->message);
}
}
......@@ -19,5 +19,6 @@ Röselerstr. 3
30159 Hannover
Germany',
'error.1' => 'Tut uns leid, aber leider haben wir mit Ihrer Kontaktanfrage keine Daten erhalten. Die Nachricht wurde nicht versandt.',
'success.1' => 'Ihre Nachricht wurde uns erfolgreich zugestellt. Vielen Dank dafür! Wir werden diese schnellstmöglich bearbeiten und uns dann ggf. wieder bei Ihnen melden.'
"error.2" => 'Beim Versand Ihrer Nachricht ist ein Fehler aufgetreten. Sie können uns direkt unter folgender E-Mail Adresse kontaktieren: :email',
'success.1' => 'Ihre Nachricht wurde uns erfolgreich zugestellt. Eine erste automatische Bestätigung haben wir an :email gesendet.'
];
......@@ -17,5 +17,6 @@ Röselerstr. 3
30159 Hannover
Germany',
'error.1' => 'We are sorry, but unfortunately we did not receive any data with your contact request. The message was not sent.',
'success.1' => 'Your message was successfully sent to us. Thanks a lot for this! We will process this as soon as possible and then contact you again if necessary.'
"error.2" => 'There was an error delivering your message. You can contact us directly under :email',
'success.1' => 'Your message was delivered successfully. A first automatic reply was sent to :email.'
];
......@@ -17,19 +17,19 @@
{{ csrf_field() }}
<input type="hidden" name="pcsrf" value="{{ base64_encode(\time()) }}">
<div class="form-group kontakt-form-group">
<input class="form-control" name="name" placeholder="{!!trans('kontakt.form.name')!!}" type="text" required @if(isset($formerrors) && Request::has('name'))value="{{Request::input('name')}}"@endif>
<input class="form-control" name="name" placeholder="{!!trans('kontakt.form.name')!!}" type="text" required @if((isset($formerrors) || !empty($error)) && Request::has('name'))value="{{Request::input('name')}}"@endif>
</div>
<div class="form-group kontakt-form-group">
<input class="form-control" name="email" placeholder="{!! trans('kontakt.form.5') !!}" type="email" required @if(isset($formerrors) && Request::has('email'))value="{{Request::input('email')}}"@endif>
<input class="form-control" name="email" placeholder="{!! trans('kontakt.form.5') !!}" type="email" required @if((isset($formerrors) || !empty($error)) && Request::has('email'))value="{{Request::input('email')}}"@endif>
</div>
<div class="form-group kontakt-form-group">
<input class="form-control" name="subject" placeholder="{!! trans('kontakt.form.7') !!}" type="text" required @if(isset($formerrors) && Request::has('subject'))value="{{Request::input('subject')}}"@endif>
<input class="form-control" name="subject" placeholder="{!! trans('kontakt.form.7') !!}" type="text" required @if((isset($formerrors) || !empty($error)) && Request::has('subject'))value="{{Request::input('subject')}}"@endif>
</div>
<div class="form-group kontakt-form-group">
@if(isset($url) && $url !== "")
<label for="message">Wenn MetaGer bestimmte Webseiten nicht angezeigt hat, von denen Sie wissen, dass es sie gibt: Bitte nennen Sie deren Adresse/n (http:// ...???...). Wir werden das detailliert untersuchen.</label>
@endif
<textarea class="form-control" id="message" name="message" placeholder="{!! trans('kontakt.form.6') !!}" required>@if(isset($formerrors) && Request::has('message')){{Request::input('message')}}@endif</textarea>
<textarea class="form-control" id="message" name="message" placeholder="{!! trans('kontakt.form.6') !!}" required>@if((isset($formerrors) || !empty($error)) && Request::has('message')){{Request::input('message')}}@endif</textarea>
</div>
<div class="form-group kontakt-form-group">
<label for="attachments">@lang("kontakt.form.9")</label>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment