2016-07-21 22:01:57 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Middlewares;
|
|
|
|
|
|
|
|
use \Pecee\Http\Middleware\IMiddleware;
|
|
|
|
use \Pecee\Http\Request;
|
|
|
|
use App\Exceptions\E;
|
2016-07-28 15:09:29 +08:00
|
|
|
use Validate;
|
2016-08-16 22:52:00 +08:00
|
|
|
use Utils;
|
2016-07-27 18:28:54 +08:00
|
|
|
use View;
|
2016-07-21 22:01:57 +08:00
|
|
|
|
|
|
|
class CheckPostMiddleware implements IMiddleware
|
|
|
|
{
|
|
|
|
public function handle(Request $request)
|
|
|
|
{
|
2016-08-16 13:27:06 +08:00
|
|
|
if (Utils::getValue('email', $_POST) != "") {
|
2016-08-06 19:38:37 +08:00
|
|
|
if (!Validate::email($_POST['email'])) {
|
2016-08-16 22:52:00 +08:00
|
|
|
View::json('邮箱或角色名格式错误', 3);
|
2016-07-21 22:01:57 +08:00
|
|
|
}
|
2016-08-16 13:27:06 +08:00
|
|
|
$_SESSION['auth_type'] = 'email';
|
|
|
|
} elseif (Utils::getValue('username', $_POST) != "") {
|
|
|
|
if (!Validate::playerName($_POST['username'])) {
|
2016-08-16 22:52:00 +08:00
|
|
|
View::json('邮箱或角色名格式错误', 3);
|
2016-08-16 13:27:06 +08:00
|
|
|
}
|
|
|
|
$_SESSION['auth_type'] = 'username';
|
|
|
|
} else {
|
|
|
|
View::json('无效的参数', 3);
|
|
|
|
}
|
2016-07-21 22:01:57 +08:00
|
|
|
|
2016-08-16 13:27:06 +08:00
|
|
|
if ($request->getUri() == "/auth/forgot") return true;
|
2016-07-21 22:01:57 +08:00
|
|
|
|
2016-08-16 13:27:06 +08:00
|
|
|
if (isset($_POST['password']) && $_POST['password'] != "") {
|
|
|
|
return true;
|
2016-07-21 22:01:57 +08:00
|
|
|
} else {
|
2016-08-16 13:27:06 +08:00
|
|
|
View::json('密码不能为空哦', 2);
|
2016-07-21 22:01:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|