Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty user profile fields #73

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 39 additions & 34 deletions wave/src/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function index($section = ''){
if(empty($section)){
return redirect(route('wave.settings', 'profile'));
}
return view('theme::settings.index', compact('section'));
return view('theme::settings.index', compact('section'));
}

public function profilePut(Request $request){
Expand All @@ -32,39 +32,44 @@ public function profilePut(Request $request){
'avatar.base64image' => 'The avatar must be a valid image.'
]);

$authed_user = auth()->user();
$authed_user = auth()->user();

$authed_user->name = $request->name;
$authed_user->email = $request->email;
$authed_user->name = $request->name;
$authed_user->email = $request->email;
if($request->avatar){
$authed_user->avatar = $this->saveAvatar($request->avatar, $authed_user->username);
$authed_user->avatar = $this->saveAvatar($request->avatar, $authed_user->username);
}
$authed_user->save();

foreach(config('wave.profile_fields') as $key){
if(isset($request->{$key})){
$type = $key . '_type__wave_keyvalue';
if($request->{$type} == 'checkbox'){
if(!isset($request->{$key})){
$request->request->add([$key => null]);
}
}

$row = (object)['field' => $key, 'type' => $request->{$type}, 'details' => ''];
$value = $this->getContentBasedOnType($request, 'themes', $row);

if(!is_null($authed_user->keyValue($key))){
$keyValue = KeyValue::where('keyvalue_id', '=', $authed_user->id)->where('keyvalue_type', '=', 'users')->where('key', '=', $key)->first();
$keyValue->value = $value;
$keyValue->type = $request->{$type};
$keyValue->save();
} else {
KeyValue::create(['type' => $request->{$type}, 'keyvalue_id' => $authed_user->id, 'keyvalue_type' => 'users', 'key' => $key, 'value' => $value]);
}
}
}

return back()->with(['message' => 'Successfully updated user profile', 'message_type' => 'success']);
$authed_user->save();

foreach(config('wave.profile_fields') as $key){
if(isset($request->{$key})){
$type = $key . '_type__wave_keyvalue';
if($request->{$type} == 'checkbox'){
if(!isset($request->{$key})){
$request->request->add([$key => null]);
}
}

$row = (object)['field' => $key, 'type' => $request->{$type}, 'details' => ''];
$value = $this->getContentBasedOnType($request, 'themes', $row);

if(!is_null($authed_user->keyValue($key))){
$keyValue = KeyValue::where('keyvalue_id', '=', $authed_user->id)->where('keyvalue_type', '=', 'users')->where('key', '=', $key)->first();
$keyValue->value = $value;
$keyValue->type = $request->{$type};
$keyValue->save();
} else {
KeyValue::create(['type' => $request->{$type}, 'keyvalue_id' => $authed_user->id, 'keyvalue_type' => 'users', 'key' => $key, 'value' => $value]);
}
} else {
if(!is_null($authed_user->keyValue($key))){
$keyValue = KeyValue::where('keyvalue_id', '=', $authed_user->id)->where('keyvalue_type', '=', 'users')->where('key', '=', $key)->first();
$keyValue->delete();
}
}
}

return back()->with(['message' => 'Successfully updated user profile', 'message_type' => 'success']);
}

public function securityPut(Request $request){
Expand Down Expand Up @@ -132,9 +137,9 @@ public function apiDelete(Request $request, $id = null){
}

private function saveAvatar($avatar, $filename){
$path = 'avatars/' . $filename . '.png';
Storage::disk(config('voyager.storage.disk'))->put($path, file_get_contents($avatar));
return $path;
$path = 'avatars/' . $filename . '.png';
Storage::disk(config('voyager.storage.disk'))->put($path, file_get_contents($avatar));
return $path;
}

public function invoice(Request $request, $invoiceId) {
Expand Down