Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
eai04191 2019-01-14 21:38:34 +09:00
commit 11836ddd43
10 changed files with 191 additions and 7 deletions

View File

@ -35,3 +35,8 @@ SPARKPOST_SECRET=
PUSHER_APP_ID= PUSHER_APP_ID=
PUSHER_APP_KEY= PUSHER_APP_KEY=
PUSHER_APP_SECRET= PUSHER_APP_SECRET=
# (Optional) reCAPTCHA Key
# https://www.google.com/recaptcha
NOCAPTCHA_SECRET=
NOCAPTCHA_SITEKEY=

View File

@ -3,7 +3,7 @@ FROM php:7.1-apache
ENV APACHE_DOCUMENT_ROOT /var/www/html/public ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y git libpq-dev \ && apt-get install -y git libpq-dev unzip \
&& docker-php-ext-install pdo_pgsql \ && docker-php-ext-install pdo_pgsql \
&& curl -sS https://getcomposer.org/installer | php \ && curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \ && mv composer.phar /usr/local/bin/composer \

View File

@ -47,11 +47,18 @@ class RegisterController extends Controller
*/ */
protected function validator(array $data) protected function validator(array $data)
{ {
return Validator::make($data, [ $rules = [
'name' => 'required|string|regex:/^[a-zA-Z0-9_-]+$/u|max:15|unique:users', 'name' => 'required|string|regex:/^[a-zA-Z0-9_-]+$/u|max:15|unique:users',
'email' => 'required|string|email|max:255|unique:users', 'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed', 'password' => 'required|string|min:6|confirmed'
], ];
// reCAPTCHAのキーが設定されている場合、判定を有効化
if (!empty(config('captcha.secret'))) {
$rules['g-recaptcha-response'] = 'required|captcha';
}
return Validator::make($data, $rules,
['name.regex' => 'ユーザー名には半角英数字とアンダーバー、ハイフンのみ使用できます。'], ['name.regex' => 'ユーザー名には半角英数字とアンダーバー、ハイフンのみ使用できます。'],
['name' => 'ユーザー名'] ['name' => 'ユーザー名']
); );

View File

@ -2,8 +2,6 @@
namespace App\MetadataResolver; namespace App\MetadataResolver;
use Illuminate\Support\Facades\Log;
class DLsiteResolver implements Resolver class DLsiteResolver implements Resolver
{ {
public function resolve(string $url): Metadata public function resolve(string $url): Metadata

View File

@ -12,6 +12,7 @@ class MetadataResolver implements Resolver
'~ec\.toranoana\.jp/tora_r/ec/item/.*~' => ToranoanaResolver::class, '~ec\.toranoana\.jp/tora_r/ec/item/.*~' => ToranoanaResolver::class,
'~iwara\.tv/videos/.*~' => IwaraResolver::class, '~iwara\.tv/videos/.*~' => IwaraResolver::class,
'~www\.dlsite\.com/.*/work/=/product_id/..\d+\.html~' => DLsiteResolver::class, '~www\.dlsite\.com/.*/work/=/product_id/..\d+\.html~' => DLsiteResolver::class,
'~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class,
'/.*/' => OGPResolver::class '/.*/' => OGPResolver::class
]; ];

View File

@ -0,0 +1,93 @@
<?php
namespace App\MetadataResolver;
class PixivResolver implements Resolver
{
/**
* サムネイル画像 URL から最大長辺 1200px の画像 URL に変換する
*
* @param string $thumbnailUrl サムネイル画像 URL
* @return string 1200px の画像 URL
*/
public function thumbnailToMasterUrl(string $thumbnailUrl):string
{
$temp = str_replace("/c/128x128", "", $thumbnailUrl);
$largeUrl = str_replace("square1200.jpg", "master1200.jpg", $temp);
return $largeUrl;
}
/**
* 直リン可能な pixiv.cat のプロキシ URL に変換する
* HUGE THANKS TO PIXIV.CAT!
*
* @param string $pixivUrl i.pximg URL
* @return string i.pixiv.cat URL
*/
public function proxize(string $pixivUrl):string
{
return str_replace("i.pximg.net", "i.pixiv.cat", $pixivUrl);
}
public function resolve(string $url): Metadata
{
preg_match("~illust_id=(\d+)~", parse_url($url)["query"], $match);
$illustId = $match[1];
// 漫画ページかつページ数あり
if (strpos(parse_url($url)["query"], "mode=manga_big") && strpos(parse_url($url)["query"], "page=")) {
preg_match("~page=(\d+)~", parse_url($url)["query"], $match);
$page = $match[1];
// 未ログインでは漫画ページを開けないため、URL を作品ページに変換する
$url = str_replace("mode=manga_big", "mode=medium", $url);
$client = new \GuzzleHttp\Client();
$res = $client->get($url);
if ($res->getStatusCode() === 200) {
$ogpResolver = new OGPResolver();
$metadata = $ogpResolver->parse($res->getBody());
preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illustId}_p0_square1200\.jpg~", $res->getBody(), $match);
$illustThumbnailUrl = $match[0];
$illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl);
// 指定ページに変換
$illustUrl = str_replace("p0_master", "p{$page}_master", $illustUrl);
$metadata->image = $this->proxize($illustUrl);
return $metadata;
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
} else {
$client = new \GuzzleHttp\Client();
$res = $client->get($url);
if ($res->getStatusCode() === 200) {
$ogpResolver = new OGPResolver();
$metadata = $ogpResolver->parse($res->getBody());
// OGP がデフォルト画像であるようならなんとかして画像を取得する
if (strpos($metadata->image, "pixiv_logo.gif") || strpos($metadata->image, "pictures.jpg")) {
// 作品ページの場合のみ対応
if (strpos(parse_url($url)["query"], "mode=medium")) {
preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illustId}(_p0)?_square1200\.jpg~", $res->getBody(), $match);
$illustThumbnailUrl = $match[0];
$illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl);
$metadata->image = $this->proxize($illustUrl);
}
}
return $metadata;
} else {
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}
}

View File

@ -6,6 +6,7 @@
"type": "project", "type": "project",
"require": { "require": {
"php": ">=7.0.0", "php": ">=7.0.0",
"anhskohbo/no-captcha": "^3.0",
"doctrine/dbal": "^2.9", "doctrine/dbal": "^2.9",
"fideloper/proxy": "~3.3", "fideloper/proxy": "~3.3",
"guzzlehttp/guzzle": "^6.3", "guzzlehttp/guzzle": "^6.3",

61
composer.lock generated
View File

@ -4,8 +4,67 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "6ac4cd158b1f93a24e21fce57d4404c8", "content-hash": "4a3dffd3f7adecbb805a02c43f5c1f25",
"packages": [ "packages": [
{
"name": "anhskohbo/no-captcha",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/anhskohbo/no-captcha.git",
"reference": "164715a2de0fded5979e7a9b7721785d72a4a7d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/anhskohbo/no-captcha/zipball/164715a2de0fded5979e7a9b7721785d72a4a7d3",
"reference": "164715a2de0fded5979e7a9b7721785d72a4a7d3",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.2",
"illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*",
"php": ">=5.5.5"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Anhskohbo\\NoCaptcha\\NoCaptchaServiceProvider"
],
"aliases": {
"NoCaptcha": "Anhskohbo\\NoCaptcha\\Facades\\NoCaptcha"
}
}
},
"autoload": {
"psr-4": {
"Anhskohbo\\NoCaptcha\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "anhskohbo",
"email": "anhskohbo@gmail.com"
}
],
"description": "No CAPTCHA reCAPTCHA For Laravel.",
"keywords": [
"captcha",
"laravel",
"laravel4",
"laravel5",
"no-captcha",
"recaptcha"
],
"time": "2018-08-27T02:16:31+00:00"
},
{ {
"name": "dnoegel/php-xdg-base-dir", "name": "dnoegel/php-xdg-base-dir",
"version": "0.1", "version": "0.1",

View File

@ -99,6 +99,10 @@ return [
'attribute-name' => [ 'attribute-name' => [
'rule-name' => 'custom-message', 'rule-name' => 'custom-message',
], ],
'g-recaptcha-response' => [
'required' => '「私はロボットではありません」にチェックを入れてください。',
'captcha' => 'reCAPTCHAチェックに失敗しました。何度試しても解決しない場合、管理者にお問い合わせください。',
],
], ],
/* /*

View File

@ -2,6 +2,12 @@
@section('title', '新規登録') @section('title', '新規登録')
@push('head')
@if (!empty(config('captcha.secret')))
{!! NoCaptcha::renderJs() !!}
@endif
@endpush
@section('content') @section('content')
<div class="container"> <div class="container">
<h2>新規登録</h2> <h2>新規登録</h2>
@ -53,6 +59,16 @@
</div> </div>
</div> </div>
</div> </div>
@if (!empty(config('captcha.secret')))
<div class="form-row ml-1 mt-2 my-4">
<div class="mx-auto">
{!! NoCaptcha::display() !!}
</div>
@if ($errors->has('g-recaptcha-response'))
<div class="invalid-feedback d-block text-center">{{ $errors->first('g-recaptcha-response') }}</div>
@endif
</div>
@endif
<div class="text-center"> <div class="text-center">
<button class="btn btn-primary btn-lg" type="submit">登録</button> <button class="btn btn-primary btn-lg" type="submit">登録</button>