[Jaws-commits] r13406 - trunk/jaws/html/gadgets/Users/Actions

afz at jaws-project.com afz at jaws-project.com
Mon Aug 13 06:03:43 UTC 2012


Author: afz
Date: 2012-08-13 06:03:43 +0000 (Mon, 13 Aug 2012)
New Revision: 13406

Added:
   trunk/jaws/html/gadgets/Users/Actions/Account.php
   trunk/jaws/html/gadgets/Users/Actions/Admin/
   trunk/jaws/html/gadgets/Users/Actions/Login.php
   trunk/jaws/html/gadgets/Users/Actions/Preferences.php
   trunk/jaws/html/gadgets/Users/Actions/Profile.php
   trunk/jaws/html/gadgets/Users/Actions/Registration.php
Removed:
   trunk/jaws/html/gadgets/Users/Actions/AdminHTML/
   trunk/jaws/html/gadgets/Users/Actions/HTML/
Log:
[Users]: restructure users actions

Copied: trunk/jaws/html/gadgets/Users/Actions/Account.php (from rev 13400, trunk/jaws/html/gadgets/Users/Actions/HTML/Account.php)
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/Account.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Actions/Account.php	2012-08-13 06:03:43 UTC (rev 13406)
@@ -0,0 +1,133 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   Gadget
+ * @package    Users
+ * @author     Jonathan Hernandez <ion at suavizado.com>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2004-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersHTML_Account extends UsersHTML
+{
+    /**
+     * Prepares a simple form to update user's data (nickname, email, password)
+     *
+     * @access  public
+     * @return  string  XHTML template of a form
+     */
+    function Account()
+    {
+        if (!$GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                                'Users',
+                                                'LoginBox',
+                                                array('referrer'  => Jaws_Utils::getRequestURL(false))), true);
+        }
+
+        $GLOBALS['app']->Session->CheckPermission('Users', 'EditAccountInformation');
+        $account = $GLOBALS['app']->Session->PopSimpleResponse('Users.Account.Data');
+        if (empty($account)) {
+            require_once JAWS_PATH . 'include/Jaws/User.php';
+            $jUser = new Jaws_User;
+            $account  = $jUser->GetUser($GLOBALS['app']->Session->GetAttribute('user'), true, true);
+        }
+
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+
+        // Load the template
+        $tpl = new Jaws_Template('gadgets/Users/templates/');
+        $tpl->Load('Account.html');
+        $tpl->SetBlock('account');
+        $tpl->SetVariable('title', _t('USERS_ACCOUNT_INFO'));
+        $tpl->SetVariable('base_script', BASE_SCRIPT);
+        $tpl->SetVariable('update', _t('USERS_USERS_ACCOUNT_UPDATE'));
+
+        $tpl->SetVariable('lbl_email',         _t('GLOBAL_EMAIL'));
+        $tpl->SetVariable('email',             $xss->filter($account['email']));
+        $tpl->SetVariable('lbl_nickname',      _t('USERS_USERS_NICKNAME'));
+        $tpl->SetVariable('nickname',          $xss->filter($account['nickname']));
+        $tpl->SetVariable('lbl_password',      _t('USERS_USERS_PASSWORD'));
+        $tpl->SetVariable('emptypassword',     _t('USERS_NOCHANGE_PASSWORD'));
+        $tpl->SetVariable('lbl_checkpassword', _t('USERS_USERS_PASSWORD_VERIFY'));
+
+        if ($response = $GLOBALS['app']->Session->PopSimpleResponse('Users.Account.Response')) {
+            $tpl->SetBlock('account/response');
+            $tpl->SetVariable('msg', $response);
+            $tpl->ParseBlock('account/response');
+        }
+        $tpl->ParseBlock('account');
+        return $tpl->Get();
+    }
+
+    /**
+     * Updates user information
+     *
+     * @access  public
+     */
+    function UpdateAccount()
+    {
+        if (!$GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                                'Users',
+                                                'LoginBox',
+                                                array('referrer'  => Jaws_Utils::getRequestURL(false))), true);
+        }
+
+        $GLOBALS['app']->Session->CheckPermission('Users', 'EditAccountInformation');
+        $request =& Jaws_Request::getInstance();
+        $post = $request->get(array('email', 'nickname', 'password', 'password_check'), 'post');
+
+        if ($post['password'] === $post['password_check']) {
+            $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Account');
+            $result = $model->UpdateAccount($GLOBALS['app']->Session->GetAttribute('user'),
+                                            $GLOBALS['app']->Session->GetAttribute('username'),
+                                            $post['email'],
+                                            $post['nickname'],
+                                            $post['password']);
+            if (!Jaws_Error::IsError($result)) {
+                $GLOBALS['app']->Session->PushSimpleResponse(_t('USERS_MYACCOUNT_UPDATED'),
+                                                             'Users.Account.Response');
+            } else {
+                $GLOBALS['app']->Session->PushSimpleResponse($result->GetMessage(),
+                                                             'Users.Account.Response');
+            }
+        } else {
+            $GLOBALS['app']->Session->PushSimpleResponse(_t('USERS_USERS_PASSWORDS_DONT_MATCH'),
+                                                         'Users.Account.Response');
+        }
+
+        // unset unnecessary account data
+        unset($post['password'], $post['password_check']);
+        $GLOBALS['app']->Session->PushSimpleResponse($post, 'Users.Account.Data');
+        Jaws_Header::Location($this->GetURLFor('Account'));
+    }
+
+    /**
+     * Check if given recovery key really exists, it it exists it generates
+     * a new password (pronounceable) and sends it to user mailbox
+     *
+     * @access  public
+     * @return  string  XHTML template
+     */
+    function ChangePassword()
+    {
+        if ($GLOBALS['app']->Registry->Get('/gadgets/Users/password_recovery') !== 'true') {
+            return parent::_404();
+        }
+
+        $request =& Jaws_Request::getInstance();
+        $key     = $request->get('key', 'get');
+
+        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Account');
+        $result = $model->ChangePassword($key);
+
+        if (Jaws_Error::IsError($result)) {
+            return $result->GetMessage();
+        }
+
+        return _t('USERS_FORGOT_PASSWORD_CHANGED');
+    }
+
+}
\ No newline at end of file

