2018-04-26 23:02:06 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\User;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
|
|
|
|
|
|
|
class LinksController extends BaseController
|
|
|
|
{
|
|
|
|
public function add(Request $request)
|
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = $request->user()->first();
|
|
|
|
$email = $user->email;
|
2018-04-29 22:43:29 +02:00
|
|
|
|
|
|
|
$link = $request->input('u');
|
2018-04-26 23:02:06 +02:00
|
|
|
$link = filter_var($link, FILTER_VALIDATE_URL);
|
|
|
|
if ($link === false) {
|
|
|
|
return response()->json(['error' => 'Invalid link.'], 422);
|
|
|
|
}
|
|
|
|
|
2018-04-29 22:43:29 +02:00
|
|
|
$title = $request->input('t') ?: '';
|
|
|
|
|
|
|
|
$email_sent = mail($email, 'New link : '.$title, $link);
|
2018-04-26 23:02:06 +02:00
|
|
|
|
|
|
|
if ($email_sent) {
|
|
|
|
return response()->json(['info' => 'Email sent.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(['error' => 'An error occured while sending email'], 500);
|
|
|
|
}
|
|
|
|
}
|