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