mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-06-25 16:04:37 -05:00
added member profile editing
added a basic ui so logged in members can change their info/password when needed
This commit is contained in:
59
app/Repositories/MemberRepository.php
Normal file
59
app/Repositories/MemberRepository.php
Normal 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"];
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user