added member profile editing

added a basic ui so logged in members can change their info/password
when needed
This commit is contained in:
ro 2024-09-20 15:09:45 -06:00
parent 2932af0d3f
commit 99e22f5697
12 changed files with 153 additions and 5 deletions

1
.gitignore vendored
View file

@ -5,6 +5,7 @@
/public/storage /public/storage
/public/reference /public/reference
/public/assets/images/references /public/assets/images/references
/public/assets/images/members
/storage/*.key /storage/*.key
/vendor /vendor
.env .env

View file

@ -37,9 +37,19 @@ class DenController extends Controller
public function profile(Request $request) public function profile(Request $request)
{ {
$member = Auth::user(); $member = Auth::user();
$avi = '';
if ($member->avatar == 'default-member-avatar') {
$avi = '/assets/images/global/default-avi.png';
} else {
$avi = $member->avatar;
}
return view('back.profile', [ return view('back.profile', [
'handle' => $member->handle,
'title' => "Your Profile", 'title' => "Your Profile",
'handle' => $member->handle,
'email' => $member->email,
'avatar' => $avi,
'pronouns' => $member->pronoun,
'uuid' => $member->uuid,
'role' => $member->role 'role' => $member->role
]); ]);
} }

View file

@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Repositories\MemberRepository;
class MemberController extends Controller
{
protected $members;
public function __construct(
MemberRepository $memberRepo
) {
$this->members = $memberRepo;
}
public function memberEdit(Request $request)
{
$token = csrf_token();
$response = $this->members->edit($request);
if ($response['status'] == true) {
return back()->with('message', $response['message']);
} else {
return back()->withErrors([$response['message']]);
}
}
}

View file

@ -9,6 +9,7 @@ class Member extends Authenticatable
{ {
use HasFactory; use HasFactory;
public $timestamps = false;
protected $table = "member"; protected $table = "member";
protected $fillable = ["uuid", "handle", "email", "password", "active", "role", "avatar", "pronoun", "gender"]; protected $fillable = ["uuid", "handle", "email", "password", "active", "role", "avatar", "pronoun", "gender"];
} }

View file

@ -5,10 +5,12 @@ namespace App\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use App\Repositories\LocationRepository; use App\Repositories\LocationRepository;
use App\Repositories\SourceRepository; use App\Repositories\SourceRepository;
use App\Repositories\MemberRepository;
use App\Services\UpdateService; use App\Services\UpdateService;
use App\Services\MaintenanceService; use App\Services\MaintenanceService;
use App\Models\Location; use App\Models\Location;
use App\Models\Source; use App\Models\Source;
use App\Models\Member;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
@ -25,6 +27,10 @@ class AppServiceProvider extends ServiceProvider
return new SourceRepository(new Source()); return new SourceRepository(new Source());
}); });
$this->app->bind(MemberRepository::class, function ($app) {
return new MemberRepository(new Member());
});
$this->app->bind(UpdateService::class, function ($app) { $this->app->bind(UpdateService::class, function ($app) {
return new UpdateService( return new UpdateService(
new LocationRepository(new Location()), new LocationRepository(new Location()),

View file

@ -0,0 +1,59 @@
<?php
namespace App\Repositories;
use App\Models\Member;
use Illuminate\Support\Facades\Hash;
class MemberRepository
{
protected $model;
public function __construct(Member $model)
{
$this->model = $model;
}
public function get($uuid)
{
return $this->model::where("uuid", $uuid)->first();
}
public function edit($request)
{
//get member to edit
$member = $this->get($request->id);
//save new avi if available
$publicPath = '../public/';
$refPath = 'assets/images/members/' . $member->uuid;
if ($request->hasfile("fresh_avi")) {
$file = $request->fresh_avi;
if (!is_dir($publicPath . $refPath)) {
mkdir($publicPath . $refPath, 0755, true);
}
$filename = urlencode($file->getClientOriginalName());
$file->move($publicPath . $refPath, $filename);
$freshAvi = '/' . $refPath . '/' . $filename;
$member->avatar = $freshAvi;
}
//changing password
if (isset($request->fresh_pass) && $request->fresh_pass !== '') {
if ($request->fresh_pass === $request->fresh_pass_confirm) {
$member->password = Hash::make($request->fresh_pass);
} else {
return ['status' => false, 'message' => "Passwords Do Not Match"];
}
}
$member->handle = $request->handle;
$member->email = $request->email;
$member->pronoun = $request->pronouns;
if ($member->save()) {
return ['status' => true, 'message' => "Profile Editited"];
} else {
return ['status' => false, 'message' => "Profile Not Editited"];
}
}
}

View file

@ -36,6 +36,7 @@ input[type="submit"] {
border: 0; border: 0;
transition: all 0.3s linear; transition: all 0.3s linear;
height: 35px; height: 35px;
margin-top: 15px;
} }
select { select {

View file

@ -200,7 +200,6 @@ footer {
gap: 10px; gap: 10px;
height: auto; height: auto;
width: auto; width: auto;
margin: 20px auto;
position: relative; position: relative;
} }
@ -212,6 +211,15 @@ footer > div:nth-child(2) {
text-align: right; text-align: right;
} }
/*
member stuff
*/
.your-avatar {
width: 250px;
border-radius: 5px;
}
/* /*
responsive responsive
*/ */

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -6,7 +6,8 @@
<section> <section>
<article> <article>
<h2>Edit Profile Deets </h2> <h2>Edit Profile Deets </h2>
Hi. This is where you change stuff. @include('forms.profile-edit')
</article> </article>
</section> </section>
<br />
@endsection @endsection

