Ejemplo n.º 1
0
 public function getEdit($sid)
 {
     $user = User::find($sid);
     if ($user == null) {
         $errors = new MessageBag();
         $errors->add('editError', Lang::get('redminportal::messages.user_error_user_not_found'));
         return redirect('/admin/users')->withErrors($errors);
     }
     $roles = Group::orderBy('name')->lists('name', 'id');
     $groups = [];
     foreach ($user->groups as $group) {
         $groups[$group->id] = $group->id;
     }
     $permission_inherit = [];
     $permission_allow = [];
     $permission_deny = [];
     foreach ($user->permissions() as $key => $value) {
         if ($value < 0) {
             $permission_deny[$key] = $key;
         } elseif ($value > 0) {
             $permission_allow[$key] = $key;
         } else {
             $permission_inherit[$key] = $key;
         }
     }
     $data = array('roles' => $roles, 'user' => $user, 'groups' => $groups, 'permission_inherit' => implode(',', $permission_inherit), 'permission_allow' => implode(',', $permission_allow), 'permission_deny' => implode(',', $permission_deny));
     return view('redminportal::users/edit', $data);
 }
Ejemplo n.º 2
0
 public function postStore()
 {
     $sid = \Input::get('id');
     $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required');
     if (isset($sid)) {
         $rules['password'] = '******';
     } else {
         $rules['password'] = '******';
     }
     $validation = \Validator::make(\Input::all(), $rules);
     $path = isset($sid) ? 'admin/users/edit/' . $sid : 'admin/users/create';
     if ($validation->fails()) {
         return redirect($path)->withErrors($validation)->withInput();
     }
     $first_name = \Input::get('first_name');
     $last_name = \Input::get('last_name');
     $email = \Input::get('email');
     $password = \Input::get('password');
     $role = \Input::get('role');
     $activated = \Input::get('activated') == '' ? false : true;
     $user = isset($sid) ? User::find($sid) : new User();
     if ($user == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The user cannot be found or created. Please try again later.");
         return redirect('/admin/users')->withErrors($errors);
     }
     // Save or Update
     $user->email = $email;
     if ($password != '') {
         $user->password = \Hash::make($password);
     }
     $user->first_name = $first_name;
     $user->last_name = $last_name;
     $user->activated = $activated;
     if (!$user->save()) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The user cannot be updated due to some problem. Please try again.");
         return redirect($path)->withErrors($errors)->withInput();
     }
     // Find user's group
     $old_group = $user->groups()->first();
     $new_group = Group::find($role);
     if ($new_group == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The user cannot be updated because the selected group cannot be found. Please try again.");
         return redirect($path)->withErrors($errors)->withInput();
     }
     // Assign the group to the user
     if ($old_group == null) {
         $user->groups()->save($new_group);
     } elseif ($old_group->id != $new_group->id) {
         $user->groups()->detach();
         $user->groups()->save($new_group);
     }
     return redirect('admin/users');
 }
Ejemplo n.º 3
0
 public function run()
 {
     DB::table('users')->delete();
     DB::table('groups')->delete();
     DB::table('users_groups')->delete();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = \Hash::make("admin");
     $user->first_name = 'System';
     $user->last_name = 'Admin';
     $user->activated = 1;
     $user->save();
     $admin_group = new Group();
     $admin_group->name = 'Admin';
     $admin_group->permissions = json_encode(array('admin.view' => 1, 'admin.create' => 1, 'admin.delete' => 1, 'admin.update' => 1));
     $admin_group->save();
     $user_group = new Group();
     $user_group->name = 'User';
     $user_group->permissions = json_encode(array('admin.view' => 0, 'admin.create' => 0, 'admin.delete' => 0, 'admin.update' => 0));
     $user_group->save();
     // Assign user permissions
     $user->groups()->save($admin_group);
 }
Ejemplo n.º 4
0
 public function getSort($sortBy = 'email', $orderBy = 'asc')
 {
     $inputs = array('sortBy' => $sortBy, 'orderBy' => $orderBy);
     $rules = array('sortBy' => 'required|regex:/^[a-zA-Z0-9 _-]*$/', 'orderBy' => 'required|regex:/^[a-zA-Z0-9 _-]*$/');
     $validation = \Validator::make($inputs, $rules);
     if ($validation->fails()) {
         return redirect('admin/groups')->withErrors($validation);
     }
     if ($orderBy != 'asc' && $orderBy != 'desc') {
         $orderBy = 'asc';
     }
     $groups = Group::orderBy($sortBy, $orderBy)->paginate(20);
     return view('redminportal::groups/view')->with('sortBy', $sortBy)->with('orderBy', $orderBy)->with('groups', $groups);
 }
Ejemplo n.º 5
0
 public function getDelete($sid)
 {
     $group = Group::find($sid);
     if ($group == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The group cannot be deleted at this time. It may have already been deleted.");
         return redirect()->back()->withErrors($errors);
     }
     if (count($group->users) > 0) {
         // Prevent deletion of this group
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The group cannot be deleted because it is in use. Try moving the users to another group first.");
         return redirect()->back()->withErrors($errors);
     } else {
         $group->delete();
     }
     return redirect()->back();
 }
Ejemplo n.º 6
0
 /**
     /* Add Group(s) to User
     /* @param Group can be single Id or array of Group Id
     /* @return bool True if successful
 */
 public function addGroup($group_id)
 {
     $successful = true;
     if ($group_id == null) {
         return false;
     }
     // Remove all existing group(s) from user
     $this->groups()->detach();
     // Assign group(s) to user
     if (is_array($group_id)) {
         // If multiple roles
         if (count($group_id) > 0) {
             foreach ($group_id as $item) {
                 $new_group = Group::find($item);
                 if ($new_group == null) {
                     $successful = false;
                 } else {
                     $this->groups()->save($new_group);
                 }
             }
         }
     } else {
         $new_group = Group::find($group_id);
         if ($new_group == null) {
             $successful = false;
         } else {
             $this->groups()->save($new_group);
         }
     }
     return $successful;
 }