public function actionEdit($id) { $model = BlogCategory::findByPk($id); $model->reloadTranslations(); if (isset($_POST['BlogCategory']) && $model->setAttributes($_POST['BlogCategory'])->save()) { $model->saveTranslations(); Messages::get()->success(Translator::get()->t('Category saved!')); $this->goToAction('index'); } $this->assign('model', $model); }
public function actionCreate() { $model = $this->modelClass; $model = new $model(); if (isset($_POST[$this->getModelShortName()])) { $model->setAttributes($_POST[$this->getModelShortName()]); if ($model->save()) { Messages::get()->success($this->messages['created']); $this->goToAction($this->afterSaveRedirectTo, 'index' == $this->afterSaveRedirectTo ? [] : ['id' => $model->id]); } } $this->assign('model', $model); }
public function actionEdit($id) { $article = BlogPost::findByPk($id); $article->edited_by = WebApp::get()->user()->id; $article->edit_time = date('Y-m-d H:i:s'); $article->edit_number += 1; $article->beforeEdit(); if (isset($_POST['BlogPost']) && $article->setAttributes(['anonimous' => 0]) && $article->setAttributes($_POST['BlogPost'])->save()) { $article->afterAdminEdit(); $this->goToPage('home', 'read', ['id' => $article->id, 'title' => $article->url]); } $this->assign('model', $article); Messages::get()->info("Add " . BlogConfig::get()->introductionSeparator . " to set the limit for text displayed on the articles list!"); }
public function actionDelete() { $models = UserGroup::findAllByPk($_POST['UserGroup']); $no = 0; foreach ($models as $model) { $no += (int) $model->delete(); } if ($no !== 1) { Messages::get()->success("{$no} groups deleted!"); } else { Messages::get()->success("Group deleted!"); } $this->getRequest()->goBack(); }
public function actionRead($id) { $this->assign('article', $art = BlogPost::findByPk($id)); if ($art->allow_comments) { $model = new BlogComment(); $model->post_id = $id; if (isset($_POST['BlogComment']) && $model->setAttributes($_POST['BlogComment'])->save()) { Messages::get()->success("Comment saved!"); $this->goBack(); } $this->assign('model', $model); $this->assign('comments', BlogComment::findAllByAttributes(['post_id' => $id, 'status' => BlogComment::STATUS_OK])); } }
public function actionMerge() { $models = User::findAllByPk($_POST['User']); if (!count($models)) { $this->getRequest()->goBack(); } $mergeId = $models[0]->id; foreach ($models as $model) { $model->joinuser_id = $mergeId; $model->save(false); $model->logAction(UserHistory::ACTION_MERGED, 'List of IDs: ' . implode(", ", $_POST['User'])); } Messages::get()->success("Accounts merged!"); $this->getRequest()->goBack(); }
/** * Upload image * @param $for * @param $name * @param $id * @return bool|string */ public function uploadImage($for, $name, $id) { $folder = $this->getUploadFolder() . $for . DIRECTORY_SEPARATOR . $id . '-'; $finalName = "{$id}-"; if (isset($_FILES[$name]) && file_exists($_FILES[$name]['tmp_name'])) { if (FileHelper::get()->isImage($_FILES[$name]['tmp_name'])) { $finalName .= $fname = trim(substr($_FILES[$name]['name'], -100)); if (FileHelper::get()->upload($name, $folder . $fname)) { return $finalName; } return false; } else { Messages::get()->error("Selected file isn't a image!"); return false; } } return false; }
public function beforeDelete() { if (!UserAccess::get()->isCategoryAdmin($this->category_id, $this->category->section_id)) { Messages::get()->error("You can't delete this category!"); return false; } return parent::beforeDelete(); }
echo \mpf\WebApp::get()->title; ?> </title> <?php echo \mpf\web\helpers\Html::get()->cssFile(\mpf\WebApp::get()->request()->getWebRoot() . 'main/style.css'); ?> <?php echo \mpf\web\helpers\Html::get()->mpfScriptFile('jquery.js'); ?> <?php echo \mpf\web\helpers\Html::get()->scriptFile(\mpf\WebApp::get()->request()->getWebRoot() . 'main/main.js'); ?> </head> <body> <div id="wrapper"> <div id="site"> <div id="header"> <h1><?php echo \mpf\web\helpers\Html::get()->link(\mpf\WebApp::get()->request()->getLinkRoot(), \mpf\WebApp::get()->title); ?> </h1> <?php \mpf\widgets\menu\Menu::get(['items' => [['url' => [], 'label' => 'Home'], ['url' => ['user', 'login'], 'label' => 'Login', 'visible' => \mpf\WebApp::get()->user()->isGuest()], ['url' => ['user', 'register'], 'label' => 'Register', 'visible' => \mpf\WebApp::get()->user()->isGuest()], ['url' => ['user', 'forgotpassword'], 'label' => 'Forgot Password', 'visible' => \mpf\WebApp::get()->user()->isGuest()], ['class' => 'Label', 'label' => \mpf\WebApp::get()->user()->isGuest() ? 'Welcome Guest!' : 'Welcome ' . \mpf\WebApp::get()->user()->name, 'htmlOptions' => ['style' => 'float:right;'], 'items' => [['url' => ['user', 'profile'], 'label' => 'My Profile'], ['url' => ['user', 'edit'], 'label' => 'Edit My Profile'], ['url' => ['user', 'email'], 'label' => 'Change Email'], ['url' => ['user', 'password'], 'label' => 'Change Password'], ['url' => ['home', 'index', 'admin'], 'label' => 'Administration'], ['url' => ['user', 'logout'], 'label' => 'Logout']]], ['label' => 'Google Login', 'url' => $url = \mpf\WebApp::get()->user()->getGoogleClient() ? \mpf\WebApp::get()->user()->getGoogleClient()->createAuthUrl() : null, 'htmlOptions' => ['style' => 'float:right;'], 'linkHtmlOptions' => ['class' => 'ext-login-button google-login-button'], 'visible' => \mpf\WebApp::get()->user()->isGuest() && trim($url)], ['label' => 'Facebook Login', 'url' => $url = \mpf\WebApp::get()->user()->getFacebookLoginURL(), 'visible' => \mpf\WebApp::get()->user()->isGuest() && trim($url), 'htmlOptions' => ['style' => 'float:right;'], 'linkHtmlOptions' => ['class' => 'ext-login-button facebook-login-button']]]])->display(); ?> </div> <div id="content"> <?php echo \app\components\htmltools\Messages::get()->display(); ?>
public function actionEditConfig($id = null) { if (!$id) { $id = isset($_POST['save']) ? array_keys($_POST['GlobalConfig']) : $_POST['GlobalConfig']; } $ms = GlobalConfig::findAllByPk($id); $models = array(); foreach ($ms as $model) { $models[$model->id] = $model; } if (isset($_POST['save'])) { $ok = true; foreach ($_POST['GlobalConfig'] as $k => $details) { $models[$k]->setAttributes($details); $models[$k]->lastupdate_date = date('Y-m-d H:i:s'); $models[$k]->lastupdate_user = WebApp::get()->user()->id; $ok = $ok && $models[$k]->save(); } if ($ok) { Messages::get()->info('Changes saved!'); $this->getRequest()->goToPage('admin', 'config'); } } $this->assign('models', $models); }
/** * @param User $user * @param string $source * @param boolean $rememberMe * @return boolean */ protected function checkUserLogin(User $user, $source, $rememberMe) { if ($user->status == User::STATUS_NEW) { if (is_null($user->lastconfirmationmail_date) || $user->lastconfirmationmail_date < date('Y-m-d H:i:s', strtotime('-5 minutes'))) { // if confirmation email was older than 5 minutes then allow it to resend it User::$allowConfirmationEmailResend = true; if (isset($_POST['resend'])) { $user->resendConfirmationEmail(); } } if (!isset($_POST['resend'])) { Messages::get()->error('Email address was not yet confirmed! Check your emails and access received link to activate the account!'); } return false; } if ($user->status == User::STATUS_BLOCKED) { Messages::get()->error('This account has been banned! Please contact an admin if you think this is a mistake!'); return false; } if ($user->status == User::STATUS_DELETED) { Messages::get()->error('This account has been recently deleted! If you want to recover it please contact an admin. An account is permanently removed ' . User::DELETE_ACCOUNT_AFTER_X_DAYS . ' days after it was deleted!'); return false; } $this->connected = true; $this->setState('id', $user->id); $this->setState('name', $user->name); $this->setState('email', $user->email); $this->setState('icon', $user->icon ?: 'default.png'); $this->setState('status', $user->status); $this->setState('title', $user->title ? $user->title->title : '- no title -'); if ($user->joinuser_id) { $all = User::findAllByAttributes(['joinuser_id' => $user->joinuser_id]); $this->setState('mergedIDs', ArrayHelper::get()->transform($all, 'id')); } $this->setRights($groups = $user->getGroupsList()); $this->debug("Saved groups: " . implode(", ", $groups)); $user->last_login = date('Y-m-d H:i:s'); $user->last_login_source = $source; $user->save(); if ($rememberMe) { Cookie::get()->set(App::get()->shortName . $this->cookieKey, $user->email, $this->cookieTimeout); } if (!trim($user->name)) { // fill last details if they were not already saved $this->debug('need auto register'); WebApp::get()->request()->setController('user'); WebApp::get()->request()->setAction('registerauto'); } return true; }
/** * Set a different default group for current section. It will check if group exists and if it's assigned to this * section but it will not check if user has access to this section as this method will also be used by automated * processes when a new section is generated. * @param int $groupId * @param string $for * @return bool */ public function setDefaultGroup($groupId, $for = 'visitor') { $group = ForumUserGroup::findByPk($groupId); if (!$group) { Messages::get()->error("Group not found!"); return false; } if ($group->section_id != $this->id) { Messages::get()->error("Group is assigned to a different section of the forum!"); return false; } if ('visitor' == $for) { $this->default_visitors_group_id = $groupId; } else { $this->default_members_group_id = $groupId; } return $this->save(); }
public function actionDelete() { if (isset($_POST['ForumUserGroup'])) { $models = ForumUserGroup::findAllByPk($_POST['ForumUserGroup']); foreach ($models as $model) { $model->delete(); } Messages::get()->success("Deleted!"); $this->goBack(); } if (isset($_POST['ForumCategory'])) { $models = ForumCategory::findAllByPk($_POST['ForumCategory']); foreach ($models as $model) { $model->delete(); } Messages::get()->success("Deleted!"); $this->goBack(); } if (isset($_POST['ForumSubcategory'])) { $models = ForumSubcategory::findAllByPk($_POST['ForumSubcategory']); foreach ($models as $model) { $model->delete(); } Messages::get()->success("Deleted!"); $this->goBack(); } }
/** * Send email to change current email with a new address. * @return bool */ public function changeEmail() { $this->new_email = $this->newEmail; $this->lastconfirmationmail_date = date('Y-m-d H:i:s'); if ($this->save()) { if (!Emails::get()->sentToEmailChange($this)) { $this->new_email = null; $this->save(); Messages::get()->error('Error while sending email!'); return false; } $this->logAction(UserHistory::ACTION_EMAILCHANGED, "Old email: " . $this->email . "\nNew email: " . $this->new_email); return true; } return false; }
public function beforeSave() { if (is_a(App::get(), '\\mpf\\WebApp') && WebApp::get()->request()->getModule()) { if (!UserAccess::get()->isSectionAdmin($this->section_id)) { Messages::get()->error("You don't have access to edit this user group!"); return false; } } return parent::beforeSave(); }
/** * Reset password for user with the selected code. * @param string $code */ public function actionResetPassword($code) { $code = explode('_', $code, 2); $user = \app\models\User::findByPk($code[0]); if (!$user) { Messages::get()->error('Invalid code!'); $this->assign('error', true); return; } $this->assign('error', $user->resetPassword($code)); }