split controller to Profile* and Account*, sort tables by last change
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\EmailConfirmation;
|
||||||
|
use Hash;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use MightyPork\Utils\Str;
|
||||||
|
|
||||||
|
class AccountController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function editAccount()
|
||||||
|
{
|
||||||
|
return view('profile.edit-account', ['user' => user()]);
|
||||||
|
}
|
||||||
|
public function storeAccount(Request $request)
|
||||||
|
{
|
||||||
|
$input = $this->validate($request, [
|
||||||
|
'name' => [
|
||||||
|
'required',
|
||||||
|
VALI_NAME,
|
||||||
|
Rule::unique('users')->ignoreModel(\user()),
|
||||||
|
],
|
||||||
|
'email' => [
|
||||||
|
'required',
|
||||||
|
VALI_EMAIL,
|
||||||
|
Rule::unique('users')->ignoreModel(\user()),
|
||||||
|
],
|
||||||
|
'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 forgetSocialLogin($id)
|
||||||
|
{
|
||||||
|
$identity = user()->socialIdentities()->where('id', $id)->first();
|
||||||
|
if (null === $identity) {
|
||||||
|
abort(404, "No such identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
$identity->delete();
|
||||||
|
return redirect(route('profile.manage-oauth'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\EmailConfirmation;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Hash;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use MightyPork\Utils\Str;
|
|
||||||
|
|
||||||
class ProfileController extends Controller
|
class ProfileController extends Controller
|
||||||
{
|
{
|
||||||
@@ -21,6 +17,7 @@ class ProfileController extends Controller
|
|||||||
{
|
{
|
||||||
$tables = $user->tables()
|
$tables = $user->tables()
|
||||||
->with('revision:id,row_count')
|
->with('revision:id,row_count')
|
||||||
|
->orderByDesc('updated_at')
|
||||||
->paginate(10);
|
->paginate(10);
|
||||||
|
|
||||||
return view('profile.view')->with(compact('tables', 'user'));
|
return view('profile.view')->with(compact('tables', 'user'));
|
||||||
@@ -37,11 +34,6 @@ class ProfileController extends Controller
|
|||||||
return view('profile.edit-profile')->with('user', \user());
|
return view('profile.edit-profile')->with('user', \user());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editAccount()
|
|
||||||
{
|
|
||||||
return view('profile.edit-account', ['user' => user()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store changed profile
|
* Store changed profile
|
||||||
*/
|
*/
|
||||||
@@ -60,62 +52,4 @@ class ProfileController extends Controller
|
|||||||
flash()->success('Settings saved');
|
flash()->success('Settings saved');
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeAccount(Request $request)
|
|
||||||
{
|
|
||||||
$input = $this->validate($request, [
|
|
||||||
'name' => [
|
|
||||||
'required',
|
|
||||||
VALI_NAME,
|
|
||||||
Rule::unique('users')->ignoreModel(\user()),
|
|
||||||
],
|
|
||||||
'email' => [
|
|
||||||
'required',
|
|
||||||
VALI_EMAIL,
|
|
||||||
Rule::unique('users')->ignoreModel(\user()),
|
|
||||||
],
|
|
||||||
'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 forgetSocialLogin($id)
|
|
||||||
{
|
|
||||||
$identity = user()->socialIdentities()->where('id', $id)->first();
|
|
||||||
if (null === $identity) {
|
|
||||||
abort(404, "No such identity");
|
|
||||||
}
|
|
||||||
|
|
||||||
$identity->delete();
|
|
||||||
return redirect(route('profile.manage-oauth'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,6 +22,7 @@ function _loginVia($method) {
|
|||||||
->where('provider_user_id', $details->id)
|
->where('provider_user_id', $details->id)
|
||||||
->exists()) {
|
->exists()) {
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
abort(403,
|
abort(403,
|
||||||
"Account with this e-mail already exists. Add the identity
|
"Account with this e-mail already exists. Add the identity
|
||||||
to the account manually after logging in through an existing
|
to the account manually after logging in through an existing
|
||||||
@@ -85,7 +86,6 @@ Route::get('/auth/facebook/callback', function() {
|
|||||||
return _loginVia('facebook');
|
return _loginVia('facebook');
|
||||||
})->name('oauth-facebook-callback');
|
})->name('oauth-facebook-callback');
|
||||||
|
|
||||||
Route::get('/auth/forget/{id}', 'ProfileController@forgetSocialLogin')->name('forget-identity');
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Route::get('/auth/stack/authorize', function() {
|
Route::get('/auth/stack/authorize', function() {
|
||||||
|
|||||||
+8
-5
@@ -31,12 +31,15 @@ Route::group(['middleware' => 'auth'], function () {
|
|||||||
'prefix' => 'profile',
|
'prefix' => 'profile',
|
||||||
], function () {
|
], function () {
|
||||||
Route::get('edit', 'ProfileController@editProfile')->name('profile.edit');
|
Route::get('edit', 'ProfileController@editProfile')->name('profile.edit');
|
||||||
Route::post('edit', 'ProfileController@storeProfile')->name('profile.store');
|
Route::post('store', 'ProfileController@storeProfile')->name('profile.store');
|
||||||
|
});
|
||||||
|
|
||||||
Route::post('create', 'TableController@storeNew')->name('table.storeNew');
|
Route::group([
|
||||||
|
'prefix' => 'account',
|
||||||
Route::get('logins', 'ProfileController@editAccount')->name('account.edit');
|
], function () {
|
||||||
Route::post('logins', 'ProfileController@storeAccount')->name('account.store');
|
Route::get('edit', 'AccountController@editAccount')->name('account.edit');
|
||||||
|
Route::post('store', 'AccountController@storeAccount')->name('account.store');
|
||||||
|
Route::get('forget-social-login/{id}', 'AccountController@forgetSocialLogin')->name('forget-identity');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user