1
0
forked from s421507/eOSP2

Edycja web.php przed merge

This commit is contained in:
czup 2019-12-25 22:37:22 +01:00
commit 969b9126c8
5 changed files with 178 additions and 3 deletions

View File

@ -0,0 +1,72 @@
<?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();
return view("userProfileEdit", ["userData" => $userData]);
}
else
return redirect()->to('/login');
}
public function update(){
$this->validate(request(), [
'name' => 'required|alpha|min:3|max:45',
'surname' => 'required|alpha|min:3|max:45',
'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.',
'alpha' => ':attribute może zawierać tylko litery.',
'alpha_num' => ':attribute może zawierać tylko litery i cyfry.',
'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');;
}
}

View File

@ -18,10 +18,11 @@
@if( auth()->check() )
{{ auth()->user()->name }}
{{ auth()->user()->surname }}
<a href="/logout">Logout</a>
<a href="/logout">Wyloguj</a>
<a href="/userprofile">Mój profil</a>
@else
<a href="/login">Login</a>
<a href="/register">Register</a>
<a href="/login">Zaloguj się</a>
<a href="/register">Rejestracja</a>
@endif
<div id="header">
<div class="logo"><a href="/register"><img src="../img/logo.png"></a></div>

View File

@ -0,0 +1,51 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul>
@stop
@section('center-area')
@parent
@if( auth()->check())
<p align='center'>
<table class='firefighterViewTable'>
<tr>
<td>Imię i nazwisko:</td>
<td>{{ $userData->name }} {{ $userData->surname }}</td>
</tr>
<tr>
<td>PESEL:</td>
<td>{{ $userData->PESEL}}</td>
</tr>
<tr>
<td>Nr telefonu:</td>
<td>{{ $userData->phoneNumber}}</td>
</tr>
<tr>
<td>Adres e-mail:</td>
<td>{{ $userData->email}}</td>
</tr>
<tr>
<td>Numer ewidencyjny:</td>
<td>{{ $userData->number}}</td>
</tr>
<tr>
<td>Stopień:</td>
<td>{{ $userData->rank}}</td>
</tr>
<tr>
<td>Funkcja:</td>
<td>{{ $userData->unitFunction}}</td>
</tr>
</table>
</p>
@else
Brak autoryzacji
@endif
@stop

View File

@ -0,0 +1,45 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul>
@stop
@section('center-area')
@parent
<form method="POST" action="/userprofile/edit">
{{ csrf_field() }}
<input type="hidden" class="form-control" name="userID" value="{{ $userData->id }}">
<div class="form-group">
<label for="name">Imię:</label>
<input type="text" class="form-control" id="name" name="name" value="{{ $userData->name }} ">
</div>
<div class="form-group">
<label for="amount">Nazwisko:</label>
<input type="text" class="form-control" id="surname" name="surname" value="{{ $userData->surname }}">
</div>
<div class="form-group">
<label for="parameter">PESEL:</label>
<input type="text" class="form-control" id="PESEL" name="PESEL" value="{{ $userData->PESEL }}">
</div>
<div class="form-group">
<label for="parameter">Numer telefonu:</label>
<input type="text" class="form-control" id="phoneNumber" name="phoneNumber" value="{{ $userData->phoneNumber }}">
</div>
<div class="form-group">
<label for="parameter">Adres e-mail:</label>
<input type="email" class="form-control" id="email" name="email" value="{{ $userData->email }}">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zatwierdź</button>
</div>
@include('inc.formerrors')
</form>
@stop

View File

@ -74,11 +74,17 @@ Route::get('/sprzet/edit/{id}', 'EquipmentController@editForm');
Route::post('/sprzet/edit', 'EquipmentController@update');
Route::resource('equipment', 'EquipmentController');
Route::get('/szkolenia', 'trainingsController@create');
Route::post('/szkolenia', 'trainingsController@store');
Route::get('/szkolenia/addTrainingsFireFighters/{id}', 'trainingsController@addTrainingsFireFighters');
Route::post('/szkolenia/addTrainingsFireFighters/', 'trainingsController@ajaxRequest');
Route::get('/userprofile', 'userProfileController@create');
Route::get('/userprofile/edit', 'userProfileController@editForm');
Route::post('/userprofile/edit', 'userProfileController@update');
Route::get('register/verify/{confirmationCode}', [
'as' => 'confirmation_path',
'uses' => 'RegistrationController@confirm'