Copied: trunk/jaws/html/gadgets/Users/Actions/Login.php (from rev 13400, trunk/jaws/html/gadgets/Users/Actions/HTML/Login.php)
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/Login.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Actions/Login.php	2012-08-13 06:03:43 UTC (rev 13406)
@@ -0,0 +1,151 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   Gadget
+ * @package    Users
+ * @author     Jonathan Hernandez <ion at suavizado.com>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2004-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersHTML_Login extends UsersHTML
+{
+    /**
+     * Verifies if user/email/(captcha) are valid, if they are a mail
+     * is sent to user with a secret (MD5) key
+     *
+     * @access  public
+     */
+    function SendRecoverKey()
+    {
+        if ($GLOBALS['app']->Registry->Get('/gadgets/Users/password_recovery') !== 'true') {
+            return parent::_404();
+        }
+
+        $request =& Jaws_Request::getInstance();
+        $post  = $request->get(array('email'), 'post');
+        $error = '';
+
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        $resCheck = $mPolicy->CheckCaptcha();
+        if (Jaws_Error::IsError($resCheck)) {
+            $GLOBALS['app']->Session->PushSimpleResponse($resCheck->getMessage(), 'Users.ForgotLogin');
+            Jaws_Header::Location($this->GetURLFor('ForgotLogin'));
+        }
+
+        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Registration');
+        $result = $model->SendRecoveryKey($post['email']);
+        if (Jaws_Error::IsError($result)) {
+            $GLOBALS['app']->Session->PushSimpleResponse($result->GetMessage(), 'Users.ForgotLogin');
+        } else {
+            $GLOBALS['app']->Session->PushSimpleResponse(_t('USERS_FORGOT_MAIL_SENT'), 'Users.ForgotLogin');
+        }
+        Jaws_Header::Location($this->GetURLFor('ForgotLogin'));
+    }
+
+    /**
+     * Password recovery
+     *
+     * @access  public
+     * @return  string  XHTML template
+     */
+    function ForgotLogin()
+    {
+        if ($GLOBALS['app']->Registry->Get('/gadgets/Users/password_recovery') !== 'true') {
+            return parent::_404();
+        }
+
+        // Load the template
+        $tpl = new Jaws_Template('gadgets/Users/templates/');
+        $tpl->Load('ForgotLogin.html');
+        $tpl->SetBlock('forgot');
+        $tpl->SetVariable('base_script', BASE_SCRIPT);
+        $tpl->SetVariable('title', _t('USERS_FORGOT_REMEMBER'));
+        $tpl->SetVariable('info', _t('USERS_FORGOT_REMEMBER_INFO'));
+        $tpl->SetVariable('email', _t('GLOBAL_EMAIL'));
+        $tpl->SetVariable('remember', _t('GLOBAL_SUBMIT'));
+
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        if ($mPolicy->LoadCaptcha($captcha, $entry, $description)) {
+            $tpl->SetBlock('forgot/captcha');
+            $tpl->SetVariable('lbl_captcha', _t('GLOBAL_CAPTCHA_CODE'));
+            $tpl->SetVariable('captcha', $captcha);
+            if (!empty($entry)) {
+                $tpl->SetVariable('captchavalue', $entry);
+            }
+            $tpl->SetVariable('captcha_msg', $description);
+            $tpl->ParseBlock('forgot/captcha');
+        }
+
+        if ($response = $GLOBALS['app']->Session->PopSimpleResponse('Users.ForgotLogin')) {
+            $tpl->SetBlock('forgot/response');
+            $tpl->SetVariable('msg', $response);
+            $tpl->ParseBlock('forgot/response');
+        }
+        $tpl->ParseBlock('forgot');
+        return $tpl->Get();
+    }
+
+    /**
+     * Calls Login box
+     *
+     * @access  public
+     */
+    function LoginBox()
+    {
+        $layoutGadget = $GLOBALS['app']->LoadGadget('Users', 'LayoutHTML');
+        if ($GLOBALS['app']->Session->Logged()) {
+            return $layoutGadget->LoginLinks();
+        } else {
+            return $layoutGadget->LoginBox();
+        }
+    }
+
+    /**
+     * Logins an user, if something goes wrong then redirect user to previous page
+     * and notify the error
+     *
+     * @access  public
+     */
+    function Login()
+    {
+        $request =& Jaws_Request::getInstance();
+        $post    = $request->get(array('username', 'password', 'remember', 'usecrypt', 'referrer'), 'post');
+
+        if ($GLOBALS['app']->Registry->Get('/crypt/enabled') == 'true' && isset($post['usecrypt'])) {
+            require_once JAWS_PATH . 'include/Jaws/Crypt.php';
+            $JCrypt = new Jaws_Crypt();
+            $JCrypt->Init();
+            $post['password'] = $JCrypt->decrypt($post['password']);
+            if (Jaws_Error::isError($post['password'])) {
+                $post['password'] = '';
+            }
+        }
+
+        $login = $GLOBALS['app']->Session->Login($post['username'], $post['password'], $post['remember']);
+        if (Jaws_Error::isError($login)) {
+            $GLOBALS['app']->Session->PushSimpleResponse($login->GetMessage(), 'Users.Login');
+            unset($post['password']);
+            $GLOBALS['app']->Session->PushSimpleResponse($post, 'Users.Login.Data');
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                            'Users',
+                                            'LoginBox',
+                                            array('referrer'  => $post['referrer'])), true);
+        }
+
+        Jaws_Header::Location($post['referrer']);
+    }
+
+    /**
+     * Logout an user
+     *
+     * @access  public
+     */
+    function Logout()
+    {
+        $GLOBALS['app']->Session->Logout();
+        Jaws_Header::Referrer();
+    }
+
+}
\ No newline at end of file

