@@ 1000-1038 (lines=39) @@ | ||
997 | * @param int $gid |
|
998 | * @return Redirect |
|
999 | */ |
|
1000 | public function getAdminRemoveGroup($id = null, $gid = null) |
|
1001 | { |
|
1002 | // Get user information |
|
1003 | $user = Sentinel::findById($id); |
|
1004 | ||
1005 | if ($user == null) |
|
1006 | { |
|
1007 | // Prepare the error message |
|
1008 | $error = Lang::get('base.auth.not_found'); |
|
1009 | return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
|
1010 | } |
|
1011 | ||
1012 | // Check if we are not trying to delete ourselves |
|
1013 | if ($user->id === Sentinel::getUser()->id + 1) { |
|
1014 | // Prepare the error message |
|
1015 | $error = Lang::get('base.base.yourself'); |
|
1016 | ||
1017 | return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
|
1018 | } |
|
1019 | ||
1020 | // Get group information |
|
1021 | $group = Sentinel::findRoleById($gid); |
|
1022 | ||
1023 | if ($group == null) |
|
1024 | { |
|
1025 | // Prepare the error message |
|
1026 | $error = Lang::get('base.groups.not_found'); |
|
1027 | return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
|
1028 | } |
|
1029 | ||
1030 | // Remove the group |
|
1031 | $group->users()->detach($user); |
|
1032 | ||
1033 | // Prepare the success message |
|
1034 | $success = Lang::get('base.groups.removed'); |
|
1035 | ||
1036 | // Redirect to the user management page |
|
1037 | return Redirect::route('users.update', $user->id)->with('success', $success); |
|
1038 | } |
|
1039 | ||
1040 | /** |
|
1041 | * Add the group to a given user. |
|
@@ 1046-1085 (lines=40) @@ | ||
1043 | * @param int $id |
|
1044 | * @return Redirect |
|
1045 | */ |
|
1046 | public function postAdminAddGroup($id = null) |
|
1047 | { |
|
1048 | // Get user information |
|
1049 | $user = Sentinel::findById($id); |
|
1050 | ||
1051 | if ($user == null) |
|
1052 | { |
|
1053 | // Prepare the error message |
|
1054 | $error = Lang::get('base.auth.not_found'); |
|
1055 | return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
|
1056 | } |
|
1057 | ||
1058 | $gid = Input::get('group'); |
|
1059 | ||
1060 | if ($gid == null) |
|
1061 | { |
|
1062 | // Prepare the error message |
|
1063 | $error = Lang::get('base.groups.not_found'); |
|
1064 | return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
|
1065 | } |
|
1066 | ||
1067 | // Get group information |
|
1068 | $group = Sentinel::findRoleById($gid); |
|
1069 | ||
1070 | if ($group == null) |
|
1071 | { |
|
1072 | // Prepare the error message |
|
1073 | $error = Lang::get('base.groups.not_found'); |
|
1074 | return View('layouts.modal_confirmation', compact('title', 'message', 'error', 'model', 'confirm_route')); |
|
1075 | } |
|
1076 | ||
1077 | // Remove the group |
|
1078 | $group->users()->attach($user); |
|
1079 | ||
1080 | // Prepare the success message |
|
1081 | $success = Lang::get('base.groups.added'); |
|
1082 | ||
1083 | // Redirect to the user management page |
|
1084 | return Redirect::route('users.update', $user->id)->with('success', $success); |
|
1085 | } |
|
1086 | ||
1087 | } |
|
1088 |