/** * Change the current users password. * * @param string $password The new password. * @param int $user_id The id of the user. * * @return boolean */ public function changePassword($password, $user_id = null) { if ($user_id === null) { $user_id = $this->userId(); } //if return $this->User->update(array('password' => \Crypt::hash($password)))->where('id=?', $user_id)->finalize(); }
public function save() { $di = $this->getDi(); $em = $di['doctrine'](); $user = new User(); $user->setEntityManager($em); $user->update(); header('Location: /users'); }
/** * Edit action method * * @return void */ public function edit($id) { $user = new Model\User(); $user->getById($id); if (!isset($user->id)) { $this->redirect('/users'); } if ($this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $user->role_id, 'edit')) { $this->prepareView('users/edit.phtml'); $this->view->title = 'Edit User'; $this->view->username = $user->username; $role = new Model\Role(); $roles = $role->getAll(); $roleValues = []; foreach ($roles as $r) { $roleValues[$r->id] = $r->name; } $fields = $this->application->config()['forms']['App\\Form\\User']; $fields[1]['username']['attributes']['onkeyup'] = 'pop.changeTitle(this.value);'; $fields[1]['password1']['required'] = false; $fields[1]['password2']['required'] = false; $fields[0]['clear_logins']['value'][1] = $user->total_logins . ' Login' . ($user->total_logins == 1 ? '' : 's'); $fields[0]['role_id']['type'] = 'select'; $fields[0]['role_id']['label'] = 'Role'; $fields[0]['role_id']['value'] = $roleValues; $fields[0]['role_id']['marked'] = $user->role_id; $this->view->form = new Form\User($fields); $this->view->form->addFilter('strip_tags', null, 'textarea')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray()); if ($this->request->isPost()) { $this->view->form->addFilter('strip_tags', null, 'textarea')->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $user = new Model\User(); $user->update($this->view->form->getFields(), $this->application->config()['application_title'], $this->sess); $this->view->id = $user->id; $this->sess->setRequestValue('saved', true); $this->redirect('/users/edit/' . $user->id); } } $this->send(); } else { $this->redirect('/users'); } }
/** * Password action method * * @return void */ public function password() { $roleId = $this->getRoleId(); $user = new Model\User(); $users = $user->getAll($roleId); $userIds = []; $this->console->append(); $this->console->append("ID \tUsername\tEmail"); $this->console->append("----\t--------\t-----"); foreach ($users as $user) { $userIds[] = $user->id; $this->console->append($user->id . "\t" . $user->username . "\t\t" . $user->email); } $this->console->append(); $this->console->send(); $userId = null; while (!is_numeric($userId) || !in_array($userId, $userIds)) { $userId = $this->console->prompt('Select User ID: '); } $password = ''; while ($password == '') { $password = $this->console->prompt('Enter New Password: '******'id' => $userId, 'role_id' => $roleId, 'password1' => $password], $this->application->config()['application_title']); $this->console->write(); $this->console->write($this->console->colorize('User Password Updated!', Console::BOLD_GREEN)); }
/** * Update the specified resource in storage. * * ps: Queue works when you have 3rd party service taking care for your jobs like Amazon SQS. * Using Amazon SQS, you can queue mails, * jobs, etc. If 3rd party service is not configured, * Laravel performs all command at the same time as a fail-safe. * * @param Illuminate\Http\Request $request * @param App\Model\User $user * @return \Illuminate\Http\Response */ public function update(Request $request, User $user) { $user->update($request->all()); return $this->redirectWithSuccessFlash("user/{$user->id}/edit", "您已經更新了<b>{$user->username}</b>的資料"); }
/** * Profile action method * * @return void */ public function profile() { $this->prepareView('profile.phtml'); $this->view->title = 'My Profile'; $user = new Model\User(); $user->getById($this->sess->user->id); $this->view->form = new Form\Profile($this->application->config()['forms']['App\\Form\\Profile']); $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray()); if ($this->request->isPost()) { $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $user = new Model\User(); $user->update($this->view->form->getFields(), $this->sess); $this->view->id = $user->id; $this->sess->setRequestValue('saved', true); $this->redirect('/profile'); } } $this->send(); }
public function update(User $user) { //验证表单 $this->validate($this->request(), ['mobile' => 'required|digits:11', 'birthday' => 'required|date', 'sex' => 'required|in:' . array_keys_impload(UserEnum::$sexLang), 'password' => 'min:5|max:20', 'password_confirm' => 'required_with:password|same:password', 'marriage' => 'in:' . array_keys_impload(UserEnum::$marriageLang), 'height' => 'numeric|digits:3|min:130|max:210', 'education' => 'in:' . array_keys_impload(UserEnum::$educationLang), 'salary' => 'in:' . array_keys_impload(UserEnum::$salaryLang), 'user_name' => 'required|min:2|max:15']); $form = $this->request()->only(['sex', 'user_name', 'mobile', 'birthday', 'marriage', 'height', 'education', 'salary', 'work_province', 'work_city', 'level', 'house', 'children', 'realname', 'status']); if ($password = $this->request()->get('password')) { $form['password'] = $password; } $info = $this->request()->only(array('stock', 'origin_province', 'origin_city', 'introduce')); $object = $this->request()->get('object'); try { transaction(); $user->update($form); $user->info()->update($info); $user->object()->update($object); commit(); return $this->redirect()->back()->withErrors(array('success' => '保存成功')); } catch (\Exception $e) { rollback(); } return $this->redirect()->back()->withErrors(array('error' => '修改失败,请稍后再试')); }