Copied: trunk/jaws/html/gadgets/Users/Actions/Preferences.php (from rev 13400, trunk/jaws/html/gadgets/Users/Actions/HTML/Preferences.php)
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/Preferences.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Actions/Preferences.php	2012-08-13 06:03:43 UTC (rev 13406)
@@ -0,0 +1,145 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   Gadget
+ * @package    Users
+ * @author     Jonathan Hernandez <ion at suavizado.com>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2004-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersHTML_Preferences extends UsersHTML
+{
+    /**
+     * Prepares a simple form to update user's data (name, email, password)
+     *
+     * @access  public
+     * @return  string  XHTML template of a form
+     */
+    function Preferences()
+    {
+        if (!$GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                                'Users',
+                                                'LoginBox',
+                                                array('referrer'  => Jaws_Utils::getRequestURL(false))), true);
+        }
+
+        $GLOBALS['app']->Session->CheckPermission('Users', 'EditAccountPreferences');
+        //Here we load the Settings/Layout models (which is part of core) to extract some data
+        $settingsModel = $GLOBALS['app']->loadGadget('Settings', 'AdminModel');
+
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $jUser = new Jaws_User;
+        $info  = $jUser->GetUser($GLOBALS['app']->Session->GetAttribute('user'), false, false, true);
+
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+
+        // Load the template
+        $tpl = new Jaws_Template('gadgets/Users/templates/');
+        $tpl->Load('Preferences.html');
+        $tpl->SetBlock('preferences');
+        
+        $tpl->SetVariable('title', _t('USERS_USERS_ACCOUNT_PREF'));
+        $tpl->SetVariable('base_script', BASE_SCRIPT);
+        $tpl->SetVariable('update', _t('USERS_USERS_ACCOUNT_UPDATE'));
+
+        //Language
+        $lang =& Piwi::CreateWidget('Combo', 'user_language');
+        $lang->setID('user_language');
+        $lang->AddOption(_t('USERS_ADVANCED_OPTS_NOT_YET'), null);
+        $languages = Jaws_Utils::GetLanguagesList();
+        foreach($languages as $k => $v) {
+            $lang->AddOption($v, $k);
+        }
+        $lang->SetDefault($info['language']);
+        $lang->SetTitle(_t('USERS_ADVANCED_OPTS_LANGUAGE'));
+        $tpl->SetVariable('user_language', $lang->Get());
+        $tpl->SetVariable('language', _t('USERS_ADVANCED_OPTS_LANGUAGE'));
+
+        //Theme
+        $uTheme =& Piwi::CreateWidget('ComboGroup', 'user_theme');
+        $uTheme->setID('user_theme');
+        $uTheme->addGroup('local', _t('LAYOUT_THEME_LOCAL'));
+        $uTheme->addGroup('remote', _t('LAYOUT_THEME_REMOTE'));
+        $uTheme->AddOption('local', _t('USERS_ADVANCED_OPTS_NOT_YET'), null);
+        $themes = Jaws_Utils::GetThemesList();
+        foreach ($themes as $theme => $tInfo) {
+            $uTheme->AddOption($tInfo['local']? 'local' : 'remote', $tInfo['name'], $theme);
+        }
+        $uTheme->SetDefault($info['theme']);
+        $uTheme->SetTitle(_t('USERS_ADVANCED_OPTS_THEME'));
+        $tpl->SetVariable('user_theme', $uTheme->Get());
+        $tpl->SetVariable('theme', _t('USERS_ADVANCED_OPTS_THEME'));
+
+        //Editor
+        $editor =& Piwi::CreateWidget('Combo', 'user_editor');
+        $editor->setID('user_editor');
+        $editor->AddOption(_t('USERS_ADVANCED_OPTS_NOT_YET'), null);
+        $editors = $settingsModel->GetEditorList();
+        foreach($editors as $k => $v) {
+            $editor->AddOption($v, $k);
+        }
+        $editor->SetDefault($info['editor']);
+        $editor->SetTitle(_t('USERS_ADVANCED_OPTS_EDITOR'));
+        $tpl->SetVariable('user_editor', $editor->Get());
+        $tpl->SetVariable('editor', _t('USERS_ADVANCED_OPTS_EDITOR'));
+
+        //Time Zones
+        $timezone =& Piwi::CreateWidget('Combo', 'user_timezone');
+        $timezone->setID('user_timezone');
+        $timezone->AddOption(_t('USERS_ADVANCED_OPTS_NOT_YET'), null);
+        $timezones = $settingsModel->GetTimeZonesList();
+        foreach($timezones as $k => $v) {
+            $timezone->AddOption($v, $k);
+        }
+        $timezone->SetDefault($info['timezone']);
+        $timezone->SetTitle(_t('GLOBAL_TIMEZONE'));
+        $tpl->SetVariable('user_timezone', $timezone->Get());
+        $tpl->SetVariable('timezone', _t('GLOBAL_TIMEZONE'));
+
+        if ($response = $GLOBALS['app']->Session->PopSimpleResponse('Users.Preferences')) {
+            $tpl->SetBlock('preferences/response');
+            $tpl->SetVariable('msg', $response);
+            $tpl->ParseBlock('preferences/response');
+        }
+        $tpl->ParseBlock('preferences');
+        return $tpl->Get();
+    }
+
+    /**
+     * Updates user information
+     *
+     * @access  public
+     */
+    function UpdatePreferences()
+    {
+        if (!$GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                                'Users',
+                                                'LoginBox',
+                                                array('referrer'  => Jaws_Utils::getRequestURL(false))), true);
+        }
+
+        $GLOBALS['app']->Session->CheckPermission('Users', 'EditAccountPreferences');
+        $request =& Jaws_Request::getInstance();
+        $post = $request->get(array('user_language', 'user_theme', 'user_editor', 'user_timezone'), 'post');
+
+        $model = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Preferences');
+        $result = $model->UpdatePreferences($GLOBALS['app']->Session->GetAttribute('user'),
+                                            $post['user_language'],
+                                            $post['user_theme'],
+                                            $post['user_editor'],
+                                            $post['user_timezone']);
+
+        if (!Jaws_Error::IsError($result)) {
+            $GLOBALS['app']->Session->PushSimpleResponse(_t('USERS_PREFERENCES_UPDATED'), 'Users.Preferences');
+        } else {
+            $GLOBALS['app']->Session->PushSimpleResponse($result->GetMessage(), 'Users.Preferences');
+        }
+
+        Jaws_Header::Location($this->GetURLFor('Preferences'));
+    }
+
+}
\ No newline at end of file

