forked from projects/thebadspace
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:
parent
31f45c4af5
commit
098cd72186
1 changed files with 46 additions and 14 deletions
|
@ -76,11 +76,20 @@ 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) {
|
||||||
$response = $this->member->editProfile($request);
|
//validate required fields
|
||||||
if ($response['status'] == true) {
|
$valid = $request->validate([
|
||||||
return back()->with('message', $response['message']);
|
'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 {
|
} else {
|
||||||
return back()->withErrors([$response['message']]);
|
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,12 +101,22 @@ 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) {
|
||||||
$response = $this->member->edit($request);
|
$valid = $request->validate([
|
||||||
if ($response['status'] == true) {
|
'handle' => ['required'],
|
||||||
return back()->with('message', $response['message']);
|
'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 {
|
} else {
|
||||||
return back()->withErrors([$response['message']]);
|
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,12 +127,25 @@ 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) {
|
||||||
$response = $this->member->add($request);
|
$valid = $request->validate([
|
||||||
if ($response['status'] == true) {
|
'handle' => ['required'],
|
||||||
return redirect('/den/member')->with('message', $response['message']);
|
'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 {
|
} else {
|
||||||
return back()->withErrors([$response['message']]);
|
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.']);
|
||||||
|
|
Loading…
Reference in a new issue