2024-09-20 23:09:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2024-09-25 00:21:59 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-09-20 23:09:45 +02:00
|
|
|
use App\Repositories\MemberRepository;
|
|
|
|
|
|
|
|
class MemberController extends Controller
|
|
|
|
{
|
2024-09-25 00:21:59 +02:00
|
|
|
protected $member;
|
2024-09-20 23:09:45 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
MemberRepository $memberRepo
|
|
|
|
) {
|
2024-09-25 00:21:59 +02:00
|
|
|
$this->member = $memberRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$member = Auth::user();
|
|
|
|
return view('back.member', [
|
|
|
|
'handle' => $member->handle,
|
|
|
|
'members' => $this->member->getAll(),
|
|
|
|
'mode' => 'index',
|
|
|
|
'title' => "Manage Members"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function profile(Request $request)
|
|
|
|
{
|
|
|
|
$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', [
|
|
|
|
'title' => "Hey, it's you!",
|
|
|
|
'handle' => $member->handle,
|
|
|
|
'email' => $member->email,
|
|
|
|
'avatar' => $avi,
|
|
|
|
'pronouns' => $member->pronoun,
|
|
|
|
'uuid' => $member->uuid,
|
|
|
|
'role' => $member->role
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editMember(Request $request, $uuid = 0)
|
|
|
|
{
|
|
|
|
$member = $this->member->get($uuid);
|
|
|
|
$avi = '';
|
|
|
|
if ($member->avatar == 'default-member-avatar') {
|
|
|
|
$avi = '/assets/images/global/default-avi.png';
|
|
|
|
} else {
|
|
|
|
$avi = $member->avatar;
|
|
|
|
}
|
|
|
|
return view('back.member', [
|
|
|
|
'member' => $member,
|
|
|
|
'avatar' => $avi,
|
|
|
|
'mode' => 'member-edit',
|
|
|
|
'title' => "Edit Member Info"]);
|
|
|
|
}
|
|
|
|
|
2024-09-27 20:39:56 +02:00
|
|
|
public function createMember(Request $Request)
|
|
|
|
{
|
|
|
|
return view('back.member', [
|
|
|
|
'mode' => 'member-create',
|
|
|
|
'title' => "Make a new friend"]);
|
|
|
|
}
|
|
|
|
|
2024-09-25 00:21:59 +02:00
|
|
|
//actions
|
|
|
|
public function profileEdit(Request $request)
|
|
|
|
{
|
2024-09-29 23:55:55 +02:00
|
|
|
$token = csrf_token();
|
|
|
|
//check if logged in member id matches profile request id
|
|
|
|
$member = Auth::user();
|
|
|
|
if ($member->uuid == $request->id) {
|
2024-09-30 00:11:50 +02:00
|
|
|
//validate required fields
|
|
|
|
$valid = $request->validate([
|
|
|
|
'handle' => ['required'],
|
|
|
|
'email' => ['required'],
|
|
|
|
]);
|
|
|
|
if ($valid) {
|
|
|
|
$response = $this->member->editProfile($request);
|
|
|
|
if ($response['status'] == true) {
|
|
|
|
return back()->with('message', $response['message']);
|
|
|
|
} else {
|
|
|
|
return back()->withErrors([$response['message']]);
|
|
|
|
}
|
2024-09-29 23:55:55 +02:00
|
|
|
} else {
|
2024-09-30 00:11:50 +02:00
|
|
|
return back()->withErrors(['Misssing some required info, homie.']);
|
2024-09-29 23:55:55 +02:00
|
|
|
}
|
2024-09-25 00:21:59 +02:00
|
|
|
} else {
|
2024-09-29 23:55:55 +02:00
|
|
|
return back()->withErrors(['This is not your profile to edit.']);
|
2024-09-25 00:21:59 +02:00
|
|
|
}
|
2024-09-20 23:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function memberEdit(Request $request)
|
|
|
|
{
|
2024-09-29 23:55:55 +02:00
|
|
|
$token = csrf_token();
|
|
|
|
//role check
|
|
|
|
$member = Auth::user();
|
2024-09-30 00:11:50 +02:00
|
|
|
if ($member->role == 0) {
|
|
|
|
$valid = $request->validate([
|
|
|
|
'handle' => ['required'],
|
|
|
|
'email' => ['required'],
|
|
|
|
'role' => ['required']
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($valid) {
|
|
|
|
$response = $this->member->edit($request);
|
|
|
|
if ($response['status'] == true) {
|
|
|
|
return back()->with('message', $response['message']);
|
|
|
|
} else {
|
|
|
|
return back()->withErrors([$response['message']]);
|
|
|
|
}
|
2024-09-29 23:55:55 +02:00
|
|
|
} else {
|
2024-09-30 00:11:50 +02:00
|
|
|
return back()->withErrors(['Misssing some required info, homie.']);
|
2024-09-29 23:55:55 +02:00
|
|
|
}
|
2024-09-20 23:09:45 +02:00
|
|
|
} else {
|
2024-09-29 23:55:55 +02:00
|
|
|
return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']);
|
2024-09-20 23:09:45 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-27 20:39:56 +02:00
|
|
|
|
|
|
|
public function memberCreate(Request $request)
|
|
|
|
{
|
2024-09-29 23:55:55 +02:00
|
|
|
$token = csrf_token();
|
|
|
|
$member = Auth::user();
|
2024-09-30 00:11:50 +02:00
|
|
|
if ($member->role == 0) {
|
|
|
|
$valid = $request->validate([
|
|
|
|
'handle' => ['required'],
|
|
|
|
'email' => ['required'],
|
|
|
|
'role' => ['required'],
|
|
|
|
'pronouns' => ['required'],
|
|
|
|
'fresh_pass' => ['required'],
|
|
|
|
'fresh_pass_confirm' => ['required'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($valid) {
|
|
|
|
$response = $this->member->add($request);
|
|
|
|
if ($response['status'] == true) {
|
|
|
|
return redirect('/den/member')->with('message', $response['message']);
|
|
|
|
} else {
|
|
|
|
return back()->withErrors([$response['message']]);
|
|
|
|
}
|
2024-09-29 23:55:55 +02:00
|
|
|
} else {
|
2024-09-30 00:11:50 +02:00
|
|
|
return back()->withErrors(['Misssing some required info, homie.']);
|
2024-09-29 23:55:55 +02:00
|
|
|
}
|
2024-09-27 20:39:56 +02:00
|
|
|
} else {
|
2024-09-29 23:55:55 +02:00
|
|
|
return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']);
|
2024-09-27 20:39:56 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-20 23:09:45 +02:00
|
|
|
}
|