示例#1
0
 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');
 }
示例#2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $idOrAlias)
 {
     $alias = Alias::find($idOrAlias);
     if ($alias) {
         $alias->delete();
         $request->session()->flash('flash_message', 'Entry deleted.');
         return Redirect::back();
     }
     $affected = DB::table('alias')->where('alias', $idOrAlias)->delete();
     if ($affected > 0) {
         $request->session()->flash('flash_message', 'Deleted alias <strong>' . $idOrAlias . '</strong> with ' . $affected . ' destinations.');
         return Redirect::back();
     } else {
         $request->session()->flash('flash_message', 'No such alias (' . $idOrAlias . ').');
         return Redirect::back();
     }
 }
示例#3
0
 private function constructForwarderList()
 {
     $data = [];
     // Constructing user forwarders.
     $users = User::all();
     foreach ($users as $user) {
         if ($user->member && $user->isActiveMember()) {
             $data[$user->member->proto_username] = [$user->email];
         }
     }
     // Constructing committee forwarders.
     $committees = Committee::all();
     foreach ($committees as $committee) {
         $destinations = [];
         $users = CommitteeMembership::withTrashed()->where('committee_id', $committee->id)->where('created_at', '<', date('Y-m-d H:i:s'))->where(function ($q) {
             $q->whereNull('deleted_at')->orWhere('deleted_at', '>', date('Y-m-d H:i:s'));
         })->get();
         foreach ($users as $user) {
             $destinations[] = $user->user->email;
         }
         if (count($destinations) > 0) {
             $data[$committee->slug] = $destinations;
             $data['committees'][] = $committee->slug . '@' . config('proto.emaildomain');
         }
     }
     // Constructing manual aliases.
     $aliases = Alias::all();
     foreach ($aliases as $alias) {
         if ($alias->destination) {
             $data[$alias->alias][] = $alias->destination;
         } else {
             $data[$alias->alias][] = $alias->user->email;
         }
     }
     return $data;
 }