Copied: trunk/jaws/html/gadgets/Users/Actions/Profile.php (from rev 13400, trunk/jaws/html/gadgets/Users/Actions/HTML/Profile.php)
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/Profile.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Actions/Profile.php	2012-08-13 06:03:43 UTC (rev 13406)
@@ -0,0 +1,135 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   Gadget
+ * @package    Users
+ * @author     Jonathan Hernandez <ion at suavizado.com>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2004-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersHTML_Profile extends UsersHTML
+{
+    /**
+     * Prepares a simple form to update user's data (name, email, password)
+     *
+     * @access  public
+     * @return  string  XHTML template of a form
+     */
+    function Profile()
+    {
+        if (!$GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                                'Users',
+                                                'LoginBox',
+                                                array('referrer'  => Jaws_Utils::getRequestURL(false))), true);
+        }
+
+        $GLOBALS['app']->Session->CheckPermission('Users', 'EditAccountProfile');
+        $profile = $GLOBALS['app']->Session->PopSimpleResponse('Users.Profile.Data');
+        if (empty($profile)) {
+            require_once JAWS_PATH . 'include/Jaws/User.php';
+            $jUser = new Jaws_User;
+            $profile  = $jUser->GetUser($GLOBALS['app']->Session->GetAttribute('user'), true, true);
+        }
+
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+
+        // Load the template
+        $tpl = new Jaws_Template('gadgets/Users/templates/');
+        $tpl->Load('Profile.html');
+        $tpl->SetBlock('profile');
+        $tpl->SetVariable('title', _t('USERS_PERSONAL_INFO'));
+        $tpl->SetVariable('base_script', BASE_SCRIPT);
+        $tpl->SetVariable('update', _t('USERS_USERS_ACCOUNT_UPDATE'));
+
+        $tpl->SetVariable('lbl_fname',         _t('USERS_USERS_FIRSTNAME'));
+        $tpl->SetVariable('fname',             $xss->filter($profile['fname']));
+        $tpl->SetVariable('lbl_lname',         _t('USERS_USERS_LASTNAME'));
+        $tpl->SetVariable('lname',             $xss->filter($profile['lname']));
+        $tpl->SetVariable('lbl_gender',        _t('USERS_USERS_GENDER'));
+        $tpl->SetVariable('gender_male',       _t('USERS_USERS_MALE'));
+        $tpl->SetVariable('gender_female',     _t('USERS_USERS_FEMALE'));
+        if (empty($profile['gender'])) {
+            $tpl->SetVariable('male_selected',   'selected="selected"');
+        } else {
+            $tpl->SetVariable('female_selected', 'selected="selected"');
+        }
+
+        if (empty($profile['dob'])) {
+            $dob = array('', '', '');
+        } else {
+            $date = $GLOBALS['app']->loadDate();
+            $dob = $date->Format($profile['dob'], 'Y-m-d');
+            $dob = explode('-', $dob);
+        }
+
+        $tpl->SetVariable('lbl_dob',    _t('USERS_USERS_BIRTHDAY'));
+        $tpl->SetVariable('dob_year',   $dob[0]);
+        $tpl->SetVariable('dob_month',  $dob[1]);
+        $tpl->SetVariable('dob_day',    $dob[2]);
+        $tpl->SetVariable('dob_sample', _t('USERS_USERS_BIRTHDAY_SAMPLE'));
+
+        $tpl->SetVariable('lbl_url',           _t('GLOBAL_URL'));
+        $tpl->SetVariable('url',               $xss->filter($profile['url']));
+
+        if ($response = $GLOBALS['app']->Session->PopSimpleResponse('Users.Profile.Response')) {
+            $tpl->SetBlock('profile/response');
+            $tpl->SetVariable('msg', $response);
+            $tpl->ParseBlock('profile/response');
+        }
+        $tpl->ParseBlock('profile');
+        return $tpl->Get();
+    }
+
+    /**
+     * Updates user information
+     *
+     * @access  public
+     */
+    function UpdateProfile()
+    {
+        if (!$GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location($GLOBALS['app']->Map->GetURLFor(
+                                                'Users',
+                                                'LoginBox',
+                                                array('referrer'  => Jaws_Utils::getRequestURL(false))), true);
+        }
+
+        $GLOBALS['app']->Session->CheckPermission('Users', 'EditAccountProfile');
+        $request =& Jaws_Request::getInstance();
+        $post = $request->get(array('fname', 'lname', 'gender', 'dob_year', 'dob_month', 'dob_day', 'url'), 'post');
+
+        $post['dob'] = null;
+        if (!empty($post['dob_year']) && !empty($post['dob_year']) && !empty($post['dob_year'])) {
+            $date = $GLOBALS['app']->loadDate();
+            $dob  = $date->ToBaseDate($post['dob_year'], $post['dob_month'], $post['dob_day']);
+            $post['dob'] = date('Y-m-d H:i:s', $dob['timestamp']);
+        }
+
+        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Personal');
+        $result = $model->UpdatePersonal($GLOBALS['app']->Session->GetAttribute('user'),
+                                         $post['fname'],
+                                         $post['lname'],
+                                         $post['gender'],
+                                         $post['dob'],
+                                         $post['url']);
+        if (!Jaws_Error::IsError($result)) {
+            $GLOBALS['app']->Session->PushSimpleResponse(_t('USERS_MYACCOUNT_UPDATED'),
+                                                         'Users.Profile.Response');
+        } else {
+            $GLOBALS['app']->Session->PushSimpleResponse($result->GetMessage(),
+                                                         'Users.Profile.Response');
+        }
+
+        // unset unnecessary profile data
+        unset($post['dob_day'],
+              $post['dob_month'],
+              $post['dob_year']);
+
+        $GLOBALS['app']->Session->PushSimpleResponse($post, 'Users.Profile.Data');
+        Jaws_Header::Location($this->GetURLFor('Profile'));
+    }
+
+}
\ No newline at end of file