View file

@ -0,0 +1,30 @@
<form action="/den/profile/edit" method="post" enctype="multipart/form-data">
<div>
<img class="your-avatar" src='{{$avatar}}'>
<br />
<label>New Avatar</label><br />
<input type="file" id="fresh_avi" name="fresh_avi" />
<br />
<label>Handle</label><br />
<input type="text" name="handle" value="{{$handle}}" />
<br />
<label>Email</label><br />
<input type="text" name="email" value="{{$email}}" />
<br />
<label>Pronouns</label><br />
<input type="text" name="pronouns" value="{{$pronouns}}" />
<br />
<h2>Change Password</h2>
<label>Fresh Password</label><br />
<input type="password" id="fresh_pass" name="fresh_pass" value="" />
<br />
<label>Confirm Fresh Password</label><br />
<input type="password" id="fresh_pass_confirm" name="fresh_pass_confirm" value="" />
<br />
</div>
@csrf
<input type="hidden" name="id" value="{{$uuid}}" />
<input type="submit" value="Edit Profile" name="submit_button">
</form>

View file

@ -5,6 +5,7 @@ use App\Http\Controllers\FrontIndexController;
use App\Http\Controllers\AuthController; use App\Http\Controllers\AuthController;
use App\Http\Controllers\DenController; use App\Http\Controllers\DenController;
use App\Http\Controllers\LocationController; use App\Http\Controllers\LocationController;
use App\Http\Controllers\MemberController;
use App\Http\Controllers\ExportController; use App\Http\Controllers\ExportController;
use App\Http\Controllers\AppealController; use App\Http\Controllers\AppealController;
@ -49,4 +50,6 @@ Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () {
Route::post("/locations/edit", [LocationController::class, 'editLocation']); Route::post("/locations/edit", [LocationController::class, 'editLocation']);
Route::get("/admin/update", [LocationController::class, 'updateLocations']); Route::get("/admin/update", [LocationController::class, 'updateLocations']);
Route::get("/admin/compile", [LocationController::class, 'compileLocations']); Route::get("/admin/compile", [LocationController::class, 'compileLocations']);
//member actions
Route::post("/profile/edit", [MemberController::class, 'memberEdit']);
}); });