2021-06-17 14:08:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-06-18 15:09:34 +00:00
|
|
|
use Illuminate\Auth\Events\Registered;
|
2021-06-17 14:08:30 +00:00
|
|
|
use Illuminate\Http\Request;
|
2021-11-26 06:19:55 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-04-25 05:44:06 +00:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
2022-03-14 11:28:54 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2021-06-17 14:08:30 +00:00
|
|
|
|
2023-08-02 12:42:59 +00:00
|
|
|
use App\Http\Requests\UserRequest;
|
2022-03-14 11:28:54 +00:00
|
|
|
use App\Models\{Address,User};
|
2021-06-17 14:08:30 +00:00
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Add or edit a node
|
|
|
|
*/
|
2023-08-02 12:42:59 +00:00
|
|
|
public function add_edit(UserRequest $request,User $o)
|
2021-06-17 14:08:30 +00:00
|
|
|
{
|
|
|
|
if ($request->post()) {
|
2023-08-02 12:42:59 +00:00
|
|
|
foreach (['name','email','pgp_pubkey','active','admin','alias','system_id'] as $key)
|
2021-06-17 14:08:30 +00:00
|
|
|
$o->{$key} = $request->post($key);
|
|
|
|
|
2021-06-18 15:09:34 +00:00
|
|
|
if (! $o->exists)
|
|
|
|
$o->password = base64_encode(random_bytes(20));
|
2024-04-25 05:44:06 +00:00
|
|
|
elseif ($request->password)
|
|
|
|
$o->password = Hash::make($request->password);
|
2021-06-18 15:09:34 +00:00
|
|
|
|
2021-06-17 14:08:30 +00:00
|
|
|
$o->save();
|
|
|
|
|
2021-06-18 15:09:34 +00:00
|
|
|
if ($o->wasRecentlyCreated)
|
|
|
|
event(new Registered($o));
|
|
|
|
|
2024-04-25 05:44:06 +00:00
|
|
|
return redirect()
|
|
|
|
->to('user/addedit/'.$o->id)
|
|
|
|
->with('success','User Updated');
|
2021-06-17 14:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return view('user.addedit')
|
|
|
|
->with('o',$o);
|
|
|
|
}
|
|
|
|
|
2022-03-14 11:28:54 +00:00
|
|
|
public function link(Request $request)
|
|
|
|
{
|
|
|
|
if ($request->post()) {
|
|
|
|
$request->validate([
|
|
|
|
'address_id'=>'required|exists:addresses,id',
|
|
|
|
'code'=>'required:string',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$ao = Address::findOrFail($request->address_id);
|
2024-05-09 11:31:50 +00:00
|
|
|
if ($ao->activation_check(Auth::user(),$request->code)) {
|
2022-03-14 11:28:54 +00:00
|
|
|
$ao->validated = TRUE;
|
|
|
|
$ao->save();
|
|
|
|
|
|
|
|
$ao->system->users()->save(Auth::user());
|
|
|
|
|
|
|
|
return redirect()->to('/');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$validator = Validator::make([],[]);
|
|
|
|
$validator->errors()->add(
|
|
|
|
'code', 'Invalid Code!'
|
|
|
|
);
|
|
|
|
|
|
|
|
return back()->withErrors($validator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('user.link');
|
|
|
|
}
|
2023-10-05 11:42:41 +00:00
|
|
|
}
|