コード例 #1
0
 public function resetAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user[user_id]')) {
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
     }
     $done = $request->issetQuery('done');
     if ($done) {
         $this->forward('password', 'done');
     }
     if ($request->isPost()) {
         $validate = new Helper_Validate();
         $validate->_set_rules($request->getPost('email'), $this->translate('E-mail'), 'not_empty;min_length[5];max_length[100];email');
         if ($validate->_valid_form()) {
             $result = Model_Users::forgotPassword($request->getPost('email'));
             if ($result) {
                 if ($result['status']) {
                     $new_password = Model_Users::generatePassword(8);
                     $key_forgot = md5($result['user_id'] . md5($new_password));
                     $add_new_pass = Model_Users::edit($result['user_id'], array('new_password' => $new_password, 'new_password_key' => $key_forgot));
                     if ($add_new_pass) {
                         $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp');
                         $mail = new JO_Mail();
                         if ($is_mail_smtp) {
                             $mail->setSMTPParams(JO_Registry::forceGet('config_mail_smtp_host'), JO_Registry::forceGet('config_mail_smtp_port'), JO_Registry::forceGet('config_mail_smtp_user'), JO_Registry::forceGet('config_mail_smtp_password'));
                         }
                         $this->view->new_password = $new_password;
                         $this->view->user_info = $result;
                         $this->view->forgot_password_href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=login&user_id=' . $result['user_id'] . '&key=' . $key_forgot);
                         $this->view->header_title = JO_Registry::get('site_name');
                         $this->view->base_href = WM_Router::create($request->getBaseUrl());
                         $mail->setFrom(JO_Registry::get('noreply_mail'));
                         $mail->setReturnPath(JO_Registry::get('noreply_mail'));
                         $mail->setSubject($this->translate('Request for forgotten password') . ' ' . JO_Registry::get('site_name'));
                         $mail->setHTML($this->view->render('send_forgot_password_request', 'mail'));
                         $result_send = (int) $mail->send(array($result['email']), $is_mail_smtp ? 'smtp' : 'mail');
                         if ($result_send) {
                             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=password&action=reset&done='));
                         } else {
                             $this->view->error = $this->translate('There was an error. Please try again later!');
                         }
                     } else {
                         $this->view->error = $this->translate('There was a problem with the record. Please try again!');
                     }
                 } else {
                     $this->view->error = $this->translate('This profile is not active.');
                 }
             } else {
                 $this->view->error = $this->translate('E-mail address was not found!');
             }
         } else {
             $this->view->error = $validate->_get_error_messages();
         }
     }
     $this->view->form_action = WM_Router::create($request->getBaseUrl() . '?controller=password&action=reset');
     $this->view->children = array('header_part' => 'layout/header_part', 'footer_part' => 'layout/footer_part');
 }
