Commit c56ed598 authored by ZeMKI's avatar ZeMKI

Bugfix new person on public url

* now you can add a person using public urls.
* now you can set up a name for the interviewee.
parent a7bb4a1e
......@@ -25,7 +25,7 @@ class PublicInterviewUrlController extends Controller
$PublicInterviewUrl->study_id = request()->study;
$PublicInterviewUrl->created_at = Carbon::now()->toDateTimeString('minutes');
$PublicInterviewUrl->save();
$url = (string)URLShortener::shorten(url('/interviews/new?study=' . request()->study . '&t=' . $uuid));
$url = (string)URLShortener::shorten(url('/interviews/new?study=' . request()->study . '&interviewed='.(request()->name ?? '').'&t=' . $uuid));
$PublicInterviewUrl->short_url_id = Carbon::now()->toDateTimeString('minutes');
return response()->json(['message' => 'Url Created! Refresh the page to access the interview list.', 'url' => $url], 200);
} else
......
......@@ -5,6 +5,7 @@ namespace App\Http\Middleware;
use App\PublicInterviewUrl;
use Carbon\Carbon;
use Closure;
use Illuminate\Support\Facades\App;
use Spatie\WebhookServer\Exceptions\CouldNotCallWebhook;
use Spatie\WebhookServer\WebhookCall;
......@@ -26,8 +27,7 @@ class PublicInterviewTokenCheck
abort(403);
}
$uuid = request()->t;
$validToken = PublicInterviewUrl::isValid($uuid);
$validToken = PublicInterviewUrl::isValid($this->fetchToken($request));
if ($validToken)
{
if (is_null($validToken->first_opened_at))
......@@ -36,7 +36,8 @@ class PublicInterviewTokenCheck
$validToken->save();
}
if(request()->isMethod('post'))
$submitRequest = request()->isMethod('post') && request()->has("publicInterviewToken");
if($submitRequest)
{
$validToken->submitted_at = Carbon::now()->toDateTimeString('minutes');
......@@ -46,12 +47,33 @@ class PublicInterviewTokenCheck
return $next($request);
} else
{
WebhookCall::create()
->url('https://chat.zemki.uni-bremen.de/hooks/Jj3dDY2KzSFDS2kxZ/SvbmjdswXTASAXxC2GfgfTpFooK5Eo4kFBGPyDRrtsWmgED3')
->payload(['text' => 'Someone tried to do an interview with a wrong Token on Mesort from ' . request()->ip()])
->useSecret('Jj3dDY2KzSFDS2kxZ/SvbmjdswXTASAXxC2GfgfTpFooK5Eo4kFBGPyDRrtsWmgED3')
->dispatch();
if (!App::environment('local'))
{
WebhookCall::create()
->url('https://chat.zemki.uni-bremen.de/hooks/Jj3dDY2KzSFDS2kxZ/SvbmjdswXTASAXxC2GfgfTpFooK5Eo4kFBGPyDRrtsWmgED3')
->payload(['text' => 'Someone tried to do an interview with a wrong Token on Mesort from ' . request()->ip()])
->useSecret('Jj3dDY2KzSFDS2kxZ/SvbmjdswXTASAXxC2GfgfTpFooK5Eo4kFBGPyDRrtsWmgED3')
->dispatch();
}
abort(403, "Token not valid, contact your reference person.");
}
}
/**
* @param $request
* @return array
*/
private function fetchToken($request)
{
if (!$request->has("t"))
{
parse_str(parse_url(request()->headers->get('referer'))['query'], $url);
$uuid = $url['t'];
} else
{
$uuid = request()->t;
}
return $uuid;
}
}
......@@ -510,7 +510,7 @@ window.app = new Vue(
let self = this;
axios.post(
'interview/publicurl/create',
{study: this.interview.study},
{study: this.interview.study,name:this.interview.name},
).
then(
response =>
......
......@@ -1480,7 +1480,7 @@
saveinterview: async function()
{
let t = this.getUrlVars()['t'];
let publicInterviewToken = this.getUrlVars()['t'];
this.loading = true;
let self = this;
......@@ -1542,7 +1542,7 @@
{study: this.study.id},
{interviewed: this.interviewed},
{sorting: sortings},
{t: t ?? ''},
{publicInterviewToken: publicInterviewToken ?? ''},
);
......@@ -1559,8 +1559,7 @@
{
window.imagepreset = null;
self.loading = false;
let redirectUrl = t ? window.location.origin + self.productionUrl + '/interview/done' : '../';
window.location.href = redirectUrl;
window.location.href = publicInterviewToken ? window.location.origin + self.productionUrl + '/interview/done' : '../';
}, 1000);
}).catch(error =>
......
......@@ -19,7 +19,7 @@
<div class="modal opacity-0 pointer-events-none fixed w-full h-full top-0 left-0 flex items-center justify-center">
<div class="absolute w-full h-full bg-gray-900 opacity-50" @click="toggleModal()"></div>
<div class="modal-container bg-white w-11/12 md:max-w-md mx-auto rounded shadow-lg z-50 overflow-y-auto">
<div class="modal-container bg-white w-1/2 md:max-w-md mx-auto rounded shadow-lg z-50 overflow-y-auto">
<div @click="toggleModal()" class="absolute top-0 right-0 cursor-pointer flex flex-col items-center mt-4 mr-4 text-white text-sm z-50">
<svg class="fill-current text-white" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
......@@ -44,9 +44,14 @@
<p>{{__('Create a new url for a public interview')}}</p>
<p>{{__('The url won\'t be valid anymore as soon as the interview is submitted.')}}</p>
<p class="font-bold">{{__('If the url is not used within 48h, it will be deleted.')}}</p>
<p class="font-bold text-center">{{__('Interviewee Name')}}</p>
<input class="bg-white focus:outline-none focus:shadow-outline border border-gray-300 rounded-lg py-2 px-4 block w-full appearance-none leading-normal" type="text" v-model="interview.name" id="intervieweename">
<input class="bg-white focus:outline-none focus:shadow-outline border border-gray-300 rounded-lg py-2 px-4 block w-full appearance-none leading-normal" type="url" v-model="interview.url" id="publicUrl">
<!--Footer-->
<div class="flex justify-end pt-2">
<button class="px-4 bg-transparent p-3 rounded-lg text-blue-500 hover:bg-gray-100 hover:text-blue-400 mr-2" @click="createPublicUrl()">{{__('Create')}}</button>
......
......@@ -11,7 +11,7 @@
|
*/
Route::group(['middleware' => 'auth'], function () {
Route::group(['middleware' => 'interview'], function () {
Route::group(['prefix' => 'v1'], function () {
Route::post('getpresettokenimages', 'ApiController@getpresettokenimages');
Route::post('savetoken', 'ApiController@savetoken');
......
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