Added option to create new user from the Admin Panel

This commit is contained in:
Julian Prieber 2022-07-11 16:05:28 +02:00
parent ffcab1c8ec
commit 9a38e061c9
3 changed files with 33 additions and 0 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Auth\Events\Registered;
use Auth;
use Exception;
@ -100,6 +101,36 @@ class AdminController extends Controller
return redirect('panel/users/all');
}
//Create new user from the Admin Panel
public function createNewUser()
{
function random_str(
int $length = 64,
string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
): string {
if ($length < 1) {
throw new \RangeException("Length must be a positive integer");
}
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces []= $keyspace[random_int(0, $max)];
}
return implode('', $pieces);
}
$user = User::create([
'name' => 'Admin-Created-' . random_str(8),
'email' => random_str(8) . '@test.com',
'password' => Hash::make(random_str(32)),
'role' => 'user',
'block' => 'no',
]);
return redirect('panel/edit-user/'. $user->id);
}
//Show user to edit
public function showUser(request $request)
{

View File

@ -43,5 +43,6 @@
@endforeach
</tbody>
</table>
<a href="{{ url('') }}/panel/new-user">+ Add new user</a>
@endsection

View File

@ -101,6 +101,7 @@ Route::get('/panel/users/block/{block}/{id}', [AdminController::class, 'blockUse
Route::get('/panel/users/verify/-{verify}/{id}', [AdminController::class, 'verifyUser'])->name('verifyUser');
Route::get('/panel/edit-user/{id}', [AdminController::class, 'showUser'])->name('showUser');
Route::post('/panel/edit-user/{id}', [AdminController::class, 'editUser'])->name('editUser');
Route::get('/panel/new-user', [AdminController::class, 'createNewUser'])->name('createNewUser');
Route::get('/panel/pages', [AdminController::class, 'showSitePage'])->name('showSitePage');
Route::post('/panel/pages', [AdminController::class, 'editSitePage'])->name('editSitePage');
Route::get('/panel/advanced-config', [AdminController::class, 'showFileEditor'])->name('showFileEditor');