Permalink
Browse files

Plugin updated for Wolf CMS 0.7.3 and added documentation for plugin …

…devs
  • Loading branch information...
1 parent ff17ccd commit 8656bdb3011d580b562d9dc94639c09a19c85580 @mvdkleijn committed Jan 24, 2011
Showing with 358 additions and 29 deletions.
  1. +70 −11 AccountController.php
  2. +14 −4 index.php
  3. +100 −0 models/AccountSetting.php
  4. +36 −0 views/actions.php
  5. +119 −5 views/documentation.php
  6. +7 −1 views/edit.php
  7. +11 −6 views/index.php
  8. +0 −1 views/password.php
  9. +1 −1 views/sidebar.php
View
@@ -31,17 +31,42 @@ function __construct() {
if (defined('CMS_BACKEND')) {
define('ACCOUNT_VIEWS', 'account/views');
$this->setLayout('backend');
+ $this->assignToLayout('sidebar', new View('../../plugins/account/views/sidebar'));
}
else {
define('ACCOUNT_VIEWS', '../../plugins/account/views');
- //$page = Page::findByUri(Plugin::getSetting('layout', 'account'));
- //$layout_id = $this->getLayoutId($page);
$settings = Plugin::getAllSettings('account');
$layout = Layout::findById($settings['layout']);
$this->setLayout($layout->name);
}
- $this->assignToLayout('sidebar', new View('../../plugins/account/views/sidebar'));
+
+ // Retrieve setting
+ $uri = Plugin::getSetting('uri', 'account');
+
+ // Add primary actions
+ if (AuthUser::isLoggedIn()) {
+ self::$actions[__('Change password')] = BASE_URL.$uri.'/password';
+ //self::$actions[__('Reset password')] = BASE_URL.'users/reset.html';
+ self::$actions[__('Edit account settings')] = BASE_URL.$uri.'/edit';
+ }
+
+ // Add plugin actions
+ foreach(Observer::getObserverList('account_list_actions') as $callback) {
+ self::$actions = array_merge(self::$actions, call_user_func_array($callback, array()));
+ }
+
+ // Add secondary actions
+ if (AuthUser::isLoggedIn()) {
+ //self::$actions[__('Logout')] = BASE_URL.'users/logout.html';
+ self::$actions[__('Logout')] = BASE_URL.$uri.'/logout/';
+ }
+
+ $this->assignToLayout('account_sidebar', new View('../../plugins/account/views/actions',
+ array('actions' => self::$actions,
+ 'settings' => Plugin::getAllSettings('account')
+ )
+ ));
}
private function getLayoutId($page) {
@@ -81,10 +106,12 @@ public function index() {
}
public function profile($username) {
+ /* @todo User this in later versions
// Get profile information from other plugins.
foreach(Observer::getObserverList('account_display_profile') as $callback) {
self::$profile = array_merge(self::$profile, call_user_func_array($callback, array()));
}
+ */
$this->display(ACCOUNT_VIEWS.'/profile', array('settings' => Plugin::getAllSettings('account'),
'user' => User::findOneFrom('User', 'username=?', array($username)),
@@ -119,15 +146,15 @@ public function password() {
exit();
}
- if ($user->password != sha1($data['old'].$user->salt)) {
+ if (!AuthUser::validatePassword($user, $data['old'])) {
$this->display(ACCOUNT_VIEWS.'/error', array('errors' => array('The old password you entered was incorrect.')));
}
if ($data['password'] != $data['confirm'] || strlen($data['password']) < 5) {
$this->display(ACCOUNT_VIEWS.'/error', array('errors' => array('Password and Confirm are not the same or too small!')));
}
- $user->password = sha1($data['password'].$user->salt);
+ $user->password = AuthUser::generateHashedPassword($data['password'], $user->salt);
if (!$user->save()) {
$this->display(ACCOUNT_VIEWS.'/error', array('errors' => array('Unable to update password!')));
}
@@ -149,8 +176,9 @@ public function edit() {
$profile['email'] = $user->email;
$this->display(ACCOUNT_VIEWS.'/edit', array('profile' => $profile,
- 'csrf_token' => SecureToken::generateToken(BASE_URL.'account/edit'),
- 'url' => BASE_URL.'account/edit'
+ 'settings' => AccountSetting::findByUserId(AuthUser::getId()),
+ 'csrf_token' => SecureToken::generateToken(BASE_URL.'account/edit'),
+ 'url' => BASE_URL.'account/edit'
));
}
@@ -168,20 +196,51 @@ public function edit() {
$this->display(ACCOUNT_VIEWS.'/error', array('errors' => array('No CSRF token found!')));
exit();
}
-
+
$errors = array();
+
+ foreach ($data as $name => $value) {
+ if (!AccountSetting::validAccountSetting($name, $value)) {
+ Flash::setNow('error', __('Account settings could not be saved! Invalid value entered for field ":name".', array(':name' => AccountSetting::accountSettingName($name))));
+ $this->index();
+ }
+ else {
+ $as = AccountSetting::find($user->id, $name);
+ if ($as) {
+ $as->value = $value;
+ $as->save();
+ }
+ }
+ }
if (strlen($profile['name']) < 3) {
$errors[] = __('Your username must be at least three characters.');
}
+ else {
+ // Store full name if valid
+ if (eregi('[^a-zA-Z0-9 \-\.@+_]', $profile['name'])) {
+ Flash::setNow('error', __('Account settings could not be saved! Invalid value entered for field ":name".', array(':name' => 'name')));
+ $this->index();
+ }
+ else {
+ $user->name = $profile['name'];
+ }
+ }
if (count($errors) > 0) {
$this->display(ACCOUNT_VIEWS.'/error', array('errors' => $errors));
}
- // Set values
- $user->name = $profile['name'];
- $user->email = $profile['email'];
+ // Store email address if valid
+ // preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email)
+
+ if (eregi('[^a-zA-Z0-9 \-\.@+_]', $profile['email'])) {
+ Flash::setNow('error', __('Account settings could not be saved! Invalid value entered for field ":name".', array(':name' => 'email')));
+ $this->index();
+ }
+ else {
+ $user->email = $profile['email'];
+ }
if (!$user->save()) {
$this->display(ACCOUNT_VIEWS.'/error', array('errors' => array('Unable to update profile!')));
View
@@ -26,17 +26,20 @@
'id' => 'account',
'title' => 'Account',
'description' => 'Adds a My Account page to your site.',
- 'version' => '0.0.7',
+ 'version' => '0.5.0',
'license' => 'GPLv3',
'author' => 'Martijn van der Kleijn',
'website' => 'http://www.vanderkleijn.net/wolf-cms.html',
'update_url' => 'http://www.vanderkleijn.net/plugins.xml',
'type' => 'both',
- //'require_wolf_version' => '0.7.0'
+ 'require_wolf_version' => '0.7.3'
));
// Setup the controller.
-Plugin::addController('account', 'Account', 'administrator', false);
+Plugin::addController('account', 'Account', 'admin_edit', false);
+
+// Load classes.
+AutoLoader::addFolder(CORE_ROOT.'/plugins/account/models/');
// Get settings
$settings = Plugin::getAllSettings('account');
@@ -50,5 +53,12 @@
'/'.$uri.'/password' => '/plugin/account/password',
'/'.$uri.'/:any' => '/plugin/account/profile/$1',
'/'.$uri.'/:any/' => '/plugin/account/profile/$1',
+ '/'.$uri.'/logout/' => '/login/logout',
//'/users' => '/plugin/account/list',
- ));
+ ));
+
+//Observer::observe('admin_login_success', 'notifyLogin');
+
+function notifyLogin($user) {
+ Flash::setNow('message', 'You are now logged in.');
+}
View
@@ -0,0 +1,100 @@
+<?php
+/*
+ * Wolf CMS - Content Management Simplified. <http://www.wolfcms.org>
+ * Copyright (C) 2009-2010 Martijn van der Kleijn <martijn.niji@gmail.com>
+ *
+ * This file is part of Wolf CMS. Wolf CMS is licensed under the GNU GPLv3 license.
+ * Please see license.txt for the full license text.
+ */
+
+/**
+ * @package wolf
+ * @subpackage models
+ *
+ * @author Martijn van der Kleijn <martijn.niji@gmail.com>
+ * @version 0.1
+ * @license http://www.gnu.org/licenses/gpl.html GPL License
+ * @copyright Martijn van der Kleijn, 2010
+ */
+
+/**
+ * Account
+ *
+ * @todo finish phpdoc
+ *
+ * @author Martijn van der Kleijn <martijn.niji@gmail.com>
+ * @since Wolf version 0.7.0
+ */
+class AccountSetting extends Record {
+ const TABLE_NAME = 'account_setting';
+
+ public $id;
+ public $user_id;
+ public $name;
+ public $value;
+
+ private static $fieldname_map;
+ private static $fieldtype_map;
+ private static $fieldvalid_map;
+
+ public static function registerAccountSetting($id, $name, $type, $valid='[^a-zA-Z0-9_]') {
+ if (eregi('[^a-zA-Z0-9 -_]', $id) || eregi('[^a-zA-Z0-9 -_]', $name) || eregi('[^a-z]', $type)) {
+ return false;
+ }
+
+ self::$fieldname_map[$id] = $name;
+ self::$fieldtype_map[$id] = $type;
+ self::$fieldvalid_map[$id] = $valid;
+
+ return true;
+ }
+
+ public static function accountSettingName($id) {
+ return self::$fieldname_map[$id];
+ }
+/*
+ public static function accountSettingType($id) {
+ return self::$fieldtype_map[$id];
+ }
+*/
+ public static function validAccountSetting($id, $value) {
+ return (!eregi(self::$fieldvalid_map[$id], $value));
+ }
+
+/*
+ public function __toString() {
+ return $this->value;
+ }
+*/
+ public static function find($id, $name) {
+ return self::findByUserIdAndName($id, $name);
+ }
+
+ public static function findByUserId($id) {
+ $where = 'user_id=?';
+ $values = array($id);
+
+ return self::findAllFrom('AccountSetting', $where, $values);
+ }
+
+ public static function findByUserIdAndName($id, $name) {
+ $where = 'user_id=? AND name=?';
+ $values = array($id, $name);
+
+ return self::findOneFrom('AccountSetting', $where, $values);
+ }
+
+ public static function findByName($name) {
+ $where = 'name=?';
+ $values = array($name);
+
+ return self::findAllFrom('AccountSetting', $where, $values);
+ }
+
+ public function beforeSave() {
+ //if (!ctype_alnum($this->name))
+ // return false;
+
+ return true;
+ }
+}
View
@@ -0,0 +1,36 @@
+<?php
+/*
+ * Account plugin for Wolf CMS. <http://www.wolfcms.org>
+ * Copyright (C) 2010 Martijn van der Kleijn <martijn.niji@gmail.com>
+ *
+ * This file is part of the Account plugin for Wolf CMS.
+ *
+ * The Account plugin for Wolf CMS is made available under the terms of the GNU GPLv3 license.
+ * Please see <http://www.gnu.org/licenses/gpl.html> for full details.
+ */
+
+/**
+ * The Account plugin allows end users to view and manipulate their accounts.
+ *
+ * @package wolf
+ * @subpackage plugin.account
+ *
+ * @author Martijn van der Kleijn <martijn.niji@gmail.com>
+ * @version 1.0.0
+ * @since Wolf version 0.7.0
+ * @license http://www.gnu.org/licenses/gpl.html GPLv3 License
+ * @copyright Martijn van der Kleijn, 2010
+ */
+?>
+
+<!--div id="account"-->
+<h2 class="title">Actions...</h2>
+<div class="account-plugin-sidebar">
+ <ul>
+ <?php if (count($actions) == 0) { echo '<li>'.__('No actions available').'</li>'; } ?>
+ <?php foreach($actions as $name => $link) { ?>
+ <li><a href="<?php echo $link; ?>"><?php echo $name; ?></a></li>
+ <?php } ?>
+ </ul>
+</div>
+<!--/div-->
Oops, something went wrong.

0 comments on commit 8656bdb

Please sign in to comment.