eOSP2/app/Http/Controllers/userProfileController.php

99 lines
4.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\User;
use App\Rules\Pesel;
class userProfileController extends Controller
{
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$userData = DB::table('users')->where("users.id", '=', auth()->user()->id)
->leftJoin('ranks', 'users.degreeID', '=', 'ranks.id')
->leftJoin('unitFunctions', 'users.functionID', '=', 'unitFunctions.id')
->select('users.id','users.name', 'users.surname', 'users.PESEL','users.phoneNumber', 'users.email', 'ranks.rank', 'unitFunctions.unitFunction', 'users.number')
->first();
return view("userProfile", ["userData" => $userData]);
} else{
return redirect()->to('/login');
}
}
public function editForm()
{
if(auth()->user() != null && auth()->user()->fireStationID != null )
{
$userData = DB::table('users')->where("id", '=', auth()->user()->id)
->first();
2020-02-01 01:03:57 +01:00
return view("userProfileEdit", ["userData" => $userData]);
2020-02-01 01:03:57 +01:00
}
else
return redirect()->to('/login');
2020-02-01 01:03:57 +01:00
}
public function update(){
$this->validate(request(), [
2020-02-01 03:53:59 +01:00
'name' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/',
'surname' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/',
'PESEL' => new Pesel,
'phoneNumber' => 'required|digits:9',
'email' => 'required|email|unique:users,email,'.auth()->user()->id, //wymagaj unikalnego adresu email ale pozwól na zachowanie starego adresu
],
[
'required' => ':attribute jest wymagany(e).',
'min' => ':attribute musi mieć przynajmniej :min znaki.',
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
2020-01-31 03:13:13 +01:00
'regex' => ':attribute może zawierać tylko litery, spacje, myślniki i apostrofy',
'digits' => ':attribute musi składać się z :digits cyfr.',
'unique' =>':attribute jest już zajęty.',
'confirmed' =>':attribute się nie zgadza.',
'email' => 'Niepoprawny adres e-mail.'
]);
$request = request();
$user = User::find( $request->userID);
$user-> name = $request->name;
$user-> surname = $request->surname;
$user-> PESEL = $request->PESEL;
$user-> phoneNumber = $request->phoneNumber;
$user-> email = $request->email;
$user-> changingID = auth()->user()-> id;
$user->save();
return redirect()->to('/userprofile');;
}
public function userTrainings(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
2020-01-02 14:20:35 +01:00
$userTrainings = DB::table('trainingsFirefighters')->where("trainingsFirefighters.firefighterID", '=', auth()->user()->id)
->leftJoin('trainings', 'trainingsFirefighters.trainingID', '=', 'trainings.id')
2020-02-01 01:03:57 +01:00
->whereNull('deleted_at')
2020-01-02 14:20:35 +01:00
->select('trainingsFirefighters.id','trainings.trainingName','trainingsFirefighters.dateOfComplete', 'trainingsFirefighters.dateOfExpiry')
->get();
return view("userTrainings", ["userTrainings" => $userTrainings]);
}
else{
return redirect()->to('/login');;
}
}
2020-01-02 14:20:35 +01:00
public function userDecorations(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$userDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', auth()->user()->id)
->whereNull('decorationsFirefighters.deleted_at')
->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id')
->get();
return view("userDecorations", ["userDecorations" => $userDecorations]);
} else{
return "Brak dostepu";
}
}
}