This commit is contained in:
Kekskurse 2019-12-25 18:49:20 +01:00
parent c69f125126
commit bf611c5529
7 changed files with 529 additions and 357 deletions

View file

@ -15,6 +15,7 @@ use App\Models\Invite;
use App\Models\Mail;
use App\Models\Setting;
use App\Models\User;
use Domnikl\Statsd\Client;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -27,14 +28,16 @@ class UserController extends BaseController
/*
* The Password login is just for the WebGUI
*/
public function passwordLogin(Request $request, Response $response)
public function passwordLogin(Request $request, Response $response, Client $statsd)
{
$statsd->count("login.try", 1);
//If Recptache is enabled check it at the beginning
if(Setting::getSettingValue("recaptcha_v2_login")) {
$reCaptcha = new ReCaptcha(Setting::getSettingValue("recaptcha_v2_secret"));
$reresponse = $reCaptcha->verify($request->input("g-recaptcha-response"));
if(!$reresponse->isSuccess()) {
$statsd->count("login.wrongcaptcha", 1);
throw new HTTPException(400, "Captcha validation failed");
}
}
@ -51,10 +54,12 @@ class UserController extends BaseController
//Check if a user is found
if($user == null) {
$statsd->count("login.wronguser", 1);
throw new HTTPException("400", "Username or Password wrong");
}
if(!password_verify($request->input("password"), $user->password)) {
$statsd->count("login.wrongpassword", 1);
throw new HTTPException("400", "Username or Password wrong");
}
@ -69,6 +74,8 @@ class UserController extends BaseController
$_SESSION["token"] = $token->token;
}
$statsd->count("login.success", 1);
return $response->withData(new AccessToken($token));
}

View file

@ -0,0 +1,31 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Domnikl\Statsd\Client;
class StatsdMiddelware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
/* @var $statsd \Domnikl\Statsd\Client */
$statsd = app(Client::class);
$statsd->count("request.all", 1);
/* @var $response \Illuminate\Http\Response */
$response = $next($request);
$statsd->count("request.".$response->getStatusCode(), 1);
return $response;
}
}

View file

@ -3,6 +3,7 @@
namespace App\Providers;
use Aws\S3\S3Client;
use Domnikl\Statsd\Connection\Blackhole;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
@ -31,5 +32,16 @@ class AppServiceProvider extends ServiceProvider
]);
return $s3;
});
$this->app->singleton(\Domnikl\Statsd\Client::class, function() {
$server = getenv("STATSD");
if($server && $server != "") {
$connection = new \Domnikl\Statsd\Connection\UdpSocket($server, 8125);
} else {
$connection = new Blackhole();
}
$statsd = new \Domnikl\Statsd\Client($connection, "account.".getenv("STATSD_PREFIX"));
return $statsd;
});
}
}

View file

@ -62,6 +62,7 @@ $app->singleton(
// ]);
$app->middleware(array(
\App\Http\Middleware\StatsdMiddelware::class,
TaGeSo\APIResponse\Middelware::class,
\App\Http\Middleware\CorsMiddleware::class
));

View file

@ -11,7 +11,8 @@
"phpmailer/phpmailer": "~6.0",
"tageso/api-response": "*",
"google/recaptcha": "^1.2",
"aws/aws-sdk-php":"^3."
"aws/aws-sdk-php":"^3.",
"domnikl/statsd": "~3.0"
},
"require-dev": {
"fzaninotto/faker": "^1.4",

821
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,9 @@
resources:
- name: source-code
type: git
source:
branch: master
params:
depth: 1
uri: ssh://git@git.keks.cloud:32222/keksCloud/keksAccount.git
check_every: 5m