コード例 #2
0
ファイル: UsersController.php プロジェクト: noikiy/PD
 public function reset_passwordAction()
 {
     $request = $this->getRequest();
     if (JO_Session::get('user_id')) {
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=edit'));
     }
     $this->view->usersCount = Model_Users::countUsers();
     $this->view->itemsCount = Model_Items::countItems();
     $this->getLayout()->meta_title = $this->translate('Reset password');
     $this->getLayout()->meta_description = $this->translate('Reset password');
     if (JO_Session::get('msg_success')) {
         $this->view->msg_success = JO_Session::get('msg_success');
         JO_Session::clear('msg_success');
     } elseif (JO_Session::get('msg_error')) {
         $this->view->msg_error = JO_Session::get('msg_error');
         JO_Session::clear('msg_error');
     } elseif (JO_Session::get('error')) {
         $this->view->error = JO_Session::get('error');
         JO_Session::clear('error');
     }
     if ($request->isPost() && $request->getPost('send')) {
         $this->view->username = trim($request->getPost('username'));
         $this->view->email = trim($request->getPost('email'));
         $this->view->error = array();
         if (empty($this->view->username)) {
             $this->view->error['username'] = $this->translate('You must type your username');
         } elseif (!preg_match('/^[a-zA-Z0-9_]+$/i', $this->view->username)) {
             $this->view->error['username'] = $this->translate('The username you have entered is not valid');
         }
         if (empty($this->view->email)) {
             $this->view->error['email'] = $this->translate('You must type your email');
         } elseif (!Model_Users::ValidMail($this->view->email)) {
             $this->view->error['email'] = $this->translate('You must type valid email');
         }
         if (empty($this->view->error)) {
             $user = Model_Users::getByEmail($this->view->email);
             if ($user) {
                 $alphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7', '8', '9');
                 $password = '';
                 for ($i = 0; $i < 7; $i++) {
                     $random_number = rand(0, count($alphabet) - 1);
                     $password .= $alphabet[$random_number];
                 }
                 Model_Users::editPass($user['user_id'], $password);
                 $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp');
                 $mail = new JO_Mail();
                 if ($is_mail_smtp) {
                     $mail->setSMTPParams(JO_Registry::forceGet('config_mail_smtp_host'), JO_Registry::forceGet('config_mail_smtp_port'), JO_Registry::forceGet('config_mail_smtp_user'), JO_Registry::forceGet('config_mail_smtp_password'));
                 }
                 $domain = $request->getDomain();
                 $mail->setFrom('noreply@' . $domain);
                 $mail->setReturnPath('noreply@' . $domain);
                 $mail->setSubject($this->translate('Reset password') . ' ' . JO_Registry::get('store_meta_title'));
                 $html = 'Your new password for ' . $user['username'] . ' is ' . $password;
                 $mail->setHTML($html);
                 $result = (int) $mail->send(array($request->getPost('email')), $is_mail_smtp ? 'smtp' : 'mail');
                 JO_Session::set('msg_success', $this->translate('Your new password was send to your email'));
             } else {
                 JO_Session::set('msg_error', $this->translate('No match found between your username and the email you have input '));
             }
         } else {
             JO_Session::set('error', $this->view->error);
         }
         $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=reset_password'));
     }
     $this->view->lost_username = WM_Router::create($request->getBaseUrl() . '?controller=users&action=lost_username');
     $this->view->new_account = WM_Router::create($request->getBaseUrl() . '?controller=users&action=registration');
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }
コード例 #3
0
ファイル: ItemsController.php プロジェクト: noikiy/PD
    public function doeditAction()
    {
        $this->noViewRenderer(true);
        $request = $this->getRequest();
        if ($request->issetPost('item_id')) {
            $itemID = (int) $request->getPost('item_id');
            $item = Model_Items::get($itemID);
            $error = array();
            if (!$item) {
                $error['msg_error'] = $this->translate('Item not found');
            }
            if (trim($request->getPost('name')) == '') {
                $error['ename'] = $this->translate('You have to input a name');
            }
            if (trim($request->getPost('description')) == '') {
                $error['edescription'] = $this->translate('You have to input a description');
            }
            $base_upload_folder = realpath(BASE_PATH . '/uploads');
            $temp_upload_folder = $base_upload_folder . '/temporary/' . JO_Date::getInstance(JO_Session::get('register_datetime'), 'yy/mm', true) . '/';
            $fileTypes = JO_Registry::get('upload_theme');
            if (isset($fileTypes['archives'])) {
                $ew = explode(',', $fileTypes['archives']);
                foreach ($ew as $ar) {
                    $allow_archives[] = '.' . strtolower($ar);
                }
            }
            $allow_images = array();
            if (isset($fileTypes['images'])) {
                $ew = explode(',', $fileTypes['images']);
                foreach ($ew as $ar) {
                    $allow_images[] = '.' . strtolower($ar);
                }
            }
            if (trim($request->getPost('theme_preview')) != '') {
                if (!in_array(strtolower(strrchr($request->getPost('theme_preview'), '.')), $allow_images)) {
                    $error['etheme_preview'] = $this->translate('Theme preview should be ' . implode(', ', $allow_images) . ' file');
                }
            }
            if (trim($request->getPost('theme_preview_zip')) == '') {
                $error['etheme_preview_zip'] = $this->translate('You have to choose a file');
            } else {
                if (!in_array(strtolower(strrchr($request->getPost('theme_preview_zip'), '.')), $allow_archives)) {
                    $error['etheme_preview_zip'] = $this->translate('Preview archive file should be ' . implode(', ', $allow_archives) . ' file');
                } elseif (!file_exists($temp_upload_folder . $request->getPost('theme_preview_zip'))) {
                    $error['etheme_preview_zip'] = $this->translate('Preview archive file should be ' . implode(', ', $allow_archives) . ' file');
                }
            }
            if (trim($request->getPost('main_file')) != '') {
                if (!in_array(strtolower(strrchr($request->getPost('main_file'), '.')), $allow_archives)) {
                    $error['emain_file'] = $this->translate('Main file should be ' . implode(', ', $allow_archives) . ' file');
                } elseif (!file_exists($temp_upload_folder . $request->getPost('main_file'))) {
                    $error['emain_file'] = $this->translate('Main file should be ' . implode(', ', $allow_archives) . ' file');
                }
            }
            if (!$request->getPost('category')) {
                $error['ecategory'] = $this->translate('You have to choose a category');
            } elseif (!is_array($request->getPost('category'))) {
                $error['ecategory'] = $this->translate('You have to choose a category');
            } elseif (!count($request->getPost('category'))) {
                $error['ecategory'] = $this->translate('You have to choose a category');
            }
            $attributes = Model_Attributes::getAllWithCategories("attributes_categories.categories LIKE '%," . (int) $request->getPost('category_id') . ",%'");
            if (is_array($attributes)) {
                $attributesError = false;
                $cnt = count($attributes);
                for ($i = 0; $i < $cnt; $i++) {
                    if (!$request->getPost('attributes[' . $attributes[$i]['head_id'] . ']') && $attributes[$i]['required']) {
                        $attributesError = true;
                        break;
                    }
                }
                if ($attributesError) {
                    $error['eattributes'] = $this->translate('You have to mark all the attributes');
                }
            }
            if (trim($request->getPost('tags')) == '') {
                $error['etags'] = $this->translate('You have to fill the field with tags');
            }
            if (!$request->getPost('source_license')) {
                $error['esource_license'] = $this->translate('You have to confirm that you have rights to use all the materials in your template');
            }
            if ($request->getPost('demo_url') && filter_var($request->getPost('demo_url'), FILTER_VALIDATE_URL) === false) {
                $error['edemo_url'] = $this->translate('Please enter valid url for demo preview');
            }
            if (!$request->getPost('suggested_price') || !preg_match('#^\\d+(?:\\.\\d{1,})?$#', $request->getPost('suggested_price'))) {
                $error['esuggested_price'] = $this->translate('Suggested price should be in the format: number(.number)');
            }
            if (count($error) > 0) {
                $error['msg_error'] = $this->translate('Upload error');
                JO_Session::set('msg_error', $error);
                JO_Session::set('data', $request->getParams());
                $this->redirect($request->getServer('HTTP_REFERER'));
            } else {
                $free_request = $request->getPost('free_request') ? 'true' : 'false';
                if (!$request->getPost('free_request')) {
                    $free_request = 'false';
                } else {
                    $free_request = 'true';
                }
                Model_Items::updateItem(array('id' => $itemID, 'name' => $request->getPost('name'), 'description' => $request->getPost('description'), 'demo_url' => $request->getPost('demo_url'), 'free_request' => $free_request, 'reviewer_comment' => $request->getPost('reviewer_comment'), 'suggested_price' => $request->getPost('suggested_price'), 'default_module' => $item['module']));
                Model_Attributes::deleteItem($itemID);
                if ($request->getPost('attributes')) {
                    Model_Attributes::addToItem($itemID, $request->getPost('attributes'));
                }
                if ($request->getPost('theme_preview') != '' || $request->getPost('theme_preview_zip') != '' || $request->getPost('main_file') != '') {
                    $upload_folder = $base_upload_folder . '/items/' . JO_Date::getInstance($item['datetime'], 'yy/mm/', true)->toString() . $item['id'] . '/';
                    if (!file_exists($upload_folder . 'temp/') || !is_dir($upload_folder . 'temp/')) {
                        mkdir($upload_folder . 'temp/', 0777, true);
                    }
                    if (trim($request->getPost('theme_preview')) != '') {
                        $theme_preview = $request->getPost('theme_preview');
                        copy($temp_upload_folder . $theme_preview, $upload_folder . 'temp/' . $theme_preview);
                    }
                    if (trim($request->getPost('theme_preview_zip')) != '') {
                        $zip_file = $request->getPost('theme_preview_zip');
                        copy($temp_upload_folder . $zip_file, $upload_folder . 'temp/' . $zip_file);
                    }
                    if (trim($request->getPost('main_file')) != '') {
                        $main_file = $request->getPost('main_file');
                        copy($temp_upload_folder . $main_file, $upload_folder . 'temp/' . $main_file);
                    }
                    $uploaded_files = JO_Session::get('uploaded_files');
                    $upload_file = array();
                    if (isset($theme_preview)) {
                        $found = false;
                        foreach ($uploaded_files as $k => $uf) {
                            foreach ($uf as $f) {
                                if ($f['filename'] == $theme_preview) {
                                    $upload_file = $f;
                                    break;
                                }
                            }
                        }
                        if ($upload_file && file_exists($temp_upload_folder . $upload_file['filename'])) {
                            $preview = $upload_folder . 'temp/' . $upload_file['filename'];
                            copy($temp_upload_folder . $upload_file['filename'], $preview);
                            $found = true;
                        }
                    } else {
                        $found = true;
                    }
                    $zip = new ZipArchive();
                    if (isset($zip_file)) {
                        $res = $zip->open($upload_folder . 'temp/' . $zip_file);
                        if ($res == true) {
                            if (is_dir($upload_folder . 'temp/preview/')) {
                                Model_Items::unlink($upload_folder . 'temp/preview/', false);
                            } else {
                                mkdir($upload_folder . 'temp/preview/', 0777, true);
                            }
                            for ($i = 0; $i < $zip->numFiles; $i++) {
                                $file = $zip->getNameIndex($i);
                                if (stripos($file, '_MACOSX') !== false) {
                                    continue;
                                }
                                if (in_array(strtolower(strrchr($file, '.')), $allow_images)) {
                                    $fileinfo = pathinfo($file);
                                    $prw_filename = $this->rename_if_exists($upload_folder . 'temp/preview/', $fileinfo['basename']);
                                    copy("zip://" . $upload_folder . 'temp/' . $zip_file . "#" . $file, $upload_folder . 'temp/preview/' . $prw_filename);
                                    if (!$found && isset($theme_preview) && !empty($fileinfo['basename']) && $fileinfo['basename'] == $upload_file['name']) {
                                        $found = true;
                                        $filename = $this->rename_if_exists($upload_folder . 'temp/', $fileinfo['basename']);
                                        if (copy("zip://" . $upload_folder . 'temp/' . $zip_file . "#" . $file, $upload_folder . 'temp/' . $filename)) {
                                            $preview = $filename;
                                        }
                                    }
                                }
                            }
                            $zip->close();
                        }
                    }
                    if (isset($main_file)) {
                        $res = $zip->open($upload_folder . 'temp/' . $main_file);
                        for ($i = 0; $i < $zip->numFiles; $i++) {
                            $file = $zip->getNameIndex($i);
                            if (stripos($file, '_MACOSX') !== false) {
                                continue;
                            }
                            if (in_array(strtolower(strrchr($file, '.')), $allow_images)) {
                                $fileinfo = pathinfo($file);
                                if (!$found && !empty($fileinfo['basename']) && $fileinfo['basename'] == $upload_file['name']) {
                                    $filename = $this->rename_if_exists($upload_folder, $fileinfo['basename']);
                                    if (copy("zip://" . $upload_folder . 'temp/' . $main_file . "#" . $file, $upload_folder . 'temp/' . $filename)) {
                                        $preview = $filename;
                                    }
                                }
                            }
                        }
                        $zip->close();
                    }
                    $item_folder = str_replace($base_upload_folder, '', $upload_folder);
                    $uploaded_arhives = JO_Session::get('uploaded_arhives');
                    $upload_zip = array();
                    foreach ($uploaded_arhives[0] as $f) {
                        if ($f['filename'] == $request->getPost('main_file')) {
                            $upload_zip = $f;
                            break;
                        }
                    }
                    $preview = isset($preview) ? str_replace($base_upload_folder, '', $preview) : '';
                    if ($preview && strpos($preview, 'temp/') === false) {
                        $preview = $item_folder . 'temp/' . $preview;
                    }
                    Model_Items::updateTempPics(array('id' => $itemID, 'thumbnail' => $preview, 'theme_preview_thumbnail' => $preview, 'theme_preview' => isset($zip_file) ? $item_folder . 'temp/' . $zip_file : '', 'main_file' => isset($main_file) ? $item_folder . 'temp/' . $main_file : '', 'main_file_name' => isset($main_file) ? $item_folder . 'temp/' . $upload_zip['name'] : ''));
                }
                Model_Categories::deleteTempToItem($itemID);
                Model_Categories::updateToItem($itemID, $request->getPost('category'), $request->getPost('category_id'));
                Model_Attributes::deleteTempToItem($itemID);
                if ($request->getPost('attributes')) {
                    Model_Attributes::updateToItem($itemID, $request->getPost('attributes'));
                }
                Model_Tags::deleteTempToItem($itemID);
                $arr = explode(',', $request->getPost('tags'));
                Model_Tags::updateToItem($itemID, $arr);
                if ($uploaded_files) {
                    foreach ($uploaded_files[0] as $f) {
                        if (file_exists($temp_upload_folder . $f['filename'])) {
                            unlink($temp_upload_folder . $f['filename']);
                        }
                    }
                }
                JO_Session::clear('uploaded_files');
                if ($uploaded_arhives) {
                    foreach ($uploaded_arhives[0] as $f) {
                        if (file_exists($temp_upload_folder . $f['filename'])) {
                            unlink($temp_upload_folder . $f['filename']);
                        }
                    }
                }
                JO_Session::clear('uploaded_arhives');
                $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp');
                $not_template = Model_Notification::getNotification('item_added');
                $mail = new JO_Mail();
                if ($is_mail_smtp) {
                    $mail->setSMTPParams(JO_Registry::forceGet('config_mail_smtp_host'), JO_Registry::forceGet('config_mail_smtp_port'), JO_Registry::forceGet('config_mail_smtp_user'), JO_Registry::forceGet('config_mail_smtp_password'));
                }
                $domain = $request->getDomain();
                $mail->setFrom('no-reply@' . $domain);
                $mail->setReturnPath('no-reply@' . $domain);
                $mail->setSubject($this->translate('Updated item for approval') . ' ' . JO_Registry::get('store_meta_title'));
                if ($not_template) {
                    $title = $not_template['title'];
                    $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                    $html = str_replace('{URL}', $request->getBaseUrl() . '/admin/queueupdateditems/edit/?m=' . $item['module'] . '&id=' . $itemID, $html);
                } else {
                    $html = nl2br('Hello,

					There is a updated item waiting for approval. You can see it on ' . $request->getBaseUrl() . '/admin/queueupdateditems/edit/?m=' . $item['module'] . '&id=' . $itemID . '');
                }
                $mail->setHTML($html);
                $result = (int) $mail->send(array(JO_Registry::get('report_mail')), $is_mail_smtp ? 'smtp' : 'mail');
                JO_Session::set('msg_success', $this->translate('Your item has been updated successfully!'));
                $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=dashboard'));
            }
        }
        $this->redirect($request->getServer('HTTP_REFERER'));
    }