[Jaws-commits] r13400 - in trunk/jaws/html/gadgets/Users: . Actions/HTML Model

afz at jaws-project.com afz at jaws-project.com
Sun Aug 12 22:47:27 UTC 2012


Author: afz
Date: 2012-08-12 22:47:26 +0000 (Sun, 12 Aug 2012)
New Revision: 13400

Added:
   trunk/jaws/html/gadgets/Users/Model/
   trunk/jaws/html/gadgets/Users/Model/Account.php
   trunk/jaws/html/gadgets/Users/Model/GroupACL.php
   trunk/jaws/html/gadgets/Users/Model/Personal.php
   trunk/jaws/html/gadgets/Users/Model/Preferences.php
   trunk/jaws/html/gadgets/Users/Model/Registration.php
   trunk/jaws/html/gadgets/Users/Model/Settings.php
   trunk/jaws/html/gadgets/Users/Model/UserACL.php
   trunk/jaws/html/gadgets/Users/Model/UsersGroup.php
Modified:
   trunk/jaws/html/gadgets/Users/Actions/HTML/Account.php
   trunk/jaws/html/gadgets/Users/Actions/HTML/Login.php
   trunk/jaws/html/gadgets/Users/Actions/HTML/Preferences.php
   trunk/jaws/html/gadgets/Users/Actions/HTML/Profile.php
   trunk/jaws/html/gadgets/Users/Actions/HTML/Registration.php
   trunk/jaws/html/gadgets/Users/AdminAjax.php
   trunk/jaws/html/gadgets/Users/AdminModel.php
   trunk/jaws/html/gadgets/Users/Model.php
Log:
[Users]: split Mode/AdminModel for using core new feature

