/** * Метод-экшен по умолчанию * */ public function anyDefault() { $confirm = $this->input->post('confirm'); $form = $this->input->post('form'); $errors = []; $user = auth()->getAuthUser(); if (!empty($confirm) && $confirm == 'ok') { $validator = new \Wasp\Validator($form, $this->validation); if (!$validator->checkAll()) { $errors = $validator->getMessages(); } else { $profile = $user->profile; foreach ($profile->toArray() as $key => $val) { if (array_key_isset($key, $form)) { $profile->{$key} = $form[$key]; } } $profile->save(); redirect(['controller' => 'profile', 'method' => 'default', 'id' => $id]); } } $this->layout->useThemeCss('datepicker.css')->useThemeJs('bootstrap-datepicker.js', false); return $this->ui->assign('errors', $errors)->assign('user', $user)->assign('groups', Group::get())->fetch('profile/index.tpl'); }
public function anyAdd() { $confirm = $this->input->post('confirm'); $form = $this->input->post('form'); $errors = []; if (!empty($confirm) && $confirm == 'ok') { $validator = new \Wasp\Validator($form, $this->validation); if (!$validator->checkAll()) { $errors = $validator->getMessages(); } $check_user = $this->users->getByEmail($form['email']); $user_data = []; if (!empty($check_user->id)) { if (!isset($errors['email']) || !is_array($errors['email'])) { $errors['email'] = []; } $errors['email'][] = 'Такой пользователь уже есть'; } if (!is_alphanum($form['passwd1']) || !is_alphanum($form['passwd2']) || wasp_strlen($form['passwd1']) > 16 || wasp_strlen($form['passwd1']) < 6 || wasp_strlen($form['passwd2']) > 16 || wasp_strlen($form['passwd2']) < 6 || $form['passwd1'] != $form['passwd2']) { if (!isset($errors['passwd1']) || !is_array($errors['passwd1'])) { $errors['passwd1'] = []; } $errors['passwd1'][] = 'Неверное указан пароль'; } if (array_count($errors) == 0) { $current_user = $this->auth->getAuthUser(); $group_level = $this->users->getGroupLevel($form['group_id']); $passwd = password_crypt($form['passwd1']); $user_data['email'] = $form['email']; $user_data['password'] = $passwd; if ($this->users->groupIdExists($form['group_id']) && ($group_level < $current_user->group->level || $this->auth->isRoot())) { $user_data['group_id'] = intval($form['group_id']); $user_data['blocked'] = intval($form['blocked']); } if ($this->auth->isAdmin()) { foreach ($form as $key => $val) { if (!array_key_isset($key, $user_data)) { $user_data[$key] = $val; } } } $id = $this->users->create($user_data); redirect(['controller' => 'users', 'method' => 'edit', 'id' => $id, 'message' => 'Пользователь успешно добавлен в систему.']); } } $this->layout->useThemeCss('datepicker.css')->useThemeJs('bootstrap-datepicker.js', false); return $this->ui->assign('errors', $errors)->assign('form', $form)->assign('groups', $this->users->getGroups())->fetch('users/add'); }