This commit is contained in:
Kekskurse 2019-04-28 17:04:22 +02:00
parent 8d8cc32b9c
commit ffa102e597
4 changed files with 100 additions and 6 deletions

View file

@ -12,8 +12,9 @@ Keks Account currently hava a cheap Hacked WebGui
# Supportet Software
* Mattermost CE (Gitlab Integration)
* Gitea (Gitlab Integration)
* Nextcloud (not worrking correct) (Gitlab Integration)
* Jenkins (Gitlab Integration)
Application | Status | Comment
----------- | -------- | --------
Mattermost CE | Working | Based on the GitLab Integration
Gitea | Working | Based on the GitLab Integration
Nextcloud | Working | Based on the GitLab Integration with https://github.com/zorn-v/nextcloud-social-login
Jenkins | Working | To authorized user, no right managment ATM

View file

@ -8,12 +8,16 @@ use App\Exceptions\NoPermissionException;
use App\Exceptions\NotLoggedInException;
use App\Exceptions\ResourceNotFound;
use App\Http\Resources\oAuth\AccessToken;
use App\Jobs\Mails\ValidateMailAddressJob;
use App\Models\App;
use App\Models\AppAccess;
use App\Models\Invite;
use App\Models\Mail;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Laravel\Lumen\Routing\Controller as BaseController;
use ReCaptcha\ReCaptcha;
use TaGeSo\APIResponse\Response;
@ -65,7 +69,60 @@ class UserController extends BaseController
}
public function register(Request $request, Response $response) {
//If Recptache is enabled check it at the beginning
if(Setting::getSettingValue("recaptcha_v2_register")) {
$reCaptcha = new ReCaptcha(Setting::getSettingValue("recaptcha_v2_secret"));
$response = $reCaptcha->verify($request->input("g-recaptcha-response"));
if(!$response->isSuccess()) {
throw new HTTPException(400, "Captcha validation failed");
}
}
$this->validate($request, [
'username' => 'required|max:255|min:5|regex:@^[a-z0-9]*$@|unique:users',
'password' => 'required|min:8',
'mail' => 'required|email|unique:mails'
]);
DB::beginTransaction();
$user = new User();
$user->username = $request->input("username");
$user->password = password_hash($request->input("password"), PASSWORD_BCRYPT);
if($invite != null) {
$user->inviteCode = $invite->code;
}
//Make first user an admin
$count = User::query()->count("*");
if($count == 1) {
$user->admin = 1;
$user->developer = 1;
}
$user->saveOrFail();
$mail = new Mail();
$mail->createValidationToken();
$mail->mail = $request->input("mail");
$mail->primary = false;
$mail->status = "waiting";
$mail->user_id = $user->id;
$mail->saveOrFail();
$this->dispatch(new ValidateMailAddressJob($mail));
if($invite != null) {
$invite->status = "used";
$invite->saveOrFail();
}
DB::commit();
return $response->withData(new \App\Http\Resources\API\User($user));
}
/*
@ -78,4 +135,23 @@ class UserController extends BaseController
$data["register"] = (bool)Setting::getSettingValue("recaptcha_v2_register");
return $response->withData($data);
}
public function getInviteCodeInfo(Request $request, Response $response) {
$data = [];
$invite = Invite::query()->where("code", "=", $request->input("code"))->first();
if($invite == null) {
throw new ResourceNotFound();
}
$usable = false;
if($invite->status == "active") {
$usable = true;
}
$data["usable"] = $usable;
#$data["status"] = $invite->status;
$data["username"] = $invite->username;
return $response->withData($data);
}
}

View file

@ -32,6 +32,22 @@
</div>
</div>
<script language="JavaScript">
function getCaptchaConfig() {
$.ajax({
type: "GET",
url: "/api/v1/user/captcha",
success: function (res) {
captchaConfig = res.data;
if(captchaConfig["login"]) {
grecaptcha.render('captcha', {
'sitekey' : captchaConfig["key"]
});
}
$("#loginButton").removeAttr('disabled');
}
});
}
$(document).ready(function () {
console.log("READY");
$("#register").submit(function (e) {

View file

@ -50,6 +50,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'auth'], function () use ($ro
});
$router->post("api/v1/user/login", ['uses' => 'API\UserController@passwordLogin']);
$router->get("api/v1/user/captcha", ['uses' => 'API\UserController@reCAPTCHA']);
$router->get("api/v1/user/invites", ['uses' => 'API\UserController@getInviteCodeInfo']);
$router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($router) {
$router->get('/register', ['uses' => 'GUI\AccountController@registerView']);