Modified: trunk/jaws/html/gadgets/Users/Actions/HTML/Account.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/HTML/Account.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/Actions/HTML/Account.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -80,7 +80,7 @@
         $post = $request->get(array('email', 'nickname', 'password', 'password_check'), 'post');
 
         if ($post['password'] === $post['password_check']) {
-            $model  = $GLOBALS['app']->LoadGadget('Users', 'Model');
+            $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Account');
             $result = $model->UpdateAccount($GLOBALS['app']->Session->GetAttribute('user'),
                                             $GLOBALS['app']->Session->GetAttribute('username'),
                                             $post['email'],
@@ -120,7 +120,7 @@
         $request =& Jaws_Request::getInstance();
         $key     = $request->get('key', 'get');
 
-        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model');
+        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Account');
         $result = $model->ChangePassword($key);
 
         if (Jaws_Error::IsError($result)) {

Modified: trunk/jaws/html/gadgets/Users/Actions/HTML/Login.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/HTML/Login.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/Actions/HTML/Login.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -34,7 +34,7 @@
             Jaws_Header::Location($this->GetURLFor('ForgotLogin'));
         }
 
-        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model');
+        $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');

Modified: trunk/jaws/html/gadgets/Users/Actions/HTML/Preferences.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/HTML/Preferences.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/Actions/HTML/Preferences.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -126,7 +126,7 @@
         $request =& Jaws_Request::getInstance();
         $post = $request->get(array('user_language', 'user_theme', 'user_editor', 'user_timezone'), 'post');
 
-        $model = $GLOBALS['app']->LoadGadget('Users', 'Model');
+        $model = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Preferences');
         $result = $model->UpdatePreferences($GLOBALS['app']->Session->GetAttribute('user'),
                                             $post['user_language'],
                                             $post['user_theme'],

Modified: trunk/jaws/html/gadgets/Users/Actions/HTML/Profile.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/HTML/Profile.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/Actions/HTML/Profile.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -108,13 +108,13 @@
             $post['dob'] = date('Y-m-d H:i:s', $dob['timestamp']);
         }
 
-        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model');
-        $result = $model->UpdateProfile($GLOBALS['app']->Session->GetAttribute('user'),
-                                        $post['fname'],
-                                        $post['lname'],
-                                        $post['gender'],
-                                        $post['dob'],
-                                        $post['url']);
+        $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');

Modified: trunk/jaws/html/gadgets/Users/Actions/HTML/Registration.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Actions/HTML/Registration.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/Actions/HTML/Registration.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -75,7 +75,7 @@
                     $dob  = date('Y-m-d H:i:s', $dob['timestamp']);
                 }
 
-                $uModel = $GLOBALS['app']->LoadGadget('Users', 'Model');
+                $uModel = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Registration');
                 $result = $uModel->CreateUser($post['username'],
                                               $post['email'],
                                               $post['nickname'],
@@ -202,7 +202,7 @@
         $request =& Jaws_Request::getInstance();
         $key     = $request->get('key', 'get');
 
-        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model');
+        $model  = $GLOBALS['app']->LoadGadget('Users', 'Model', 'Registration');
         $result = $model->ActivateUser($key);
         if (Jaws_Error::IsError($result)) {
             return $result->getMessage();

Modified: trunk/jaws/html/gadgets/Users/AdminAjax.php
===================================================================
--- trunk/jaws/html/gadgets/Users/AdminAjax.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/AdminAjax.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -272,7 +272,8 @@
     function UpdateUserACL($uid, $keys)
     {
         $this->CheckSession('Users', 'ManageUserACLs');
-        $res = $this->_Model->UpdateUserACL($uid, $keys);
+        $uModel = $GLOBALS['app']->LoadGadget('Users', 'AdminModel', 'UserACL');
+        $res = $uModel->UpdateUserACL($uid, $keys);
         if (Jaws_Error::IsError($res)) {
             $GLOBALS['app']->Session->PushLastResponse($res->GetMessage(),
                                                        RESPONSE_ERROR);
@@ -295,7 +296,8 @@
     function UpdateGroupACL($guid, $keys)
     {
         $this->CheckSession('Users', 'ManageGroupACLs');
-        $res = $this->_Model->UpdateGroupACL($guid, $keys);
+        $uModel = $GLOBALS['app']->LoadGadget('Users', 'AdminModel', 'GroupACL');
+        $res = $uModel->UpdateGroupACL($guid, $keys);
         if (Jaws_Error::IsError($res)) {
             $GLOBALS['app']->Session->PushLastResponse($res->GetMessage(),
                                                        RESPONSE_ERROR);
@@ -354,7 +356,8 @@
     function AddUsersToGroup($guid, $users)
     {
         $this->CheckSession('Users', 'ManageGroups');
-        $res = $this->_Model->AddUsersToGroup($guid, $users);
+        $uModel = $GLOBALS['app']->LoadGadget('Users', 'AdminModel', 'UsersGroup');
+        $res = $uModel->AddUsersToGroup($guid, $users);
         if (Jaws_Error::IsError($res)) {
             $GLOBALS['app']->Session->PushLastResponse($res->GetMessage(), RESPONSE_ERROR);
         } else {
@@ -378,7 +381,8 @@
     function SaveSettings($method, $anon, $repetitive, $act, $group, $recover)
     {
         $this->CheckSession('Users', 'ManageProperties');
-        $res = $this->_Model->SaveSettings($method, $anon, $repetitive, $act, $group, $recover);
+        $uModel = $GLOBALS['app']->LoadGadget('Users', 'AdminModel', 'Settings');
+        $res = $uModel->SaveSettings($method, $anon, $repetitive, $act, $group, $recover);
         if (Jaws_Error::IsError($res)) {
             $GLOBALS['app']->Session->PushLastResponse($res->GetMessage(), RESPONSE_ERROR);
         } else {
@@ -400,7 +404,8 @@
         $this->CheckSession('Users', 'ManageUserACLs');
         $profile = $this->_UserModel->GetUser((int)$uid);
         if (isset($profile['username'])) {
-            $acl = $this->_Model->GetUserACLKeys($profile['username']);
+            $uModel = $GLOBALS['app']->LoadGadget('Users', 'AdminModel', 'UserACL');
+            $acl = $uModel->GetUserACLKeys($profile['username']);
             return $acl;
         }
         return false;
@@ -418,7 +423,8 @@
         $this->CheckSession('Users', 'ManageGroupACLs');
         $profile = $this->_UserModel->GetGroupInfoById($guid);
         if (isset($profile['name'])) {
-            $acl = $this->_Model->GetGroupACLKeys($guid);
+            $uModel = $GLOBALS['app']->LoadGadget('Users', 'AdminModel', 'GroupACL');
+            $acl = $uModel->GetGroupACLKeys($guid);
             return $acl;
         }
         return false;

Modified: trunk/jaws/html/gadgets/Users/AdminModel.php
===================================================================
--- trunk/jaws/html/gadgets/Users/AdminModel.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/AdminModel.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -106,261 +106,4 @@
         return true;
     }
 
-    /**
-     * Get ACL permissions of a given user
-     *
-     * @access  public
-     * @param   string  $username  Username
-     * @return  array   Array with ACL Keys
-     */
-    function GetUserACLKeys($username)
-    {
-        $acls = $GLOBALS['app']->ACL->GetAclPermissions($username, false);
-        $perms = array();
-        if (is_array($acls)) {
-            foreach ($acls as $gadget => $keys) {
-                $g = $GLOBALS['app']->LoadGadget($gadget, 'Info');
-                if (Jaws_Error::IsError($g)) {
-                    continue;
-                }
-
-                if (!Jaws_Gadget::IsGadgetUpdated($gadget)) {
-                    continue;
-                }
-
-                if (!isset($perms[$gadget])) {
-                    $perms[$gadget] = array();
-                    $perms[$gadget]['name'] = _t(strtoupper($gadget).'_NAME');
-                }
-
-                foreach ($keys as $k) {
-                    $aclkey = '/ACL'.str_replace('/ACL/users/'.$username, '', $k['name']);
-
-                    $perms[$gadget][$aclkey] = array(
-                        'desc'  => $g->GetACLDescription($aclkey),
-                        'value' => $k['value'],
-                        'name'  => $k['name'],
-                    );
-                }
-            }
-
-            ksort($perms);
-            return $perms;
-        }
-
-        return false;
-    }
-
-    /**
-     * Returns an array with the ACL keys of a given group
-     *
-     * @access  public
-     * @param   int     $guid   Group's ID
-     * @return  array   Array with ACL Keys
-     */
-    function GetGroupACLKeys($guid)
-    {
-        $acls = $GLOBALS['app']->ACL->GetGroupAclPermissions($guid);
-        $perms = array();
-        if (is_array($acls)) {
-            foreach ($acls as $gadget => $keys) {
-                if (!Jaws_Gadget::IsGadgetUpdated($gadget)) {
-                    continue;
-                }
-
-                $g = $GLOBALS['app']->LoadGadget($gadget, 'Info');
-                if (Jaws_Error::IsError($g)) {
-                    continue;
-                }
-
-                if (!isset($perms[$gadget])) {
-                    $perms[$gadget] = array();
-                    $perms[$gadget]['name'] = _t(strtoupper($gadget).'_NAME');
-                }
-
-                foreach ($keys as $k) {
-                    $aclkey = '/ACL'.str_replace('/ACL/groups/'.$guid, '', $k['name']);
-                    $perms[$gadget][$aclkey] = array(
-                        'desc'  => $g->GetACLDescription($aclkey),
-                        'value' => $k['value'],
-                        'name'  => $k['name'],
-                    );
-                }
-            }
-
-            ksort($perms);
-            return $perms;
-        }
-
-        return false;
-    }
-
-    /**
-     * Saves only the modified ACL user keys
-     *
-     * @access  public
-     * @param   int     $uid    User' ID
-     * @param   array   $keys   ACL Keys
-     * @return  boolean Success/Failure(Jaws_Error)
-     */
-    function UpdateUserACL($uid, $keys)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $userModel = new Jaws_User();
-        $currentUser = $GLOBALS['app']->Session->GetAttribute('user');
-        if ($user = $userModel->GetUser((int)$uid)) {
-            //Load user keys
-            $GLOBALS['app']->ACL->LoadAllFiles();
-            $GLOBALS['app']->ACL->LoadKeysOf($user['username'], 'users');
-            foreach($keys as $key => $value) {
-                //check user permission for this key
-                $expkey = explode('/', $key);
-                $aclkey = end($expkey);
-                $gadget = prev($expkey);
-                if (!$GLOBALS['app']->Session->GetPermission($gadget, $aclkey)) {
-                    continue;
-                }
-
-                //Get the current value
-                if ($key == '/ACL/users/' . $user['username'] . '/gadgets/ControlPanel/default' &&
-                    $value === false && $uid == $currentUser)
-                {
-                    return new Jaws_Error(_t('USERS_USERS_CANT_AUTO_TURN_OFF_CP'), _t('USERS_NAME'));
-                }
-
-                if (is_null($value)) {
-                    $GLOBALS['app']->ACL->DeleteKey($key);
-                } else {
-                    $valueString = ($value === true)? 'true' : 'false';
-                    if (is_null($GLOBALS['app']->ACL->Get($key))) {
-                        $GLOBALS['app']->ACL->NewKey($key, $valueString);
-                    } else {
-                        $GLOBALS['app']->ACL->Set($key, $valueString);
-                    }
-                }
-            }
-            return true;
-        }
-
-        return new Jaws_Error(_t('USERS_USER_NOT_EXIST'), _t('USERS_NAME'));
-    }
-
-    /**
-     * Saves only the modified ACL group keys
-     *
-     * @access  public
-     * @param   int     $guid   Group ID
-     * @param   array   $keys   ACL Keys
-     */
-    function UpdateGroupACL($guid, $keys)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $userModel = new Jaws_User();
-
-        if ($group = $userModel->GetGroupInfoById($guid)) {
-            $GLOBALS['app']->ACL->LoadAllFiles();
-            $GLOBALS['app']->ACL->LoadKeysOf($guid, 'groups');
-            foreach ($keys as $key => $value) {
-                if (is_null($value)) {
-                    $GLOBALS['app']->ACL->DeleteKey($key);
-                } else {
-                    $valueString = ($value === true)? 'true' : 'false';
-                    if (is_null($GLOBALS['app']->ACL->Get($key))) {
-                        $GLOBALS['app']->ACL->NewKey($key, $valueString);
-                    } else {
-                        $GLOBALS['app']->ACL->Set($key, $valueString);
-                    }
-                }
-            }
-            return true;
-        }
-        return new Jaws_Error(_t('USERS_GROUPS_GROUP_NOT_EXIST'), _t('USERS_NAME'));
-    }
-
-    /**
-     * Save user config settings
-     *
-     * @access  public
-     * @param   string  $method     Authentication method
-     * @param   string  $anon       Anonymous users can auto-register
-     * @param   string  $repetitive Anonymous can register by repetitive email
-     * @param   string  $act        Activation type
-     * @param   integer $type       User's type
-     * @param   integer $group      Default group of anonymous registered user
-     * @param   string  $recover    Users can recover their passwords
-     * @return  boolean Success/Failure
-     */
-    function SaveSettings($method, $anon, $repetitive, $act, $group, $recover)
-    {
-        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
-
-        $method     = $xss->parse($method);
-        $anon       = $xss->parse($anon);
-        $repetitive = $xss->parse($repetitive);
-        $recover    = $xss->parse($recover);
-
-        $res = true;
-        if ($GLOBALS['app']->Session->GetPermission('Users', 'ManageAuthenticationMethod')) {
-            $methods = Jaws::getAuthMethods();
-            if ($methods !== false && in_array($method, $methods)) {
-                $res = $GLOBALS['app']->Registry->Set('/config/auth_method', $method);
-            }
-        }
-        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_register', $anon);
-        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_repetitive_email', $repetitive);
-        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_activation', $act);
-        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_group', (int)$group);
-        $res = $res && $GLOBALS['app']->Registry->Set('/gadgets/Users/password_recovery', $recover);
-        if ($res) {
-            $GLOBALS['app']->Registry->Commit('Users');
-            $GLOBALS['app']->Registry->Commit('core');
-            $GLOBALS['app']->ACL->Commit('core');
-            return true;
-        }
-
-        return new Jaws_Error(_t('USERS_PROPERTIES_CANT_UPDATE'), _t('USERS_NAME'));
-    }
-
-    /**
-     * Add a group of user (by they ids) to a certain group
-     *
-     * @access  public
-     * @param   int     $guid  Group's ID
-     * @param   array   $users Array with user id
-     * @return  array   Response (notice or error)
-     */
-    function AddUsersToGroup($guid, $users)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $userModel = new Jaws_User();
-
-        $group = $userModel->GetGroupInfoById($guid);
-        if (!$group) {
-            return new Jaws_Error(_t('USERS_GROUPS_GROUP_NOT_EXIST'), _t('USERS_NAME'));
-        }
-
-        $postedUsers = array();
-        foreach ($users as $k => $v) {
-            $postedUsers[$v] = $v;
-        }
-
-        $list = $userModel->GetUsers();
-        foreach ($list as $user) {
-            if ($userModel->UserIsInGroup($user['id'], $guid)) {
-                if (!isset($postedUsers[$user['id']])) {
-                    if (!$GLOBALS['app']->Session->IsSuperAdmin() && $user['superadmin']) {
-                        continue;
-                    }
-                    $userModel->DeleteUserFromGroup($user['id'], $guid);
-                }
-            } else {
-                if (isset($postedUsers[$user['id']])) {
-                    $userModel->AddUserToGroup($user['id'], $guid);
-
-                }
-            }
-        }
-        return true;
-    }
-
 }
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/Account.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/Account.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/Account.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,111 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @package    Users
+ * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2006-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersModel_Account extends Jaws_Model
+{
+    /**
+     * Updates the profile of an user
+     *
+     * @access  public
+     * @param   int      $uid       User's ID
+     * @param   string   $username  Username
+     * @param   string   $email     User's email
+     * @param   string   $nickname     User's display name
+     * @param   string   $password  Password
+     * @return  mixed    True (Success) or Jaws_Error (failure)
+     */
+    function UpdateAccount($uid, $username, $email, $nickname, $password)
+    {
+        if (trim($nickname) == '' || trim($email) == '')
+        {
+            return new Jaws_Error(_t('USERS_USERS_INCOMPLETE_FIELDS'), _t('USERS_NAME'));
+        }
+
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $jUser  = new Jaws_User;
+        $result = $jUser->UpdateUser($uid,
+                                     $username,
+                                     $nickname,
+                                     $email,
+                                     $password);
+        return $result;
+    }
+
+    /**
+     * Changes a password from a given key
+     *
+     * @access  public
+     * @param   string   $key   Recovery key
+     * @return  boolean
+     */
+    function ChangePassword($key)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+
+        $jUser = new Jaws_User;
+        if ($id = $jUser->GetIDByVerificationKey($key)) {
+            $info = $jUser->GetUser((int)$id);
+
+            include_once 'Text/Password.php';
+            $password = Text_Password::create(8, 'pronounceable', 'alphanumeric');
+
+            $res = $jUser->UpdateVerificationKey($id);
+            if (Jaws_Error::IsError($res)) {
+                return $res;
+            }
+
+            $res = $jUser->UpdateUser($id,
+                                      $info['username'],
+                                      $info['nickname'],
+                                      $info['email'],
+                                      $password);
+            if (Jaws_Error::IsError($res)) {
+                return $res;
+            }
+
+            $site_url  = $GLOBALS['app']->getSiteURL('/');
+            $site_name = $GLOBALS['app']->Registry->Get('/config/site_name');
+
+            $tpl = new Jaws_Template('gadgets/Users/templates/');
+            $tpl->Load('NewPassword.txt');
+            $tpl->SetBlock('NewPassword');
+            $tpl->SetVariable('username', $info['username']);
+            $tpl->SetVariable('nickname', $info['nickname']);
+            $tpl->SetVariable('password', $password);
+            $tpl->SetVariable('message',  _t('USERS_FORGOT_PASSWORD_CHANGED_MESSAGE', $info['username']));
+            $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD'));
+            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
+            $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
+            $tpl->SetVariable('site-name', $site_name);
+            $tpl->SetVariable('site-url',  $site_url);
+            $tpl->ParseBlock('NewPassword');
+
+            $message = $tpl->Get();            
+            $subject = _t('USERS_FORGOT_PASSWORD_CHANGED_SUBJECT');
+
+            require_once JAWS_PATH . 'include/Jaws/Mail.php';
+            $mail = new Jaws_Mail;
+            $mail->SetFrom();
+            $mail->AddRecipient($info['email']);
+            $mail->SetSubject($subject);
+            $mail->SetBody(Jaws_Gadget::ParseText($message, 'Users'));
+            $mresult = $mail->send();
+            if (Jaws_Error::IsError($mresult)) {
+                return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
+            } else {
+                return true;
+            }
+        } else {
+            return new Jaws_Error(_t('USERS_FORGOT_KEY_NOT_VALID'));
+        }
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/GroupACL.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/GroupACL.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/GroupACL.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @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 UsersAdminModel_GroupACL extends Jaws_Model
+{
+    /**
+     * Returns an array with the ACL keys of a given group
+     *
+     * @access  public
+     * @param   int     $guid   Group's ID
+     * @return  array   Array with ACL Keys
+     */
+    function GetGroupACLKeys($guid)
+    {
+        $acls = $GLOBALS['app']->ACL->GetGroupAclPermissions($guid);
+        $perms = array();
+        if (is_array($acls)) {
+            foreach ($acls as $gadget => $keys) {
+                if (!Jaws_Gadget::IsGadgetUpdated($gadget)) {
+                    continue;
+                }
+
+                $g = $GLOBALS['app']->LoadGadget($gadget, 'Info');
+                if (Jaws_Error::IsError($g)) {
+                    continue;
+                }
+
+                if (!isset($perms[$gadget])) {
+                    $perms[$gadget] = array();
+                    $perms[$gadget]['name'] = _t(strtoupper($gadget).'_NAME');
+                }
+
+                foreach ($keys as $k) {
+                    $aclkey = '/ACL'.str_replace('/ACL/groups/'.$guid, '', $k['name']);
+                    $perms[$gadget][$aclkey] = array(
+                        'desc'  => $g->GetACLDescription($aclkey),
+                        'value' => $k['value'],
+                        'name'  => $k['name'],
+                    );
+                }
+            }
+
+            ksort($perms);
+            return $perms;
+        }
+
+        return false;
+    }
+
+    /**
+     * Saves only the modified ACL group keys
+     *
+     * @access  public
+     * @param   int     $guid   Group ID
+     * @param   array   $keys   ACL Keys
+     */
+    function UpdateGroupACL($guid, $keys)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $userModel = new Jaws_User();
+
+        if ($group = $userModel->GetGroupInfoById($guid)) {
+            $GLOBALS['app']->ACL->LoadAllFiles();
+            $GLOBALS['app']->ACL->LoadKeysOf($guid, 'groups');
+            foreach ($keys as $key => $value) {
+                if (is_null($value)) {
+                    $GLOBALS['app']->ACL->DeleteKey($key);
+                } else {
+                    $valueString = ($value === true)? 'true' : 'false';
+                    if (is_null($GLOBALS['app']->ACL->Get($key))) {
+                        $GLOBALS['app']->ACL->NewKey($key, $valueString);
+                    } else {
+                        $GLOBALS['app']->ACL->Set($key, $valueString);
+                    }
+                }
+            }
+            return true;
+        }
+        return new Jaws_Error(_t('USERS_GROUPS_GROUP_NOT_EXIST'), _t('USERS_NAME'));
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/Personal.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/Personal.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/Personal.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @package    Users
+ * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2006-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersModel_Personal extends Jaws_Model
+{
+    /**
+     * Updates the profile of an user
+     *
+     * @access  public
+     * @param   int      $uid       User's ID
+     * @param   string   $username  Username
+     * @param   string   $nickname     User's display name
+     * @param   string   $fname     First name
+     * @param   string   $lname     Last name
+     * @param   string   $email     User's email
+     * @param   string   $url       User's url
+     * @param   string   $password  Password
+     * @param   boolean  $uppass    Really updte the user password?
+     * @return  mixed    True (Success) or Jaws_Error (failure)
+     */
+    function UpdatePersonal($uid, $fname, $lname, $gender, $dob, $url)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $jUser = new Jaws_User;
+        $pInfo = array('fname'  => $fname,
+                       'lname'  => $lname,
+                       'gender' => $gender,
+                       'dob'    => $dob,
+                       'url'    => $url);
+
+        $result = $jUser->UpdatePersonalInfo($uid, $pInfo);
+        return $result;
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/Preferences.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/Preferences.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/Preferences.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @package    Users
+ * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2006-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersModel_Preferences extends Jaws_Model
+{
+    /**
+     * Updates the profile of an user
+     *
+     * @access  public
+     * @param   int      $uid       User's ID
+     * @param   string   $username  Username
+     * @param   string   $name      User's real name
+     * @param   string   $email     User's email
+     * @param   string   $url       User's url
+     * @param   string   $password  Password
+     * @param   boolean  $uppass    Really updte the user password?
+     * @return  mixed    True (Success) or Jaws_Error (failure)
+     */
+    function UpdatePreferences($uid, $language, $theme, $editor, $timezone)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $jUser    = new Jaws_User;
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+        $result = $jUser->UpdateAdvancedOptions($uid, array('language' => $language, 
+                                                            'theme' => $theme, 
+                                                            'editor' => $editor, 
+                                                            'timezone' => $timezone)); 
+        //TODO: catch error
+        return $result;
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/Registration.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/Registration.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/Registration.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,373 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @package    Users
+ * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2006-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class UsersModel_Registration extends Jaws_Model
+{
+    /**
+     * Creates a valid(registered) n user for an anonymous user
+     *
+     * @access  public
+     * @param   string  $username   Username
+     * @param   string  $email      User's email
+     * @param   string  $nickname   User's display name
+     * @param   string  $password   Password
+     * @param   string  $p_check    Password check (to verify)
+     * @param   string  $group      Default user group
+     * @return  boolean Success/Failure
+     */
+    function CreateUser($username, $user_email, $nickname, $fname, $lname, $gender, $dob, $url,
+                        $password, $group = null)
+    {
+        if (empty($username) || empty($nickname) || empty($user_email))
+        {
+            return _t('USERS_USERS_INCOMPLETE_FIELDS');
+        }
+
+        $random = false;
+        if (trim($password) == '') {
+            $random = true;
+            include_once 'Text/Password.php';
+            $password = Text_Password::create(8, 'pronounceable', 'alphanumeric');
+        }
+
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $jUser = new Jaws_User;
+
+        //We already have a $username in the DB?
+        $info = $jUser->GetUser($username);
+        if (Jaws_Error::IsError($info) || isset($info['username'])) {
+            return _t('USERS_USERS_ALREADY_EXISTS', $xss->filter($username));
+        }
+
+        if ($GLOBALS['app']->Registry->Get('/config/anon_repetitive_email') == 'false') {
+            if ($jUser->UserEmailExists($user_email)) {
+                return _t('USERS_EMAIL_ALREADY_EXISTS', $xss->filter($user_email));
+            }
+        }
+
+        $user_enabled = ($GLOBALS['app']->Registry->Get('/config/anon_activation') == 'auto')? 1 : 2;
+        $user_id = $jUser->AddUser($username,
+                                   $xss->filter($nickname),
+                                   $user_email,
+                                   $password,
+                                   false,
+                                   $user_enabled);
+        if (Jaws_Error::IsError($user_id)) {
+            return $user_id->getMessage();
+        }
+
+        $pInfo = array('fname'  => $fname,
+                       'lname'  => $lname,
+                       'gender' => $gender,
+                       'dob'    => $dob,
+                       'url'    => $url);
+
+        $result = $jUser->UpdatePersonalInfo($user_id, $pInfo);
+        if ($result === false) {
+            //do nothing
+        }
+
+        if (!is_null($group) && is_numeric($group)) {
+            $jUser->AddUserToGroup($user_id, $group);
+        }
+
+        require_once JAWS_PATH . 'include/Jaws/Mail.php';
+        $mail = new Jaws_Mail;
+
+        $site_url     = $GLOBALS['app']->getSiteURL('/');
+        $site_name    = $GLOBALS['app']->Registry->Get('/config/site_name');
+        $site_author  = $GLOBALS['app']->Registry->Get('/config/site_author');
+        $activation   = $GLOBALS['app']->Registry->Get('/config/anon_activation');
+        $notification = $GLOBALS['app']->Registry->Get('/gadgets/Users/register_notification');
+        $delete_user  = false;
+        $message      = '';
+
+        if ($random === true || $activation != 'admin') {
+            $tpl = new Jaws_Template('gadgets/Users/templates/');
+            $tpl->Load('UserNotification.txt');
+            $tpl->SetBlock('Notification');
+            $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $xss->filter($nickname)));
+
+            if ($random === true) {
+                switch ($activation) {
+                    case 'admin':
+                        $tpl->SetVariable('message', _t('USERS_REGISTER_BY_ADMIN_RANDOM_MAIL_MSG'));
+                        break;
+
+                    case 'user':
+                        $tpl->SetVariable('message', _t('USERS_REGISTER_BY_USER_RANDOM_MAIL_MSG'));
+                        break;
+
+                    default:
+                        $tpl->SetVariable('message', _t('USERS_REGISTER_RANDOM_MAIL_MSG'));
+                        
+                }
+
+                $tpl->SetBlock('Notification/Password');
+                $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD'));
+                $tpl->SetVariable('password', $xss->filter($password));
+                $tpl->ParseBlock('Notification/Password');
+            } elseif ($activation == 'user') {
+                $tpl->SetVariable('message', _t('USERS_REGISTER_ACTIVATION_MAIL_MSG'));
+            } else {
+                $tpl->SetVariable('message', _t('USERS_REGISTER_MAIL_MSG'));
+            }
+
+            $tpl->SetBlock('Notification/IP');
+            $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
+            $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
+            $tpl->ParseBlock('Notification/IP');
+
+            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
+            $tpl->SetVariable('username', $xss->filter($username));
+
+            if ($activation == 'user') {
+                $secretKey = md5(uniqid(rand(), true)) . time() . floor(microtime()*1000);
+                $result = $jUser->UpdateVerificationKey($user_id, $secretKey);
+                if ($result === true) {
+                    $tpl->SetBlock('Notification/Activation');
+                    $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK'));
+                    $tpl->SetVariable('activation_link',
+                                      $GLOBALS['app']->Map->GetURLFor('Users', 'ActivateUser',
+                                                                      array('key' => $secretKey), true, 'site_url'));
+                    $tpl->ParseBlock('Notification/Activation');
+                } else {
+                    $delete_user = true;
+                    $message = _t('GLOBAL_ERROR_QUERY_FAILED');
+                }
+            }
+
+            $tpl->SetVariable('thanks',    _t('GLOBAL_THANKS'));
+            $tpl->SetVariable('site-name', $site_name);
+            $tpl->SetVariable('site-url',  $site_url);
+
+            $tpl->ParseBlock('Notification');
+            $body = $tpl->Get();
+
+            if (!$delete_user) {
+                $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
+                $mail->SetFrom();
+                $mail->AddRecipient($user_email);
+                $mail->SetSubject($subject);
+                $mail->SetBody(Jaws_Gadget::ParseText($body, 'Users'));
+                $mresult = $mail->send();
+                if (Jaws_Error::IsError($mresult)) {
+                    if ($activation == 'user') {
+                        $delete_user = true;
+                        $message = _t('USERS_REGISTER_ACTIVATION_SENDMAIL_FAILED', $xss->filter($user_email));
+                    } elseif ($random === true) {
+                        $delete_user = true;
+                        $message = _t('USERS_REGISTER_RANDOM_SENDMAIL_FAILED', $xss->filter($user_email));
+                    }
+                }
+            }
+        }
+
+        //Send an email to website owner
+        $mail->ResetValues();
+        if (!$delete_user && ($notification == 'true' || $activation == 'admin')) {
+            $tpl = new Jaws_Template('gadgets/Users/templates/');
+            $tpl->Load('AdminNotification.txt');
+            $tpl->SetBlock('Notification');
+            $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $site_author));
+            $tpl->SetVariable('message', _t('USERS_REGISTER_ADMIN_MAIL_MSG'));
+            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
+            $tpl->SetVariable('username', $xss->filter($username));
+            $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME'));
+            $tpl->SetVariable('nickname', $xss->filter($nickname));
+            $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL'));
+            $tpl->SetVariable('email', $xss->filter($user_email));
+            $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
+            $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
+            if ($activation == 'admin') {
+                $secretKey = md5(uniqid(rand(), true)) . time() . floor(microtime()*1000);
+                $result = $jUser->UpdateVerificationKey($user_id, $secretKey);
+                if ($result === true) {
+                    $tpl->SetBlock('Notification/Activation');
+                    $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK'));
+                    $tpl->SetVariable('activation_link', $GLOBALS['app']->Map->GetURLFor('Users', 'ActivateUser',
+                                                                array('key' => $secretKey), true, 'site_url'));
+                    $tpl->ParseBlock('Notification/Activation');
+                }
+            }
+            $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
+            $tpl->SetVariable('site-name', $site_name);
+            $tpl->SetVariable('site-url', $site_url);
+            $tpl->ParseBlock('Notification');
+            $body = $tpl->Get();
+
+            if (!$delete_user) {
+                $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
+                $mail->SetFrom();
+                $mail->AddRecipient();
+                $mail->SetSubject($subject);
+                $mail->SetBody(Jaws_Gadget::ParseText($body, 'Users'));
+                $mresult = $mail->send();
+                if (Jaws_Error::IsError($mresult) && $activation == 'admin') {
+                    // do nothing
+                    //$delete_user = true;
+                    //$message = _t('USERS_ACTIVATE_NOT_ACTIVATED_SENDMAIL', $xss->filter($user_email));
+                }
+            }
+        }
+
+        if ($delete_user) {
+            $jUser->DeleteUser($user_id);
+            return $message;
+        }
+
+        return true;
+    }
+
+    /**
+     * Checks if user/email are valid, if they are generates a recovery secret
+     * key and sends it to the user
+     *
+     * @access  public
+     * @param   string  $user_email Email
+     * @return  boolean Success/Failure
+     */
+    function SendRecoveryKey($user_email)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $userModel = new Jaws_User;
+        $uInfos = $userModel->GetUserInfoByEmail($user_email);
+        if (Jaws_Error::IsError($uInfos)) {
+            return $uInfos;
+        }
+
+        if (empty($uInfos)) {
+            return new Jaws_Error(_t('USERS_USER_NOT_EXIST'));                
+        }
+
+        foreach($uInfos as $info) {
+            $secretKey = md5(uniqid(rand(), true)) . time() . floor(microtime()*1000);
+            $result = $userModel->UpdateVerificationKey($info['id'], $secretKey);
+            if ($result === true) {
+                $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+
+                $site_url    = $GLOBALS['app']->getSiteURL('/');
+                $site_name   = $GLOBALS['app']->Registry->Get('/config/site_name');
+
+                $tpl = new Jaws_Template('gadgets/Users/templates/');
+                $tpl->Load('RecoverPassword.txt');
+                $tpl->SetBlock('RecoverPassword');
+                $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
+                $tpl->SetVariable('username', $xss->filter($info['username']));
+                $tpl->SetVariable('nickname', $xss->filter($info['nickname']));
+                $tpl->SetVariable('message', _t('USERS_FORGOT_MAIL_MESSAGE'));
+                $tpl->SetVariable('lbl_url', _t('GLOBAL_URL'));
+                $tpl->SetVariable('url',
+                                  $GLOBALS['app']->Map->GetURLFor('Users', 'ChangePassword',
+                                                                  array('key' => $secretKey), true, 'site_url'));
+                $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
+                $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
+                $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
+                $tpl->SetVariable('site-name', $site_name);
+                $tpl->SetVariable('site-url', $site_url);
+                $tpl->ParseBlock('RecoverPassword');
+
+                $message = $tpl->Get();            
+                $subject = _t('USERS_FORGOT_REMEMBER', $site_name);
+
+                require_once JAWS_PATH . 'include/Jaws/Mail.php';
+                $mail = new Jaws_Mail;
+                $mail->SetFrom();
+                $mail->AddRecipient($user_email);
+                $mail->SetSubject($subject);
+                $mail->SetBody(Jaws_Gadget::ParseText($message, 'Users'));
+                $mresult = $mail->send();
+                if (Jaws_Error::IsError($mresult)) {
+                    return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
+                } else {
+                    return true;
+                }
+            } else {
+                return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
+            }
+        }
+    }
+
+    /**
+     * Changes a enabled from a given key
+     *
+     * @access  public
+     * @param   string   $key   Recovery key
+     * @return  boolean
+     */
+    function ActivateUser($key)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        
+        $jUser = new Jaws_User;
+        if ($id = $jUser->GetIDByVerificationKey($key)) {
+            $info = $jUser->GetUser((int)$id);
+
+            $res = $jUser->UpdateVerificationKey($id);
+            if (Jaws_Error::IsError($res)) {
+                return $res;
+            }
+
+            $res = $jUser->UpdateUser($id,
+                                       $info['username'],
+                                       $info['nickname'],
+                                       $info['email'],
+                                       null, // password
+                                       null, // superadmin
+                                       1);
+            if (Jaws_Error::IsError($res)) {
+                return $res;
+            }
+
+            $site_url  = $GLOBALS['app']->getSiteURL('/');
+            $site_name = $GLOBALS['app']->Registry->Get('/config/site_name');
+
+            $tpl = new Jaws_Template('gadgets/Users/templates/');
+            $tpl->Load('UserNotification.txt');
+            $tpl->SetBlock('Notification');
+            $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $info['nickname']));
+            $tpl->SetVariable('message', _t('USERS_ACTIVATE_ACTIVATED_MAIL_MSG'));
+            if ($GLOBALS['app']->Registry->Get('/config/anon_activation') == 'user') {
+                $tpl->SetBlock('Notification/IP');
+                $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
+                $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
+                $tpl->ParseBlock('Notification/IP');
+            }
+
+            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
+            $tpl->SetVariable('username', $info['username']);
+
+            $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
+            $tpl->SetVariable('site-name', $site_name);
+            $tpl->SetVariable('site-url', $site_url);
+            $tpl->ParseBlock('Notification');
+
+            $body = $tpl->Get();
+            $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
+
+            require_once JAWS_PATH . 'include/Jaws/Mail.php';
+            $mail = new Jaws_Mail;
+            $mail->SetFrom();
+            $mail->AddRecipient($info['email']);
+            $mail->SetSubject($subject);
+            $mail->SetBody(Jaws_Gadget::ParseText($body, 'Users'));
+            $mresult = $mail->send();
+            if (Jaws_Error::IsError($mresult)) {
+                // do nothing
+            }
+            return true;
+        } else {
+            return new Jaws_Error(_t('USERS_ACTIVATION_KEY_NOT_VALID'));
+        }
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/Settings.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/Settings.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/Settings.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @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 UsersAdminModel_Settings extends Jaws_Model
+{
+    /**
+     * Save user config settings
+     *
+     * @access  public
+     * @param   string  $method     Authentication method
+     * @param   string  $anon       Anonymous users can auto-register
+     * @param   string  $repetitive Anonymous can register by repetitive email
+     * @param   string  $act        Activation type
+     * @param   integer $type       User's type
+     * @param   integer $group      Default group of anonymous registered user
+     * @param   string  $recover    Users can recover their passwords
+     * @return  boolean Success/Failure
+     */
+    function SaveSettings($method, $anon, $repetitive, $act, $group, $recover)
+    {
+        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
+
+        $method     = $xss->parse($method);
+        $anon       = $xss->parse($anon);
+        $repetitive = $xss->parse($repetitive);
+        $recover    = $xss->parse($recover);
+
+        $res = true;
+        if ($GLOBALS['app']->Session->GetPermission('Users', 'ManageAuthenticationMethod')) {
+            $methods = Jaws::getAuthMethods();
+            if ($methods !== false && in_array($method, $methods)) {
+                $res = $GLOBALS['app']->Registry->Set('/config/auth_method', $method);
+            }
+        }
+        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_register', $anon);
+        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_repetitive_email', $repetitive);
+        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_activation', $act);
+        $res = $res && $GLOBALS['app']->Registry->Set('/config/anon_group', (int)$group);
+        $res = $res && $GLOBALS['app']->Registry->Set('/gadgets/Users/password_recovery', $recover);
+        if ($res) {
+            $GLOBALS['app']->Registry->Commit('Users');
+            $GLOBALS['app']->Registry->Commit('core');
+            $GLOBALS['app']->ACL->Commit('core');
+            return true;
+        }
+
+        return new Jaws_Error(_t('USERS_PROPERTIES_CANT_UPDATE'), _t('USERS_NAME'));
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/UserACL.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/UserACL.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/UserACL.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,109 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @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 UsersAdminModel_UserACL extends Jaws_Model
+{
+    /**
+     * Get ACL permissions of a given user
+     *
+     * @access  public
+     * @param   string  $username  Username
+     * @return  array   Array with ACL Keys
+     */
+    function GetUserACLKeys($username)
+    {
+        $acls = $GLOBALS['app']->ACL->GetAclPermissions($username, false);
+        $perms = array();
+        if (is_array($acls)) {
+            foreach ($acls as $gadget => $keys) {
+                $g = $GLOBALS['app']->LoadGadget($gadget, 'Info');
+                if (Jaws_Error::IsError($g)) {
+                    continue;
+                }
+
+                if (!Jaws_Gadget::IsGadgetUpdated($gadget)) {
+                    continue;
+                }
+
+                if (!isset($perms[$gadget])) {
+                    $perms[$gadget] = array();
+                    $perms[$gadget]['name'] = _t(strtoupper($gadget).'_NAME');
+                }
+
+                foreach ($keys as $k) {
+                    $aclkey = '/ACL'.str_replace('/ACL/users/'.$username, '', $k['name']);
+
+                    $perms[$gadget][$aclkey] = array(
+                        'desc'  => $g->GetACLDescription($aclkey),
+                        'value' => $k['value'],
+                        'name'  => $k['name'],
+                    );
+                }
+            }
+
+            ksort($perms);
+            return $perms;
+        }
+
+        return false;
+    }
+
+    /**
+     * Saves only the modified ACL user keys
+     *
+     * @access  public
+     * @param   int     $uid    User' ID
+     * @param   array   $keys   ACL Keys
+     * @return  boolean Success/Failure(Jaws_Error)
+     */
+    function UpdateUserACL($uid, $keys)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $userModel = new Jaws_User();
+        $currentUser = $GLOBALS['app']->Session->GetAttribute('user');
+        if ($user = $userModel->GetUser((int)$uid)) {
+            //Load user keys
+            $GLOBALS['app']->ACL->LoadAllFiles();
+            $GLOBALS['app']->ACL->LoadKeysOf($user['username'], 'users');
+            foreach($keys as $key => $value) {
+                //check user permission for this key
+                $expkey = explode('/', $key);
+                $aclkey = end($expkey);
+                $gadget = prev($expkey);
+                if (!$GLOBALS['app']->Session->GetPermission($gadget, $aclkey)) {
+                    continue;
+                }
+
+                //Get the current value
+                if ($key == '/ACL/users/' . $user['username'] . '/gadgets/ControlPanel/default' &&
+                    $value === false && $uid == $currentUser)
+                {
+                    return new Jaws_Error(_t('USERS_USERS_CANT_AUTO_TURN_OFF_CP'), _t('USERS_NAME'));
+                }
+
+                if (is_null($value)) {
+                    $GLOBALS['app']->ACL->DeleteKey($key);
+                } else {
+                    $valueString = ($value === true)? 'true' : 'false';
+                    if (is_null($GLOBALS['app']->ACL->Get($key))) {
+                        $GLOBALS['app']->ACL->NewKey($key, $valueString);
+                    } else {
+                        $GLOBALS['app']->ACL->Set($key, $valueString);
+                    }
+                }
+            }
+            return true;
+        }
+
+        return new Jaws_Error(_t('USERS_USER_NOT_EXIST'), _t('USERS_NAME'));
+    }
+
+}
\ No newline at end of file

Added: trunk/jaws/html/gadgets/Users/Model/UsersGroup.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model/UsersGroup.php	                        (rev 0)
+++ trunk/jaws/html/gadgets/Users/Model/UsersGroup.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Users Core Gadget
+ *
+ * @category   GadgetModel
+ * @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 UsersAdminModel_UsersGroup extends Jaws_Model
+{
+    /**
+     * Add a group of user (by they ids) to a certain group
+     *
+     * @access  public
+     * @param   int     $guid  Group's ID
+     * @param   array   $users Array with user id
+     * @return  array   Response (notice or error)
+     */
+    function AddUsersToGroup($guid, $users)
+    {
+        require_once JAWS_PATH . 'include/Jaws/User.php';
+        $userModel = new Jaws_User();
+
+        $group = $userModel->GetGroupInfoById($guid);
+        if (!$group) {
+            return new Jaws_Error(_t('USERS_GROUPS_GROUP_NOT_EXIST'), _t('USERS_NAME'));
+        }
+
+        $postedUsers = array();
+        foreach ($users as $k => $v) {
+            $postedUsers[$v] = $v;
+        }
+
+        $list = $userModel->GetUsers();
+        foreach ($list as $user) {
+            if ($userModel->UserIsInGroup($user['id'], $guid)) {
+                if (!isset($postedUsers[$user['id']])) {
+                    if (!$GLOBALS['app']->Session->IsSuperAdmin() && $user['superadmin']) {
+                        continue;
+                    }
+                    $userModel->DeleteUserFromGroup($user['id'], $guid);
+                }
+            } else {
+                if (isset($postedUsers[$user['id']])) {
+                    $userModel->AddUserToGroup($user['id'], $guid);
+
+                }
+            }
+        }
+        return true;
+    }
+
+}
\ No newline at end of file

Modified: trunk/jaws/html/gadgets/Users/Model.php
===================================================================
--- trunk/jaws/html/gadgets/Users/Model.php	2012-08-12 22:46:11 UTC (rev 13399)
+++ trunk/jaws/html/gadgets/Users/Model.php	2012-08-12 22:47:26 UTC (rev 13400)
@@ -12,514 +12,5 @@
 class UsersModel extends Jaws_Model
 {
     /**
-     * Creates a valid(registered) n user for an anonymous user
-     *
-     * @access  public
-     * @param   string  $username   Username
-     * @param   string  $email      User's email
-     * @param   string  $nickname   User's display name
-     * @param   string  $password   Password
-     * @param   string  $p_check    Password check (to verify)
-     * @param   string  $group      Default user group
-     * @return  boolean Success/Failure
      */
-    function CreateUser($username, $user_email, $nickname, $fname, $lname, $gender, $dob, $url,
-                        $password, $group = null)
-    {
-        if (empty($username) || empty($nickname) || empty($user_email))
-        {
-            return _t('USERS_USERS_INCOMPLETE_FIELDS');
-        }
-
-        $random = false;
-        if (trim($password) == '') {
-            $random = true;
-            include_once 'Text/Password.php';
-            $password = Text_Password::create(8, 'pronounceable', 'alphanumeric');
-        }
-
-        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $jUser = new Jaws_User;
-
-        //We already have a $username in the DB?
-        $info = $jUser->GetUser($username);
-        if (Jaws_Error::IsError($info) || isset($info['username'])) {
-            return _t('USERS_USERS_ALREADY_EXISTS', $xss->filter($username));
-        }
-
-        if ($GLOBALS['app']->Registry->Get('/config/anon_repetitive_email') == 'false') {
-            if ($jUser->UserEmailExists($user_email)) {
-                return _t('USERS_EMAIL_ALREADY_EXISTS', $xss->filter($user_email));
-            }
-        }
-
-        $user_enabled = ($GLOBALS['app']->Registry->Get('/config/anon_activation') == 'auto')? 1 : 2;
-        $user_id = $jUser->AddUser($username,
-                                   $xss->filter($nickname),
-                                   $user_email,
-                                   $password,
-                                   false,
-                                   $user_enabled);
-        if (Jaws_Error::IsError($user_id)) {
-            return $user_id->getMessage();
-        }
-
-        $pInfo = array('fname'  => $fname,
-                       'lname'  => $lname,
-                       'gender' => $gender,
-                       'dob'    => $dob,
-                       'url'    => $url);
-
-        $result = $jUser->UpdatePersonalInfo($user_id, $pInfo);
-        if ($result === false) {
-            //do nothing
-        }
-
-        if (!is_null($group) && is_numeric($group)) {
-            $jUser->AddUserToGroup($user_id, $group);
-        }
-
-        require_once JAWS_PATH . 'include/Jaws/Mail.php';
-        $mail = new Jaws_Mail;
-
-        $site_url     = $GLOBALS['app']->getSiteURL('/');
-        $site_name    = $GLOBALS['app']->Registry->Get('/config/site_name');
-        $site_author  = $GLOBALS['app']->Registry->Get('/config/site_author');
-        $activation   = $GLOBALS['app']->Registry->Get('/config/anon_activation');
-        $notification = $GLOBALS['app']->Registry->Get('/gadgets/Users/register_notification');
-        $delete_user  = false;
-        $message      = '';
-
-        if ($random === true || $activation != 'admin') {
-            $tpl = new Jaws_Template('gadgets/Users/templates/');
-            $tpl->Load('UserNotification.txt');
-            $tpl->SetBlock('Notification');
-            $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $xss->filter($nickname)));
-
-            if ($random === true) {
-                switch ($activation) {
-                    case 'admin':
-                        $tpl->SetVariable('message', _t('USERS_REGISTER_BY_ADMIN_RANDOM_MAIL_MSG'));
-                        break;
-
-                    case 'user':
-                        $tpl->SetVariable('message', _t('USERS_REGISTER_BY_USER_RANDOM_MAIL_MSG'));
-                        break;
-
-                    default:
-                        $tpl->SetVariable('message', _t('USERS_REGISTER_RANDOM_MAIL_MSG'));
-                        
-                }
-
-                $tpl->SetBlock('Notification/Password');
-                $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD'));
-                $tpl->SetVariable('password', $xss->filter($password));
-                $tpl->ParseBlock('Notification/Password');
-            } elseif ($activation == 'user') {
-                $tpl->SetVariable('message', _t('USERS_REGISTER_ACTIVATION_MAIL_MSG'));
-            } else {
-                $tpl->SetVariable('message', _t('USERS_REGISTER_MAIL_MSG'));
-            }
-
-            $tpl->SetBlock('Notification/IP');
-            $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
-            $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
-            $tpl->ParseBlock('Notification/IP');
-
-            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
-            $tpl->SetVariable('username', $xss->filter($username));
-
-            if ($activation == 'user') {
-                $secretKey = md5(uniqid(rand(), true)) . time() . floor(microtime()*1000);
-                $result = $jUser->UpdateVerificationKey($user_id, $secretKey);
-                if ($result === true) {
-                    $tpl->SetBlock('Notification/Activation');
-                    $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK'));
-                    $tpl->SetVariable('activation_link',
-                                      $GLOBALS['app']->Map->GetURLFor('Users', 'ActivateUser',
-                                                                      array('key' => $secretKey), true, 'site_url'));
-                    $tpl->ParseBlock('Notification/Activation');
-                } else {
-                    $delete_user = true;
-                    $message = _t('GLOBAL_ERROR_QUERY_FAILED');
-                }
-            }
-
-            $tpl->SetVariable('thanks',    _t('GLOBAL_THANKS'));
-            $tpl->SetVariable('site-name', $site_name);
-            $tpl->SetVariable('site-url',  $site_url);
-
-            $tpl->ParseBlock('Notification');
-            $body = $tpl->Get();
-
-            if (!$delete_user) {
-                $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
-                $mail->SetFrom();
-                $mail->AddRecipient($user_email);
-                $mail->SetSubject($subject);
-                $mail->SetBody(Jaws_Gadget::ParseText($body, 'Users'));
-                $mresult = $mail->send();
-                if (Jaws_Error::IsError($mresult)) {
-                    if ($activation == 'user') {
-                        $delete_user = true;
-                        $message = _t('USERS_REGISTER_ACTIVATION_SENDMAIL_FAILED', $xss->filter($user_email));
-                    } elseif ($random === true) {
-                        $delete_user = true;
-                        $message = _t('USERS_REGISTER_RANDOM_SENDMAIL_FAILED', $xss->filter($user_email));
-                    }
-                }
-            }
-        }
-
-        //Send an email to website owner
-        $mail->ResetValues();
-        if (!$delete_user && ($notification == 'true' || $activation == 'admin')) {
-            $tpl = new Jaws_Template('gadgets/Users/templates/');
-            $tpl->Load('AdminNotification.txt');
-            $tpl->SetBlock('Notification');
-            $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $site_author));
-            $tpl->SetVariable('message', _t('USERS_REGISTER_ADMIN_MAIL_MSG'));
-            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
-            $tpl->SetVariable('username', $xss->filter($username));
-            $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME'));
-            $tpl->SetVariable('nickname', $xss->filter($nickname));
-            $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL'));
-            $tpl->SetVariable('email', $xss->filter($user_email));
-            $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
-            $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
-            if ($activation == 'admin') {
-                $secretKey = md5(uniqid(rand(), true)) . time() . floor(microtime()*1000);
-                $result = $jUser->UpdateVerificationKey($user_id, $secretKey);
-                if ($result === true) {
-                    $tpl->SetBlock('Notification/Activation');
-                    $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK'));
-                    $tpl->SetVariable('activation_link', $GLOBALS['app']->Map->GetURLFor('Users', 'ActivateUser',
-                                                                array('key' => $secretKey), true, 'site_url'));
-                    $tpl->ParseBlock('Notification/Activation');
-                }
-            }
-            $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
-            $tpl->SetVariable('site-name', $site_name);
-            $tpl->SetVariable('site-url', $site_url);
-            $tpl->ParseBlock('Notification');
-            $body = $tpl->Get();
-
-            if (!$delete_user) {
-                $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
-                $mail->SetFrom();
-                $mail->AddRecipient();
-                $mail->SetSubject($subject);
-                $mail->SetBody(Jaws_Gadget::ParseText($body, 'Users'));
-                $mresult = $mail->send();
-                if (Jaws_Error::IsError($mresult) && $activation == 'admin') {
-                    // do nothing
-                    //$delete_user = true;
-                    //$message = _t('USERS_ACTIVATE_NOT_ACTIVATED_SENDMAIL', $xss->filter($user_email));
-                }
-            }
-        }
-
-        if ($delete_user) {
-            $jUser->DeleteUser($user_id);
-            return $message;
-        }
-
-        return true;
-    }
-
-    /**
-     * Updates the profile of an user
-     *
-     * @access  public
-     * @param   int      $uid       User's ID
-     * @param   string   $username  Username
-     * @param   string   $email     User's email
-     * @param   string   $nickname     User's display name
-     * @param   string   $password  Password
-     * @return  mixed    True (Success) or Jaws_Error (failure)
-     */
-    function UpdateAccount($uid, $username, $email, $nickname, $password)
-    {
-        if (trim($nickname) == '' || trim($email) == '')
-        {
-            return new Jaws_Error(_t('USERS_USERS_INCOMPLETE_FIELDS'), _t('USERS_NAME'));
-        }
-
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $jUser  = new Jaws_User;
-        $result = $jUser->UpdateUser($uid,
-                                     $username,
-                                     $nickname,
-                                     $email,
-                                     $password);
-        return $result;
-    }
-
-    /**
-     * Updates the profile of an user
-     *
-     * @access  public
-     * @param   int      $uid       User's ID
-     * @param   string   $username  Username
-     * @param   string   $nickname     User's display name
-     * @param   string   $fname     First name
-     * @param   string   $lname     Last name
-     * @param   string   $email     User's email
-     * @param   string   $url       User's url
-     * @param   string   $password  Password
-     * @param   boolean  $uppass    Really updte the user password?
-     * @return  mixed    True (Success) or Jaws_Error (failure)
-     */
-    function UpdateProfile($uid, $fname, $lname, $gender, $dob, $url)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $jUser = new Jaws_User;
-        $pInfo = array('fname'  => $fname,
-                       'lname'  => $lname,
-                       'gender' => $gender,
-                       'dob'    => $dob,
-                       'url'    => $url);
-
-        $result = $jUser->UpdatePersonalInfo($uid, $pInfo);
-        return $result;
-    }
-
-    /**
-     * Updates the profile of an user
-     *
-     * @access  public
-     * @param   int      $uid       User's ID
-     * @param   string   $username  Username
-     * @param   string   $name      User's real name
-     * @param   string   $email     User's email
-     * @param   string   $url       User's url
-     * @param   string   $password  Password
-     * @param   boolean  $uppass    Really updte the user password?
-     * @return  mixed    True (Success) or Jaws_Error (failure)
-     */
-    function UpdatePreferences($uid, $language, $theme, $editor, $timezone)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $jUser    = new Jaws_User;
-        $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
-        $result = $jUser->UpdateAdvancedOptions($uid, array('language' => $language, 
-                                                            'theme' => $theme, 
-                                                            'editor' => $editor, 
-                                                            'timezone' => $timezone)); 
-        //TODO: catch error
-        return $result;
-    }
-
-    /**
-     * Checks if user/email are valid, if they are generates a recovery secret
-     * key and sends it to the user
-     *
-     * @access  public
-     * @param   string  $user_email Email
-     * @return  boolean Success/Failure
-     */
-    function SendRecoveryKey($user_email)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        $userModel = new Jaws_User;
-        $uInfos = $userModel->GetUserInfoByEmail($user_email);
-        if (Jaws_Error::IsError($uInfos)) {
-            return $uInfos;
-        }
-
-        if (empty($uInfos)) {
-            return new Jaws_Error(_t('USERS_USER_NOT_EXIST'));                
-        }
-
-        foreach($uInfos as $info) {
-            $secretKey = md5(uniqid(rand(), true)) . time() . floor(microtime()*1000);
-            $result = $userModel->UpdateVerificationKey($info['id'], $secretKey);
-            if ($result === true) {
-                $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
-
-                $site_url    = $GLOBALS['app']->getSiteURL('/');
-                $site_name   = $GLOBALS['app']->Registry->Get('/config/site_name');
-
-                $tpl = new Jaws_Template('gadgets/Users/templates/');
-                $tpl->Load('RecoverPassword.txt');
-                $tpl->SetBlock('RecoverPassword');
-                $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
-                $tpl->SetVariable('username', $xss->filter($info['username']));
-                $tpl->SetVariable('nickname', $xss->filter($info['nickname']));
-                $tpl->SetVariable('message', _t('USERS_FORGOT_MAIL_MESSAGE'));
-                $tpl->SetVariable('lbl_url', _t('GLOBAL_URL'));
-                $tpl->SetVariable('url',
-                                  $GLOBALS['app']->Map->GetURLFor('Users', 'ChangePassword',
-                                                                  array('key' => $secretKey), true, 'site_url'));
-                $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
-                $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
-                $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
-                $tpl->SetVariable('site-name', $site_name);
-                $tpl->SetVariable('site-url', $site_url);
-                $tpl->ParseBlock('RecoverPassword');
-
-                $message = $tpl->Get();            
-                $subject = _t('USERS_FORGOT_REMEMBER', $site_name);
-
-                require_once JAWS_PATH . 'include/Jaws/Mail.php';
-                $mail = new Jaws_Mail;
-                $mail->SetFrom();
-                $mail->AddRecipient($user_email);
-                $mail->SetSubject($subject);
-                $mail->SetBody(Jaws_Gadget::ParseText($message, 'Users'));
-                $mresult = $mail->send();
-                if (Jaws_Error::IsError($mresult)) {
-                    return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
-                } else {
-                    return true;
-                }
-            } else {
-                return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
-            }
-        }
-    }
-
-    /**
-     * Changes a password from a given key
-     *
-     * @access  public
-     * @param   string   $key   Recovery key
-     * @return  boolean
-     */
-    function ChangePassword($key)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-
-        $jUser = new Jaws_User;
-        if ($id = $jUser->GetIDByVerificationKey($key)) {
-            $info = $jUser->GetUser((int)$id);
-
-            include_once 'Text/Password.php';
-            $password = Text_Password::create(8, 'pronounceable', 'alphanumeric');
-
-            $res = $jUser->UpdateVerificationKey($id);
-            if (Jaws_Error::IsError($res)) {
-                return $res;
-            }
-
-            $res = $jUser->UpdateUser($id,
-                                      $info['username'],
-                                      $info['nickname'],
-                                      $info['email'],
-                                      $password);
-            if (Jaws_Error::IsError($res)) {
-                return $res;
-            }
-
-            $site_url  = $GLOBALS['app']->getSiteURL('/');
-            $site_name = $GLOBALS['app']->Registry->Get('/config/site_name');
-
-            $tpl = new Jaws_Template('gadgets/Users/templates/');
-            $tpl->Load('NewPassword.txt');
-            $tpl->SetBlock('NewPassword');
-            $tpl->SetVariable('username', $info['username']);
-            $tpl->SetVariable('nickname', $info['nickname']);
-            $tpl->SetVariable('password', $password);
-            $tpl->SetVariable('message',  _t('USERS_FORGOT_PASSWORD_CHANGED_MESSAGE', $info['username']));
-            $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD'));
-            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
-            $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
-            $tpl->SetVariable('site-name', $site_name);
-            $tpl->SetVariable('site-url',  $site_url);
-            $tpl->ParseBlock('NewPassword');
-
-            $message = $tpl->Get();            
-            $subject = _t('USERS_FORGOT_PASSWORD_CHANGED_SUBJECT');
-
-            require_once JAWS_PATH . 'include/Jaws/Mail.php';
-            $mail = new Jaws_Mail;
-            $mail->SetFrom();
-            $mail->AddRecipient($info['email']);
-            $mail->SetSubject($subject);
-            $mail->SetBody(Jaws_Gadget::ParseText($message, 'Users'));
-            $mresult = $mail->send();
-            if (Jaws_Error::IsError($mresult)) {
-                return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL'));
-            } else {
-                return true;
-            }
-        } else {
-            return new Jaws_Error(_t('USERS_FORGOT_KEY_NOT_VALID'));
-        }
-    }
-
-    /**
-     * Changes a enabled from a given key
-     *
-     * @access  public
-     * @param   string   $key   Recovery key
-     * @return  boolean
-     */
-    function ActivateUser($key)
-    {
-        require_once JAWS_PATH . 'include/Jaws/User.php';
-        
-        $jUser = new Jaws_User;
-        if ($id = $jUser->GetIDByVerificationKey($key)) {
-            $info = $jUser->GetUser((int)$id);
-
-            $res = $jUser->UpdateVerificationKey($id);
-            if (Jaws_Error::IsError($res)) {
-                return $res;
-            }
-
-            $res = $jUser->UpdateUser($id,
-                                       $info['username'],
-                                       $info['nickname'],
-                                       $info['email'],
-                                       null, // password
-                                       null, // superadmin
-                                       1);
-            if (Jaws_Error::IsError($res)) {
-                return $res;
-            }
-
-            $site_url  = $GLOBALS['app']->getSiteURL('/');
-            $site_name = $GLOBALS['app']->Registry->Get('/config/site_name');
-
-            $tpl = new Jaws_Template('gadgets/Users/templates/');
-            $tpl->Load('UserNotification.txt');
-            $tpl->SetBlock('Notification');
-            $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $info['nickname']));
-            $tpl->SetVariable('message', _t('USERS_ACTIVATE_ACTIVATED_MAIL_MSG'));
-            if ($GLOBALS['app']->Registry->Get('/config/anon_activation') == 'user') {
-                $tpl->SetBlock('Notification/IP');
-                $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP'));
-                $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']);
-                $tpl->ParseBlock('Notification/IP');
-            }
-
-            $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME'));
-            $tpl->SetVariable('username', $info['username']);
-
-            $tpl->SetVariable('thanks', _t('GLOBAL_THANKS'));
-            $tpl->SetVariable('site-name', $site_name);
-            $tpl->SetVariable('site-url', $site_url);
-            $tpl->ParseBlock('Notification');
-
-            $body = $tpl->Get();
-            $subject = _t('USERS_REGISTER_SUBJECT', $site_name);
-
-            require_once JAWS_PATH . 'include/Jaws/Mail.php';
-            $mail = new Jaws_Mail;
-            $mail->SetFrom();
-            $mail->AddRecipient($info['email']);
-            $mail->SetSubject($subject);
-            $mail->SetBody(Jaws_Gadget::ParseText($body, 'Users'));
-            $mresult = $mail->send();
-            if (Jaws_Error::IsError($mresult)) {
-                // do nothing
-            }
-            return true;
-        } else {
-            return new Jaws_Error(_t('USERS_ACTIVATION_KEY_NOT_VALID'));
-        }
-    }
-
 }
\ No newline at end of file



More information about the Jaws-commits mailing list