public function update($id) { if (!$id) { return Redirect::action('system/group')->with('error', '用户组不存在'); } if (!Security::checkToken($id)) { return Redirect::action('system/group')->with('error', 'token is invalid'); } $validator = Validator::make($this->request->request->all()); $validator->addRule('group_name', 'required', array('required' => '用户组必须填写')); if (!$validator->validate()) { foreach ($validator->errors() as $value) { $this->session->addFlash('error', $value); } return Redirect::action('system/group/edit', $id); } $group_name = $this->request->get('group_name'); $description = $this->request->get('description'); $this->db()->update('usergroups', array('group_name' => $group_name, 'description' => $description), array('group_id' => $id)); if ($this->db()->rowCount()) { return Redirect::action('system/group')->with('success', '用户组修改成功'); } else { return Redirect::action('system/group')->with('error', '用户组修改失败'); } }
public function save(Session $session) { $validator = Validator::make($this->request->request->all()); $validator->addRule('email', 'required|email', array('required' => '用户名必须填写', 'email' => '必须填写合法的Email')); $validator->addRule('password', 'required|len[6,16]', '密码', array('required' => '密码必须填写', 'len' => '密码格式不正确')); if (!$validator->validate()) { foreach ($validator->errors() as $value) { $session->addFlash('error', $value); } return Redirect::action('system/login'); } $email = $this->request->get('email'); $password = $this->request->get('password'); $user = \App\User::findByEmail($email); if ($user != NULL && \App\Foundation\Security::checkPassword($password, $user->password)) { $session->set('_h1cms_user_id', $user->id); $session->set('_h1cms_user_email', $email); return Redirect::action('system/dashboard')->with('success', '登录成功'); } else { return Redirect::action('system/login')->with('error', '登录失败'); } }
public function update($id) { if (!$id) { return Redirect::action('system/user')->with('error', '用户不存在'); } if (!Security::checkToken($id, true)) { return Redirect::action('system/user')->with('error', 'token is invalid'); } $validator = Validator::make($this->request->request->all()); $validator->addRule('group_id', 'required', array('required' => '必须选择用户组')); $validator->addRule('email', 'required|email', array('required' => '用户名必须填写', 'email' => '请输入正确的Email')); $validator->addRule('password', 'same_as[repassword]|len[6,16]', array('len' => '密码长度必须在6-16个字符', 'same_as' => '两次输入的密码不同')); $user = \App\User::find($id); if ($user == NULL) { return Redirect::action('system/user')->with('error', '用户不存在'); } if ($this->request->get('email') != $user->email && \App\User::findByEmail($this->request->get('email'))) { $validator->addError('email', '用户名已经存在'); } else { $user->email = $this->request->get('email'); } if (!$validator->validate()) { foreach ($validator->errors() as $value) { $this->session->addFlash('error', $value); } return Redirect::action('system/user/edit', $id); } if ($this->request->get('password')) { $user->password = Security::password($this->request->get('password')); } $user->group_id = $this->request->get('group_id'); $user->fullname = $this->request->get('fullname'); $user->description = $this->request->get('description'); $user->save(); return Redirect::action('system/user')->with('success', '用户' . $user->email . '修改成功'); }