datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.2 KiB
97 lines
2.2 KiB
<?php
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\EmailConfirmation;
|
|
use App\Models\User;
|
|
use Hash;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
use MightyPork\Utils\Str;
|
|
|
|
class UserController extends Controller
|
|
{
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function view(User $user)
|
|
{
|
|
$tables = $user->tables()
|
|
->with('revision:id,row_count')
|
|
->paginate(10);
|
|
|
|
return view('user.view')->with(compact('tables', 'user'));
|
|
}
|
|
|
|
/**
|
|
* Edit own profile
|
|
*
|
|
* @param User $user
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function edit()
|
|
{
|
|
return view('user.edit')->with('user', \user());
|
|
}
|
|
|
|
/**
|
|
* Store changed profile
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$input = $this->validate($request, [
|
|
'name' => [
|
|
'required',
|
|
VALI_NAME,
|
|
Rule::unique('users')->ignoreModel(\user()),
|
|
],
|
|
'email' => [
|
|
'required',
|
|
VALI_EMAIL,
|
|
Rule::unique('users')->ignoreModel(\user()),
|
|
],
|
|
'bio' => ['nullable', VALI_TEXT],
|
|
'title' => ['required', VALI_LINE],
|
|
'website' => ['required', VALI_LINE],
|
|
'new_password' => ['nullable', 'confirmed', VALI_PASSWORD],
|
|
]);
|
|
|
|
$user = user();
|
|
|
|
if ($input->email != $user->email) {
|
|
$confirmation = EmailConfirmation::create([
|
|
'user_id' => $user->id,
|
|
'email' => $input->email,
|
|
'token' => Str::random(60),
|
|
]);
|
|
|
|
flash()->warning("New e-mail confirmation sent to $input->email.")->important();
|
|
|
|
// TODO send the e-mail
|
|
|
|
unset($input->email);
|
|
}
|
|
|
|
$user->fill($input->all());
|
|
|
|
if ($input->has('new_password')) {
|
|
$user->password = Hash::make($input->new_password);
|
|
|
|
flash()->warning('Password changed');
|
|
}
|
|
|
|
$user->save();
|
|
|
|
flash()->success('Settings saved');
|
|
|
|
return back();
|
|
}
|
|
|
|
public function manageOauth()
|
|
{
|
|
return view('user.logins', ['user' => user()]);
|
|
}
|
|
}
|
|
|