parent
727e2dd1b8
commit
64db4abc50
|
@ -10,6 +10,8 @@ use Illuminate\Foundation\Auth\RegistersUsers;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
use Mail;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|
@ -74,11 +76,41 @@ class RegisterController extends Controller
|
|||
|
||||
public function register(Request $request)
|
||||
{
|
||||
echo $request->input("email");
|
||||
$data = ['name' => $request->name, 'email' => $request->email, 'password' => Hash::make($request->password)];
|
||||
DB::table('users')->insert($data);
|
||||
return View('landing_page');
|
||||
|
||||
|
||||
$input = $request->all();
|
||||
$validator = $this->validator($input);
|
||||
|
||||
if($validator->passes()){
|
||||
$user = $this->create($input)->toArray();
|
||||
$user['link'] = str_random(30);
|
||||
|
||||
DB::table('user_activations')->insert(['id_user'=>$user['id'], 'token'=>$user['link']]);
|
||||
|
||||
Mail::send('emails.activation', $user, function($message) use ($user){
|
||||
$message->to($user['email']);
|
||||
$message->subject('GeoComb - Activation Code');
|
||||
});
|
||||
return redirect()->to('login')->with('success',"Foi enviado um email de confimação para a sua conta");
|
||||
}
|
||||
|
||||
return back()->with('errors', $validator->errors());
|
||||
|
||||
}
|
||||
|
||||
public function userActivation($token)
|
||||
{
|
||||
$check = DB::table('user_activations')->where('token', $token)->first();
|
||||
if(!is_null($check)){
|
||||
$user = USER::find($check->id_user);
|
||||
if($user->is_activated == 1){
|
||||
return redirect()->to('login')->with('success', "Já logado.");
|
||||
}
|
||||
$user->update(['is_activated' => 1]);
|
||||
DB::table('user_activations')->where('token',$token)->delete();
|
||||
return redirect()->to('login')->with('success', "Utilizador Activado");
|
||||
}
|
||||
return redirect()->to('login')->with('warning', "Token Inválido");
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUsersActivationTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_activations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('id_user')->unsigned();
|
||||
$table->foreign('id_user')->references('id')->on('users')->onDelete('cascade');
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table){
|
||||
$table->boolean('is_activated')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop("user_activations");
|
||||
|
||||
Schema::table('users', function (Blueprint $table){
|
||||
$table->dropColumn('is_activated');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -12,8 +12,7 @@ class UserTableSeeder extends Seeder
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$data = array(["id" => 1, "name" => "Goncalo", "email" => "goncalo@gmail.com", "password" => Hash::make(123123123)],
|
||||
["id" => 2, "name" => "Paulo", "email" => "paulo@gmail.com", "password" => Hash::make(123123123)]);
|
||||
$data = array(["id" => 1, "name" => "Gestor", "email" => "gestor@gmail.com", "password" => Hash::make(123123123), "is_activated" => 1]);
|
||||
DB::table('users')->insert($data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,21 @@
|
|||
<form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}">
|
||||
{{ csrf_field() }}
|
||||
|
||||
@if ($message = Session::get('success'))
|
||||
<div class="alert alert-success">
|
||||
<p>
|
||||
{{ $message }}
|
||||
</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($message = Session::get('warning'))
|
||||
<div class="alert alert-warning">
|
||||
<p>
|
||||
{{ $message }}
|
||||
</p>
|
||||
</div>
|
||||
@endif
|
||||
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
|
||||
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Bem-Vindo, {{ $name }}
|
||||
Para ativar a sua conta por favor carregue no seguinte link : {{ url('user/activation', $link)}}
|
|
@ -27,6 +27,8 @@ Route::post('/',
|
|||
|
||||
Auth::routes();
|
||||
|
||||
Route::get('/user/activation/{token}', 'Auth\RegisterController@userActivation');
|
||||
|
||||
Route::get('/', 'LandingController@index')->name('home');
|
||||
|
||||
Route::get('/fetchStation', 'LandingController@fetchStationData');#para apagar
|
||||
|
|
Loading…
Reference in New Issue