Skip to content

Commit

Permalink
Merge pull request #20 from adamzv/release/2.0.0
Browse files Browse the repository at this point in the history
Release/2.0.0
  • Loading branch information
adamzv authored Nov 9, 2020
2 parents 2c0f9e5 + f828445 commit e341401
Show file tree
Hide file tree
Showing 51 changed files with 3,874 additions and 978 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ yarn-error.log*
*.njsproj
*.sln
*.sw?

# Traefik related files
/letsencrypt
43 changes: 43 additions & 0 deletions backend/.env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=sqlite
DB_DATABASE="test.sqlite"


BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
2 changes: 0 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
RUN chown -R www-data:www-data /var/www/html \
&& a2enmod rewrite

EXPOSE 3000

RUN cd /var/www/html && composer install && php artisan key:generate
37 changes: 34 additions & 3 deletions backend/app/Http/Controllers/Api/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,26 @@ public function index()

/**
* Store a newly created resource in storage.
* StoreFacultyRequest $request
* * @return Event
*/
public function store(Request $request)
{
//
if ($request->input('id_repeat') === null) {
return Event::create($request->only([
'name',
'desc',
'room',
'beginning',
'end',
'attendance_limit',
'id_user',
'id_place',
'id_faculty',
'id_department',
]));
}

}

/**
Expand All @@ -45,14 +61,29 @@ public function show($id)
*/
public function update(Request $request, $id)
{
//

$event = Event::findOrFail($id);
$event->update($request->only([
'name',
'desc',
'room',
'beginning',
'end',
'attendance_limit',
'id_user',
'id_place',
'id_faculty',
'id_department'

]));
return $event;
}

/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//

}
}
2 changes: 1 addition & 1 deletion backend/app/Http/Controllers/Api/PicturesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function show($id)
public function update(StorePictureRequest $request, $id)
{
$picture = Picture::findOrFail($id);
$picture->update($request->only(['línk', 'id_event']));
$picture->update($request->only(['link', 'id_event']));
return $picture;
}

Expand Down
93 changes: 92 additions & 1 deletion backend/app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreUserRequest;
use App\Http\Requests\UserLoginRequest;
use App\Http\Requests\UserRegisterRequest;
use App\Models\Role;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;

/**
* Class UsersController
Expand All @@ -31,8 +36,12 @@ public function index()
*/
public function store(StoreUserRequest $request)
{
return User::create($request->only([
$user = User::create($request->only([
'name', 'surname', 'email', 'password', 'id_role']));

// for testing purposes
$user->makeVisible(['password']);
return $user;
}

/**
Expand All @@ -58,6 +67,9 @@ public function update(StoreUserRequest $request, $id)
$user = User::findOrFail($id);
$user->update($request->only([
'name', 'surname', 'email', 'password', 'id_role']));

// for testing purposes
$user->makeVisible(['password']);
return $user;
}

Expand All @@ -71,4 +83,83 @@ public function destroy($id)
{
// TODO: discuss with team
}

/**
* Login user
*
* @param UserLoginRequest $request
* @return JsonResponse
*/
public function login(UserLoginRequest $request)
{
// Attempt to login
if (!Auth::attempt([
'email' => $request->input('email'),
'password' => $request->input('password'),
])) {
return response()->json([
'success' => false,
'message' => 'You have entered the wrong login information!']);
}

// create token to user and return it
$accessToken = Auth::user()->createToken('authToken')->accessToken;
return response()->json([
'success' => true,
'message' => 'Login was successful',
'user' => Auth::user(),
'access_token' => $accessToken]);
}

/**
* Register new user
*
* @param UserRegisterRequest $request
* @return JsonResponse
*/
public function register(UserRegisterRequest $request)
{
// get data from request
$input = [
'name' => $request->input('name'),
'surname' => $request->input('surname'),
'email' => $request->input('email'),
'id_role' => Role::where('type', 'pouzivatel')->value('id'),
'password' => bcrypt($request->input('password')),
];

// create new user
$user = User::create($input);

// create token to the user and return it with user
$accessToken = $user->createToken('authToken')->accessToken;
return response()->json([
'success' => true,
'message' => 'User registered successfully',
'user' => $user,
'access_token' => $accessToken]);
}

/**
* Logout user
*
* @return JsonResponse
*/
public function logout()
{
if (Auth::user()) {
$user = Auth::user()->token();
$user->revoke();

return response()->json([
'success' => true,
'message' => 'Logout successfully'
]);
} else {
return response()->json([
'success' => false,
'message' => 'Unable to Logout'
]);
}
}
}
1 change: 1 addition & 0 deletions backend/app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
Expand Down
37 changes: 37 additions & 0 deletions backend/app/Http/Requests/UserLoginRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

/**
* Class UserLoginRequest
*
* @author lacal
*/
class UserLoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Auth::guest();
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|string|email|max:255',
'password' => 'required|string|min:6|max:255',
];
}
}
51 changes: 51 additions & 0 deletions backend/app/Http/Requests/UserRegisterRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

/**
* Class UserRegisterRequest
*
* @author lacal
*/
class UserRegisterRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Auth::guest();
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string|max:255',
'surname' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|max:255'
];
}

/**
* Get the custom validation messages
*
* @return array|string[]
*/
public function messages()
{
return [
'email.unique' => 'An email is already used',
];
}
}
28 changes: 24 additions & 4 deletions backend/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;

/**
* Class CreateRepeatsTable
*
* @author klukak
* @author klukak, lacal
*/
class User extends Model
class User extends Authenticatable
{
use SoftDeletes;
use SoftDeletes, Notifiable, HasApiTokens;

/**
* The attributes that aren´t max assignable
Expand All @@ -21,6 +23,24 @@ class User extends Model
*/
protected $guarded = ['id'];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];

/**
* Get the role
*/
Expand Down
Loading

0 comments on commit e341401

Please sign in to comment.