This commit is contained in:
Kekskurse 2019-08-11 22:08:56 +02:00
parent d8a212b230
commit 4f3edcceb0
4 changed files with 49 additions and 25 deletions

View file

@ -83,15 +83,17 @@ class AppController extends BaseController
} }
public function findApp(Response $response, \Illuminate\Http\Request $request) { public function findApp(Response $response, \Illuminate\Http\Request $request) {
if(!Auth::check()) {
throw new NotLoggedInException();
}
$this->validate($request, [ $this->validate($request, [
'apiKey' => '', 'apiKey' => '',
'startpage' => '' 'webpage' => ''
]); ]);
if(!$request->input("webpage", false) || !empty($request->input("apiKey"))) {
if(!Auth::check()) {
throw new NotLoggedInException();
}
}
$query = \App\Models\App::query(); $query = \App\Models\App::query();
if($request->input("apiKey", false)) { if($request->input("apiKey", false)) {

View file

@ -182,4 +182,14 @@ class UserController extends BaseController
return $response->withData($data); return $response->withData($data);
} }
public function listMails(Response $response) {
if(!Auth::check()) {
throw new NotLoggedInException();
}
$mails = Mail::query()->where("user_id", "=", Auth::id())->get();
return $response->withData(\App\Http\Resources\API\Mail::collection(collect($mails)));
}
} }

View file

@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources\API;
use Illuminate\Http\Resources\Json\JsonResource;
class Mail extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => (int)$this->id,
'created_at' => $this->created_at,
'updated_at' => $this->created_at,
'status' => $this->status,
'primary' => $this->primary,
'mail' => $this->mail
];
}
}

View file

@ -45,6 +45,7 @@ $router->group(['prefix' => 'api'], function () use ($router) {
$router->get("/captcha", ['uses' => 'API\UserController@reCAPTCHA']); $router->get("/captcha", ['uses' => 'API\UserController@reCAPTCHA']);
$router->get("/invites", ['uses' => 'API\UserController@getInviteCodeInfo']); $router->get("/invites", ['uses' => 'API\UserController@getInviteCodeInfo']);
$router->get("/me", ['uses' => 'API\UserController@me']); $router->get("/me", ['uses' => 'API\UserController@me']);
$router->get("/me/mails", ['uses' => 'API\UserController@listMails']);
}); });
$router->group(['prefix' => 'app'], function () use ($router) { $router->group(['prefix' => 'app'], function () use ($router) {
$router->get("/", ['uses' => 'API\AppController@listApps']); $router->get("/", ['uses' => 'API\AppController@listApps']);
@ -66,15 +67,13 @@ $router->group(['prefix' => 'api'], function () use ($router) {
$router->get("/authorize", ['middleware' => 'gui', 'uses' => 'oAuthController@authorizeView']); $router->get("/authorize", ['middleware' => 'gui', 'uses' => 'oAuthController@authorizeView']);
$router->post("/token", ['uses' => 'oAuthController@token']); $router->post("/token", ['uses' => 'oAuthController@token']);
}); });
$router->group(['prefix' => 'server'], function () use ($router) {
$router->get("/settings", ["uses" => "API\ServerController@getSettings"]);
});
}); });
}); });
//Public Routes
/*$router->post("api/v1/user/login", ['uses' => 'API\UserController@passwordLogin']);
$router->post("api/v1/user/register", ['uses' => 'API\UserController@register']);
$router->get("api/v1/user/captcha", ['uses' => 'API\UserController@reCAPTCHA']);
$router->get("api/v1/user/invites", ['uses' => 'API\UserController@getInviteCodeInfo']);*/
$router->get("api/v1/server/settings", ["uses" => "API\ServerController@getSettings"]);
$router->get("status/check", ["uses" => "StatusController@check"]); $router->get("status/check", ["uses" => "StatusController@check"]);
$router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($router) { $router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($router) {
@ -116,9 +115,6 @@ $router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($rou
$router->get("/admin/resendInviteMail", ["uses" => 'GUI\AdminController@resendValidationMail']); $router->get("/admin/resendInviteMail", ["uses" => 'GUI\AdminController@resendValidationMail']);
$router->get('/profile', ['uses' => 'GUI\AccountController@profileView']); $router->get('/profile', ['uses' => 'GUI\AccountController@profileView']);
$router->post('/profile/addMail', ['uses' => 'GUI\AccountController@addMail']); $router->post('/profile/addMail', ['uses' => 'GUI\AccountController@addMail']);
$router->get('/profile/changePrimaryMail', ['uses' => 'GUI\AccountController@changePrimaryMail']); $router->get('/profile/changePrimaryMail', ['uses' => 'GUI\AccountController@changePrimaryMail']);
@ -127,14 +123,4 @@ $router->group(['prefix' => 'gui', 'middleware' => 'gui'], function () use ($rou
$router->get('/access', ['uses' => 'GUI\AccessController@listAccess']); $router->get('/access', ['uses' => 'GUI\AccessController@listAccess']);
$router->get('/access/rm', ['uses' => 'GUI\AccessController@removeAccess']); $router->get('/access/rm', ['uses' => 'GUI\AccessController@removeAccess']);
}); });
/*$router->group(['prefix' => 'api'], function () use ($router) {
$router->group(['prefix' => 'auth'], function () use ($router) {
$router->post('/register', ['uses' => 'GUI\AccountController@register']);
});
});*/