2024-09-20 23:09:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Models\Member;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2024-09-27 20:39:56 +02:00
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
use Carbon\Carbon;
|
2024-09-20 23:09:45 +02:00
|
|
|
|
|
|
|
class MemberRepository
|
|
|
|
{
|
|
|
|
protected $model;
|
|
|
|
|
|
|
|
public function __construct(Member $model)
|
|
|
|
{
|
|
|
|
$this->model = $model;
|
|
|
|
}
|
|
|
|
|
2024-09-25 00:21:59 +02:00
|
|
|
public function getAll()
|
|
|
|
{
|
|
|
|
return $this->model::all();
|
|
|
|
}
|
|
|
|
|
2024-09-20 23:09:45 +02:00
|
|
|
public function get($uuid)
|
|
|
|
{
|
|
|
|
return $this->model::where("uuid", $uuid)->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit($request)
|
|
|
|
{
|
|
|
|
//get member to edit
|
|
|
|
$member = $this->get($request->id);
|
|
|
|
|
2024-09-25 00:21:59 +02:00
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$member->handle = $request->handle;
|
|
|
|
$member->email = $request->email;
|
|
|
|
$member->pronoun = $request->pronouns;
|
|
|
|
$member->role = $request->role;
|
|
|
|
$member->active = $request->status;
|
|
|
|
|
|
|
|
if ($member->save()) {
|
|
|
|
return ['status' => true, 'message' => "Member Editited"];
|
|
|
|
} else {
|
|
|
|
return ['status' => false, 'message' => "Member Not Editited"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-27 20:39:56 +02:00
|
|
|
public function add($request)
|
|
|
|
{
|
|
|
|
$password = [];
|
|
|
|
if ($request->fresh_pass === $request->fresh_pass_confirm) {
|
|
|
|
$password = Hash::make($request->fresh_pass);
|
|
|
|
} else {
|
|
|
|
return ['status' => false, 'message' => "Passwords Do Not Match"];
|
|
|
|
}
|
|
|
|
|
|
|
|
$newFriend = $this->model::create([
|
|
|
|
'uuid' => Uuid::uuid4(),
|
|
|
|
'avatar' => 'default-member-avatar',
|
|
|
|
'handle' => $request->handle,
|
|
|
|
'email' => $request->email,
|
|
|
|
'pronoun' => $request->pronouns,
|
|
|
|
'role' => $request->role,
|
|
|
|
'active' => $request->status,
|
|
|
|
'password' => $password,
|
|
|
|
'created_at' => Carbon::now(),
|
|
|
|
'last_login' => Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($newFriend) {
|
|
|
|
return ['status' => true, 'message' => "New Friend Made!"];
|
|
|
|
} else {
|
|
|
|
return ['status' => false, 'message' => "Uh oh, New Friend Delay!"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 00:21:59 +02:00
|
|
|
public function editProfile($request)
|
|
|
|
{
|
|
|
|
//get member to edit
|
|
|
|
$member = $this->get($request->id);
|
|
|
|
|
2024-09-20 23:09:45 +02:00
|
|
|
//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"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|