public function add($id, Request $request) { $user = User::find($id); if ($user == null) { abort(404); } if ($user->id != Auth::id() && !Auth::user()->can('board')) { abort(403); } // Establish new address $address = new Address(); $addressdata = $request->all(); $addressdata['user_id'] = $user->id; if (!$address->validate($addressdata)) { return Redirect::route('user::address::add', ['id' => $id])->withErrors($address->errors()); } $address->fill($addressdata); // Save it baby! $address->save(); Session::flash("flash_message", "The address has been added."); if (Session::get('wizard')) { return Redirect::route('becomeamember'); } return Redirect::route('user::dashboard', ['id' => $id]); }
public function deleteUser(Request $request, $id) { $user = User::findOrFail($id); if ($user->id != Auth::id() && !Auth::user()->can('board')) { abort(403); } if ($user->member) { $request->session()->flash('flash_message', 'You cannot delete your account while you are a member.'); return Redirect::back(); } Address::where('user_id', $user->id)->delete(); Bank::where('user_id', $user->id)->delete(); EmailListSubscription::where('user_id', $user->id)->delete(); AchievementOwnership::where('user_id', $user->id)->delete(); Alias::where('user_id', $user->id)->delete(); RfidCard::where('user_id', $user->id)->delete(); WelcomeMessage::where('user_id', $user->id)->delete(); if ($user->photo) { $user->photo->delete(); } $user->password = null; $user->remember_token = null; $user->birthdate = null; $user->gender = null; $user->nationality = null; $user->phone = null; $user->website = null; $user->utwente_username = null; $user->tfa_totp_key = null; $user->tfa_yubikey_identity = null; $user->phone_visible = 0; $user->address_visible = 0; $user->receive_sms = 0; $user->save(); $user->delete(); $request->session()->flash('flash_message', 'Your account has been deleted.'); return Redirect::route('homepage'); }