Ejemplo n.º 1
0
 public function getEdit($id)
 {
     $brand = Brands::find((int) $id);
     if (empty($brand)) {
         return Redirect::to('admin/brand')->with('errors', 'Invalid Brand ID');
     }
     $users = array();
     foreach (User::all() as $key => $value) {
         $users[$value->id] = $value->getFullname();
     }
     $groups = array();
     foreach (\Saas\Groups\Groups\Eloquent\Group::all() as $group) {
         $groups[$group->id] = $group->name;
     }
     $brandUsers = Groups::getRelationProvider()->findBrandUsers($brand->id);
     $this->viewData = array('title' => 'Brand Panel - Update', 'brand' => $brand, 'userList' => $users, 'groupList' => $groups, 'brandUsers' => $brandUsers);
     $this->setupLayout();
 }
Ejemplo n.º 2
0
 /**
  * Group update
  */
 public function postUpdate($id = 0)
 {
     $user = User::find((int) Input::get('user_id'));
     if (!$user && !empty($id)) {
         $user = User::find($id);
         if (!$user) {
             Redirect::back()->with('warning', 'Invalid user id');
         }
     }
     if (Input::has('email')) {
         Input::flash();
         if (!$user->metas) {
             $meta = UserMeta::create(array('username' => ''));
             // First time meta
             $user->metas()->save($meta);
         }
         $userMeta = $user->metas()->first();
         $validator = Validator::make(Input::all(), array('email' => 'required|email', 'website' => 'url', 'username' => 'unique:user_meta,username,' . $userMeta->id, 'password' => (Input::get('change_password') == 'on' ? 'required|' : '') . 'min:5|confirmed'));
         if ($validator->fails()) {
             $error = $validator->messages()->first();
         } else {
             try {
                 // Update the user
                 $user->first_name = Input::get('first_name');
                 $user->last_name = Input::get('last_name');
                 $user->email = Input::get('email');
                 $user->save();
                 // Check for activation
                 if ($activationState = Input::get('account_status', '0')) {
                     if (!$user->isActivated()) {
                         $user->attemptActivation($user->getActivationCode());
                     }
                 } else {
                     $user->activated = NULL;
                     $user->save();
                 }
                 // Check for password changes
                 if (Input::get('change_password') == 'on' && ($newPassword = Input::get('password')) && !empty($newPassword)) {
                     if ($newPassword == Input::get('password_confirmation')) {
                         $user->attemptResetPassword($user->getResetPasswordCode(), $newPassword);
                     } else {
                         return Redirect::back()->with('warning', 'Password confirmation does not match');
                     }
                 }
                 // Update the meta
                 $userMeta->username = Input::get('username');
                 $userMeta->website = Input::get('website');
                 $userMeta->location = Input::get('location');
                 $userMeta->title = Input::get('title');
                 $userMeta->bio = Input::get('bio');
                 $userMeta->save();
                 return Redirect::route(Route::getBaseAdminRoute() . '.user.getindex')->with('message', 'User "' . $user->id . '" updated');
             } catch (\Exception $e) {
                 $error = $e->getMessage();
             }
         }
         // Populate any errors
         if (isset($error)) {
             Session::flash('warning', $error);
         }
     }
     $this->viewData = array('title' => 'User Panel - Edit ' . $user->getFullname($user->email), 'user' => $user, 'brands' => Brand::all(), 'groups' => Group::all());
     $this->setupLayout();
 }