Copied: trunk/jaws/html/gadgets/Users/Actions/Registration.php (from rev 13400, trunk/jaws/html/gadgets/Users/Actions/HTML/Registration.php)
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/Registration.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Actions/Registration.php	2012-08-13 06:03:43 UTC (rev 13406)
@@ -0,0 +1,218 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   Gadget
+ * @package    Users
+ * @author     Jonathan Hernandez <ion at suavizado.com>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2004-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersHTML_Registration extends UsersHTML
+{
+    /**
+     * Tells the user the registation process is done
+     *
+     * @access  public
+     * @return  string  XHTML of template
+     */
+    function Registered()
+    {
+        // Load the template
+        $tpl = new Jaws_Template('gadgets/Users/templates/');
+        $tpl->Load('Registered.html');
+        $tpl->SetBlock('registered');
+        $tpl->SetVariable('title', _t('USERS_REGISTER_REGISTERED'));
+
+        switch ($GLOBALS['app']->Registry->Get('/config/anon_activation')) {
+            case 'admin':
+                $message = _t('USERS_ACTIVATE_ACTIVATION_BY_ADMIN_MSG');
+                break;
+            case 'user':
+                $message = _t('USERS_ACTIVATE_ACTIVATION_BY_USER_MSG');
+                break;
+            default:
+                $message = _t('USERS_REGISTER_REGISTERED_MSG', $this->GetURLFor('LoginBox'));
+        }
+
+        $tpl->SetVariable('registered_msg', $message);
+        $tpl->ParseBlock('registered');
+        return $tpl->Get();
+    }
+
+    /**
+     * Register the user
+     *
+     * @access  public
+     */
+    function DoRegister()
+    {
+        if ($GLOBALS['app']->Registry->Get('/config/anon_register') !== 'true') {
+            return parent::_404();
+        }
+
+        $result  = '';
+        $request =& Jaws_Request::getInstance();
+        $post = $request->get(array('username', 'email', 'nickname', 'password', 'password_check',
+                                    'fname', 'lname', 'gender', 'dob_year', 'dob_month', 'dob_day','url'),
+                              'post');
+
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        $resCheck = $mPolicy->CheckCaptcha();
+        if (Jaws_Error::IsError($resCheck)) {
+            $result = $resCheck->getMessage();
+        }
+
+        if (empty($result)) {
+            if ($post['password'] !== $post['password_check']) {
+                $result = _t('USERS_USERS_PASSWORDS_DONT_MATCH');
+            } else {
+                $dob  = null;
+                if (!empty($post['dob_year']) && !empty($post['dob_year']) && !empty($post['dob_year'])) {
+                    $date = $GLOBALS['app']->loadDate();
+                    $dob  = $date->ToBaseDate($post['dob_year'], $post['dob_month'], $post['dob_day']);
+                    $dob  = date('Y-m-d H:i:s', $dob['timestamp']);
+                }
+
+                $uModel = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Registration');
+                $result = $uModel->CreateUser($post['username'],
+                                              $post['email'],
+                                              $post['nickname'],
+                                              $post['fname'],
+                                              $post['lname'],
+                                              $post['gender'],
+                                              $dob,
+                                              $post['url'],
+                                              $post['password'],
+                                              $GLOBALS['app']->Registry->Get('/config/anon_group'));
+                if ($result === true) {
+                    Jaws_Header::Location($this->GetURLFor('Registered'));
+                }
+            }
+        }
+
+        $GLOBALS['app']->Session->PushSimpleResponse($result, 'Users.Register');
+
+        // unset unnecessary registration data
+        unset($post['password'],
+              $post['password_check'],
+              $post['random_password']);
+        $GLOBALS['app']->Session->PushSimpleResponse($post, 'Users.Register.Data');
+
+        Jaws_Header::Location($this->GetURLFor('Registration'));
+    }
+
+    /**
+     * Prepares a single form to get registered
+     *
+     * @access  public
+     * @return  string  XHTML of template
+     */
+    function Registration()
+    {
+        if ($GLOBALS['app']->Session->Logged()) {
+            Jaws_Header::Location('');
+        }
+
+        if ($GLOBALS['app']->Registry->Get('/config/anon_register') !== 'true') {
+            return parent::_404();
+        }
+
+        // Load the template
+        $tpl = new Jaws_Template('gadgets/Users/templates/');
+        $tpl->Load('Register.html');
+        $tpl->SetBlock('register');
+        $tpl->SetVariable('title', _t('USERS_REGISTER'));
+        $tpl->SetVariable('base_script', BASE_SCRIPT);
+
+        $tpl->SetVariable('lbl_account_info',  _t('USERS_ACCOUNT_INFO'));
+        $tpl->SetVariable('lbl_username',      _t('USERS_USERS_USERNAME'));
+        $tpl->SetVariable('validusernames',    _t('USERS_REGISTER_VALID_USERNAMES'));
+        $tpl->SetVariable('lbl_email',         _t('GLOBAL_EMAIL'));
+        $tpl->SetVariable('lbl_url',           _t('GLOBAL_URL'));
+        $tpl->SetVariable('lbl_nickname',         _t('USERS_USERS_NICKNAME'));
+        $tpl->SetVariable('lbl_password',      _t('USERS_USERS_PASSWORD'));
+        $tpl->SetVariable('sendpassword',      _t('USERS_USERS_SEND_AUTO_PASSWORD'));
+        $tpl->SetVariable('lbl_checkpassword', _t('USERS_USERS_PASSWORD_VERIFY'));
+
+        $tpl->SetVariable('lbl_personal_info', _t('USERS_PERSONAL_INFO'));
+        $tpl->SetVariable('lbl_fname',         _t('USERS_USERS_FIRSTNAME'));
+        $tpl->SetVariable('lbl_lname',         _t('USERS_USERS_LASTNAME'));
+        $tpl->SetVariable('lbl_gender',        _t('USERS_USERS_GENDER'));
+        $tpl->SetVariable('gender_male',       _t('USERS_USERS_MALE'));
+        $tpl->SetVariable('gender_female',     _t('USERS_USERS_FEMALE'));
+        $tpl->SetVariable('lbl_dob',           _t('USERS_USERS_BIRTHDAY'));
+        $tpl->SetVariable('dob_sample',        _t('USERS_USERS_BIRTHDAY_SAMPLE'));
+
+        if ($post_data = $GLOBALS['app']->Session->PopSimpleResponse('Users.Register.Data')) {
+            $tpl->SetVariable('username',  $post_data['username']);
+            $tpl->SetVariable('email',     $post_data['email']);
+            $tpl->SetVariable('url',       $post_data['url']);
+            $tpl->SetVariable('nickname',  $post_data['nickname']);
+            $tpl->SetVariable('fname',     $post_data['fname']);
+            $tpl->SetVariable('lname',     $post_data['lname']);
+            $tpl->SetVariable('dob_year',  $post_data['dob_year']);
+            $tpl->SetVariable('dob_month', $post_data['dob_month']);
+            $tpl->SetVariable('dob_day',   $post_data['dob_day']);
+            $tpl->SetVariable("selected_gender_{$post_data['gender']}", 'selected="selected"');
+        } else {
+            $tpl->SetVariable('url', 'http://');
+            $tpl->SetVariable("selected_gender_0", 'selected="selected"');
+        }
+
+        $tpl->SetVariable('register', _t('USERS_REGISTER'));
+        $mPolicy = $GLOBALS['app']->LoadGadget('Policy', 'Model');
+        if ($mPolicy->LoadCaptcha($captcha, $entry, $description)) {
+            $tpl->SetBlock('register/captcha');
+            $tpl->SetVariable('lbl_captcha', _t('GLOBAL_CAPTCHA_CODE'));
+            $tpl->SetVariable('captcha', $captcha);
+            if (!empty($entry)) {
+                $tpl->SetVariable('captchavalue', $entry);
+            }
+            $tpl->SetVariable('captcha_msg', $description);
+            $tpl->ParseBlock('register/captcha');
+        }
+
+        if ($response = $GLOBALS['app']->Session->PopSimpleResponse('Users.Register')) {
+            $tpl->SetBlock('register/response');
+            $tpl->SetVariable('msg', $response);
+            $tpl->ParseBlock('register/response');
+        }
+
+        $tpl->ParseBlock('register');
+        return $tpl->Get();
+    }
+
+    /**
+     * Activate the user
+     *
+     * @access  public
+     */
+    function ActivateUser()
+    {
+        if ($GLOBALS['app']->Session->Logged() && !$GLOBALS['app']->Session->IsSuperAdmin()) {
+            Jaws_Header::Location('');
+        }
+
+        if ($GLOBALS['app']->Registry->Get('/config/anon_register') !== 'true') {
+            return parent::_404();
+        }
+
+        $request =& Jaws_Request::getInstance();
+        $key     = $request->get('key', 'get');
+
+        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Registration');
+        $result = $model->ActivateUser($key);
+        if (Jaws_Error::IsError($result)) {
+            return $result->getMessage();
+        }
+
+        if ($GLOBALS['app']->Registry->Get('/config/anon_activation') == 'user') {
+            return _t('USERS_ACTIVATE_ACTIVATED_BY_USER_MSG', $this->GetURLFor('LoginBox'));
+        } else {
+            return _t('USERS_ACTIVATE_ACTIVATED_BY_ADMIN_MSG');
+        }
+    }
+
+}
\ No newline at end of file



More information about the Jaws-commits mailing list