form validation for member editing

added some form validation in the member controller to make sure all
necessary info is provided before editing/creating member
This commit is contained in:
ro 2024-09-29 16:11:50 -06:00
parent 31f45c4af5
commit 098cd72186

View file

@ -76,12 +76,21 @@ class MemberController extends Controller
//check if logged in member id matches profile request id //check if logged in member id matches profile request id
$member = Auth::user(); $member = Auth::user();
if ($member->uuid == $request->id) { if ($member->uuid == $request->id) {
//validate required fields
$valid = $request->validate([
'handle' => ['required'],
'email' => ['required'],
]);
if ($valid) {
$response = $this->member->editProfile($request); $response = $this->member->editProfile($request);
if ($response['status'] == true) { if ($response['status'] == true) {
return back()->with('message', $response['message']); return back()->with('message', $response['message']);
} else { } else {
return back()->withErrors([$response['message']]); return back()->withErrors([$response['message']]);
} }
} else {
return back()->withErrors(['Misssing some required info, homie.']);
}
} else { } else {
return back()->withErrors(['This is not your profile to edit.']); return back()->withErrors(['This is not your profile to edit.']);
} }
@ -92,13 +101,23 @@ class MemberController extends Controller
$token = csrf_token(); $token = csrf_token();
//role check //role check
$member = Auth::user(); $member = Auth::user();
if ($member->role == 0 || $member->role == 1) { if ($member->role == 0) {
$valid = $request->validate([
'handle' => ['required'],
'email' => ['required'],
'role' => ['required']
]);
if ($valid) {
$response = $this->member->edit($request); $response = $this->member->edit($request);
if ($response['status'] == true) { if ($response['status'] == true) {
return back()->with('message', $response['message']); return back()->with('message', $response['message']);
} else { } else {
return back()->withErrors([$response['message']]); return back()->withErrors([$response['message']]);
} }
} else {
return back()->withErrors(['Misssing some required info, homie.']);
}
} else { } else {
return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']); return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']);
} }
@ -108,13 +127,26 @@ class MemberController extends Controller
{ {
$token = csrf_token(); $token = csrf_token();
$member = Auth::user(); $member = Auth::user();
if ($member->role == 0 || $member->role == 1) { 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); $response = $this->member->add($request);
if ($response['status'] == true) { if ($response['status'] == true) {
return redirect('/den/member')->with('message', $response['message']); return redirect('/den/member')->with('message', $response['message']);
} else { } else {
return back()->withErrors([$response['message']]); return back()->withErrors([$response['message']]);
} }
} else {
return back()->withErrors(['Misssing some required info, homie.']);
}
} else { } else {
return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']); return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']);
} }