function editAction() { if (!User::admin()) { HTTP::redirect('backend/' . Route::controller() . '/login'); } $user = User::info(); if ($_POST) { $post = $_POST; if (strlen(Arr::get($post, 'password')) < $this->password_length or strlen(Arr::get($post, 'new_password')) < $this->password_length or strlen(Arr::get($post, 'confirm_password')) < $this->password_length or !User::factory()->check_password(Arr::get($post, 'password'), $user->password) or Arr::get($post, 'new_password') != Arr::get($post, 'confirm_password')) { Message::GetMessage(0, 'Вы что-то напутали с паролями!'); HTTP::redirect('backend/' . Route::controller() . '/edit'); } if (!strlen(trim(Arr::get($post, 'name')))) { Message::GetMessage(0, 'Имя не может быть пустым!'); HTTP::redirect('backend/' . Route::controller() . '/edit'); } if (!strlen(trim(Arr::get($post, 'login')))) { Message::GetMessage(0, 'Логин не может быть пустым!'); HTTP::redirect('backend/' . Route::controller() . '/edit'); } $count = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('users')->where('id', '!=', $user->id)->where('login', '=', Arr::get($post, 'login'))->count_all(); if ($count) { Message::GetMessage(0, 'Пользователь с таким логином уже существует!'); HTTP::redirect('backend/' . Route::controller() . '/edit'); } $data = array('name' => Arr::get($post, 'name'), 'login' => Arr::get($post, 'login'), 'password' => User::factory()->hash_password(Arr::get($post, 'new_password'))); Common::factory('users')->update($data, $user->id); Message::GetMessage(1, 'Вы успешно изменили данные!'); HTTP::redirect('backend/' . Route::controller() . '/edit'); } $this->_toolbar = Widgets::get('Toolbar/EditSaveOnly'); $this->_seo['h1'] = 'Мой профиль'; $this->_seo['title'] = 'Редактирование личных данных'; $this->setBreadcrumbs('Мой профиль', 'backend/' . Route::controller() . '/' . Route::action()); $this->_content = View::tpl(array('obj' => $user), 'Auth/Edit'); }
function sendAction() { $id = (int) Route::param('id'); $user = Model::getRow($id); if (!$user) { Message::GetMessage(0, 'Пользователь не существуют!'); HTTP::redirect('backend/admins/index'); } if ($user->deleted || $user->status == 0) { Message::GetMessage(1, 'Пользователь удален или заблокирован!'); HTTP::redirect('backend/admins/index'); } if (!filter_var($user->email, FILTER_VALIDATE_EMAIL)) { Message::GetMessage(1, 'E-Mail пользователя некорректен!'); HTTP::redirect('backend/admins/index'); } // Generate new password for user and save it to his account $password = User::factory()->generate_random_password(); User::factory()->update_password($user->id, $password); // Send E-Mail to user with instructions how recover password $mail = Common::factory('mail_templates')->getRow(5); if ($mail) { $from = array('{{site}}', '{{ip}}', '{{date}}', '{{password}}'); $to = array(Arr::get($_SERVER, 'HTTP_HOST'), System::getRealIP(), date('d.m.Y H:i'), $password); $subject = str_replace($from, $to, $mail->subject); $text = str_replace($from, $to, $mail->text); Email::send($subject, $text, $user->email); } Message::GetMessage(1, 'Новый пароль отправлен на E-Mail пользователя!'); HTTP::redirect('backend/admins/index'); }
/** * User registration * @param array $data - user data from POST */ public function registration($data = array()) { $data['hash'] = $this->hash_user($data['email'], $data['password']); $data['password'] = $this->hash_password($data['password']); return Common::factory($this->_tbl)->insert($data); }