public function handleSave(Form $form) { $values = $form->values; if ($values['file']->isOk()) { if ($values['cleanout']) { foreach ($this->userRepository->findAll() as $user) { $this->userRepository->delete($user); } } /** @var FileUpload $file */ $file = $values['file']; $data = file_get_contents($file->getTemporaryFile()); foreach (explode("\n", $data) as $row) { if (!$row) { continue; } $items = explode(',', $row); if (!count($items)) { continue; } try { $user = new UserEntity(trim($items[0])); } catch (InvalidArgumentException $e) { $form->addError($e->getMessage()); } $this->userRepository->save($user); } } }
/** * Update the specified resource in storage. * * @param int $id * @param UserRequest $request * @return Response */ public function update($id, UserRequest $request) { $data = $request->has('password') ? $request->all() : $request->except('password'); $this->user->save($id, $data); $route = $request->get('task') == 'apply' ? route('admin.users.edit', $id) : route('admin.users.index'); return redirect($route)->with(['status' => trans('messages.saved'), 'type-status' => 'success']); }
/** * Edits a user * @var User * @return \Illuminate\Http\RedirectResponse */ public function postEdit(User $user) { $oldUser = clone $user; $user->username = Input::get('username'); $user->email = Input::get('email'); $user->phone_number = Input::get('phone_number'); $password = Input::get('password'); $passwordConfirmation = Input::get('password_confirmation'); if (!empty($password)) { if ($password != $passwordConfirmation) { // Redirect to the new user page $error = Lang::get('admin/users/messages.password_does_not_match'); return Redirect::to('user')->with('error', $error); } else { $user->password = $password; $user->password_confirmation = $passwordConfirmation; } } $data = array('city_id' => Input::get('city_id'), 'address' => Input::get('address')); if ($user->address_id) { Address::where('id', $user->address_id)->update($data); } else { $address = Address::create($data); $user['address_id'] = $address->id; } if ($this->userRepo->save($user)) { return Redirect::to('user/profile/' . $user->username)->with('success', Lang::get('user/user.user_account_updated')); } else { $error = $user->errors()->all(':message'); return Redirect::to('user')->withInput(Input::except('password', 'password_confirmation'))->with('error', $error); } }
/** * Edits a user * @var User * @return \Illuminate\Http\RedirectResponse */ public function postEdit(User $user) { $oldUser = clone $user; $user->username = Input::get('username'); $user->email = Input::get('email'); $password = Input::get('password'); $passwordConfirmation = Input::get('password_confirmation'); if (!empty($password)) { if ($password != $passwordConfirmation) { $error = Lang::get('admin/users/messages.password_does_not_match'); return Redirect::to('user')->with('error', $error); } else { $user->password = $password; $user->password_confirmation = $passwordConfirmation; } } if ($this->userRepo->save($user)) { return Redirect::to('user')->with('success', Lang::get('user/user.user_account_updated')); } else { $error = $user->errors()->all(':message'); return Redirect::to('user')->withInput(Input::except('password', 'password_confirmation'))->with('error', $error); } }