This one used Lumen and is now deprecated. Use [app](https://git.shikiryu.com/ReadLaterByEmail/app) instead.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
941 B

<?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;
$link = $request->input('u');
$link = filter_var($link, FILTER_VALIDATE_URL);
if ($link === false) {
return response()->json(['error' => 'Invalid link.'], 422);
}
$title = $request->input('t') ?: '';
$email_sent = mail($email, 'New link : '.$title, $link);
if ($email_sent) {
return response()->json(['info' => 'Email sent.']);
}
return response()->json(['error' => 'An error occured while sending email'], 500);
}
}