/** * Store a newly created resource in storage. * * @return Response */ public function postCreate(UserRequest $request) { $user = new User(); $user->name = $request->name; $user->tipo_usuario = $request->tipo_usuario; $user->username = $request->username; $user->email = $request->email; $user->password = bcrypt($request->password); $user->confirmation_code = str_random(32); $user->confirmed = $request->confirmed; $picture = ""; if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $picture = sha1($filename . time()) . '.' . $extension; $destinationPath = public_path() . '/uploads/users/fotos/'; $request->file('image')->move($destinationPath, $picture); $path2 = public_path() . '/uploads/users/fotos/thumbs/'; Thumbnail::generate_image_thumbnail($destinationPath . $picture, $path2 . $picture); } $user->filename = $picture; if ($user->save()) { return redirect("/admin/users"); } }
public function postEdit(UserRequest $request) { $data = $request->all(); $response = ['errors' => []]; if ($data['id']) { $response['data'] = $this->repository->update($data); } return $response; }
/** * Update the specified resource in storage. * * @param $user * @return Response */ public function update(UserRequest $request, User $user) { $password = $request->password; $passwordConfirmation = $request->password_confirmation; if (!empty($password)) { if ($password === $passwordConfirmation) { $user->password = bcrypt($password); } } $user->update($request->except('password', 'password_confirmation')); }
/** * Execute the job. * * @return bool */ public function handle() { $this->user->name = $this->request->input('name'); $this->user->email = $this->request->input('email'); $password = $this->request->input('password'); // If the user doesn't have a set password mutator, // we'll encrypt the password. if (!$this->user->hasSetMutator('password')) { $password = bcrypt($password); } $this->user->password = $password; return $this->user->save(); }
public function postUpdate(Requests\Admin\UserRequest $request, $act, $id = 0) { $user = new User(); if ($act == 'edit') { $user = User::find($id); } $user->name = $request->input('name'); $user->phone = $request->input('phone'); $user->email = $request->input('email'); $user->password = $request->input('password') ?: $user->password; if ($user->save()) { $info = ['from' => 'update', 'status' => 'success']; j4flash($info); return redirect('admin/user'); } else { return redirect()->back()->withErrors(['err' => lang('submit failed')])->withInput(); } }
/** * Update the specified user in storage. * * @param User $user * @param UserRequest $request * @return Response */ public function update(User $user, UserRequest $request) { $saveRole = function () use($user, $request) { $user->roles()->sync([$request->get("role")]); }; $fields = $request->all(); if ($fields['password']) { $fields['password'] = Hash::make($fields['password']); } else { unset($fields['password']); } $user->fill($fields); if ($user->save()) { call_user_func($saveRole); Flash::success(trans('admin.update.success')); } else { Flash::error(trans('admin.update.fail')); } return $this->redirectRoutePath("index"); }
/** * Execute the job. * * @throws CannotRemoveRolesException * * @return bool */ public function handle() { $this->user->name = $this->request->input('name', $this->user->name); $this->user->email = $this->request->input('email'); $password = $this->request->input('password'); // Verify before changing the users password that it's not empty. if (!empty($password)) { // If the user doesn't have a set password mutator, // we'll encrypt the password. if (!$this->user->hasSetMutator('password')) { $password = bcrypt($password); } $this->user->password = $password; } // Retrieve the administrators name. $adminName = Role::getAdministratorName(); $roles = $this->request->input('roles', []); // Retrieve all administrator users. $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) { $builder->whereName($adminName); })->get(); // Retrieve the administrator role. $admin = Role::whereName($adminName)->first(); // We need to verify that if the user is trying to remove all roles on themselves, // and they are the only administrator, that we throw an exception notifying them // that they can't do that. Though we want to allow the user to remove the // administrator role if more than one administrator exists. if (count($roles) === 0 && $this->user->hasRole($admin) && $this->user->getKey() === auth()->user()->getKey() && count($administrators) === 1) { throw new CannotRemoveRolesException("Unable to remove the administrator role. You're the only administrator."); } if ($this->user->save()) { $this->user->roles()->sync($roles); return true; } return false; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Requests\Admin\UserRequest $request, User $user) { $data = $request->all(); if ($request->password) { $data['password'] = bcrypt($data['password']); } else { unset($data['password']); } $user->update($data); $user->roles()->sync($request->input('role_list')); return redirect('/admin/user')->with('flash_success', 'Пользователь успешно обновлен.'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UserRequest $request, int $id) { $dataUpdate = $request->except(['_token', '_method']); if ($dataUpdate['password']) { $dataUpdate['password'] = Hash::make($dataUpdate['password']); } User::where('id', $id)->update($dataUpdate); return redirect()->action('Admin\\UserController@index'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, ModelRequest $request) { try { $roles = $request->input('roles', []); $departments = $request->input('departments', []); $user_id = $request->input('user_id', null); $clear_picture = $request->input('clear_picture', false); $model = $this->getModel($id); try { DB::beginTransaction(); $model->user_id = $user_id; $model->update($request->all()); $model->roles()->sync($roles); $model->departments()->sync($departments); if ($clear_picture) { $picture = $model->picture; if ($picture) { try { File::delete(base_path() . $picture->filename); $picture->forcedelete(); } catch (Exception $e) { } } } else { if ($request->hasFile('photo')) { $uploaded_file = $request->file('photo'); if ($uploaded_file->isValid()) { $picture = $model->picture; if (!$picture) { $picture = new Picture(); } else { try { File::delete(base_path() . $picture->filename); } catch (Exception $e) { } } $picture->filename = $this->save_picture($model->name, $uploaded_file); $picture->mime_type = $uploaded_file->getMimeType(); $picture->extension = $uploaded_file->guessExtension(); if (!$picture->extension) { $picture->extension = $uploaded_file->getExtension(); } $picture->user_id = $model->id; $picture->save(); } } } DB::commit(); Flash::info(trans($this->resource_name . 'saved', ['model' => $this->model_name])); return redirect(route($this->show_route, [$model->id])); } catch (Exception $e) { DB::rollBack(); throw $e; } } catch (Exception $e) { $errors = []; if ($e->getCode() == 23000) { $errors['email'] = trans($this->resource_name . 'duplicated_email'); } else { Flash::error($e->getMessage()); } return $request->response($errors); } }