2019-07-11 23:55:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2019-10-02 18:45:08 +02:00
|
|
|
use Illuminate\Support\Facades\Input;
|
2019-07-11 23:55:51 +02:00
|
|
|
use Illuminate\Http\Request;
|
2019-08-30 02:12:27 +02:00
|
|
|
use App\User;
|
2019-10-02 18:45:08 +02:00
|
|
|
use Mail;
|
2019-09-17 19:23:43 +02:00
|
|
|
use App\Rules\Pesel;
|
2019-07-11 23:55:51 +02:00
|
|
|
|
2019-08-30 02:12:27 +02:00
|
|
|
class RegistrationController extends Controller
|
|
|
|
{
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('register');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store()
|
|
|
|
{
|
|
|
|
$this->validate(request(), [
|
2019-09-09 03:19:59 +02:00
|
|
|
|
2020-02-01 02:46:17 +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-]+$/',
|
2019-09-17 19:23:43 +02:00
|
|
|
'PESEL' => new Pesel,
|
2019-09-19 11:22:54 +02:00
|
|
|
'phoneNumber' => 'required|digits:9',
|
2019-09-17 19:23:43 +02:00
|
|
|
'email' => 'required|email|unique:users',
|
2020-01-31 03:13:13 +01:00
|
|
|
'password' => 'required|confirmed|min:6|max:45',
|
2019-09-17 19:23:43 +02:00
|
|
|
],
|
2019-09-19 11:22:54 +02:00
|
|
|
[
|
2019-09-17 19:23:43 +02:00
|
|
|
'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',
|
2019-09-19 11:22:54 +02:00
|
|
|
'digits' => ':attribute musi składać się z :digits cyfr.',
|
2019-09-17 19:23:43 +02:00
|
|
|
'unique' =>':attribute jest już zajęty.',
|
|
|
|
'confirmed' =>':attribute się nie zgadza.',
|
|
|
|
'email' => 'Niepoprawny adres e-mail.'
|
2019-08-30 02:12:27 +02:00
|
|
|
]);
|
|
|
|
|
2019-09-09 03:19:59 +02:00
|
|
|
|
|
|
|
$request = request();
|
2019-10-02 18:45:08 +02:00
|
|
|
|
|
|
|
$confirmation_code = str_random(30);
|
|
|
|
|
2019-09-09 03:19:59 +02:00
|
|
|
$user = User::create([
|
|
|
|
'password' => $request-> password,
|
|
|
|
'email' => $request-> email,
|
|
|
|
'name' => $request-> name,
|
|
|
|
'surname' => $request-> surname,
|
|
|
|
'PESEL' => $request-> PESEL,
|
|
|
|
'phoneNumber' => $request-> phoneNumber,
|
|
|
|
'functionID' => 1,
|
|
|
|
'degreeID' => 1,
|
2019-10-02 18:45:08 +02:00
|
|
|
'number' => 'ABC123',
|
|
|
|
'confirmation_code' => $confirmation_code
|
2019-09-09 03:19:59 +02:00
|
|
|
]);
|
2019-08-30 02:12:27 +02:00
|
|
|
|
2020-03-25 00:20:45 +01:00
|
|
|
// Mail::send('emails.verify', compact('confirmation_code'), function($message) {
|
|
|
|
// $message->to(Input::get('email'), Input::get('name'))->subject('Weryfikacja adresu e-mail');
|
|
|
|
// });
|
2019-10-02 18:45:08 +02:00
|
|
|
|
|
|
|
//Flash::message('Thanks for signing up! Please check your email.');
|
|
|
|
|
2019-08-30 02:12:27 +02:00
|
|
|
|
|
|
|
auth()->login($user);
|
|
|
|
|
|
|
|
return redirect()->to('/jednostka');
|
|
|
|
}
|
2019-10-02 18:45:08 +02:00
|
|
|
|
|
|
|
public function confirm($confirmation_code)
|
|
|
|
{
|
|
|
|
if( ! $confirmation_code)
|
|
|
|
{
|
|
|
|
throw new InvalidConfirmationCodeException;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = User::whereConfirmationCode($confirmation_code)->first();
|
|
|
|
|
|
|
|
if ( ! $user)
|
|
|
|
{
|
|
|
|
throw new InvalidConfirmationCodeException;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user->confirmed = 1;
|
|
|
|
$user->confirmation_code = null;
|
|
|
|
$user->email_verified_at = now();
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
//Flash::message('You have successfully verified your account.');
|
|
|
|
|
|
|
|
return redirect()->to('/jednostka');
|
|
|
|
}
|
|
|
|
|
2019-08-30 02:12:27 +02:00
|
|
|
}
|
2019-09-17 19:23:43 +02:00
|
|
|
|