Overview

Namespaces

  • Cron
  • None

Classes

  • _HtmlGrid_TableOut
  • _TransactionModel_RawSaveOperation
  • AccessControlComponent
  • AccessControlHelper
  • ActionListHelper
  • ActiveDirectoryUtils
  • AddCurrentPidToSchedulingShellCallLogs
  • AnonymousFunctionOperation
  • ArrayUtil
  • AssociationIntegrityBehavior
  • AtomicOperation
  • AuthenticationComponent
  • AuthenticationController
  • AuthenticationUser
  • AutocompleteDatasourceComponent
  • BaseModelComponent
  • Basics
  • CakeLayersHelper
  • CheckAndRunShell
  • ClassSearcher
  • CommandLineUtil
  • CommonValidationBehavior
  • ConfigurableShellCallsSchedulingTask
  • ConfigurationKey
  • ConfigurationKeys
  • ConfigurationKeysController
  • Context
  • ContextComponent
  • ContextHelper
  • Contexts
  • ControllerInspector
  • ControllerMenuHelper
  • CreateJournalingTables
  • CreateTableConfigurationKeys
  • CreateTableSchedulingConfigurableShellCalls
  • CreateTableSchedulingShellCallLogs
  • CreateTableSettedConfigurationKeys
  • CreateTableUserResetPasswordRequests
  • CreateTableUsers
  • CronSchedulingInstaller
  • CronValidationBehavior
  • CssBox
  • CssController
  • CssProperties
  • CssShell
  • CsvUtil
  • CustomDataModel
  • DatasourceDumperManager
  • DateTimeInput
  • DependencyShell
  • DetailHelper
  • DumperShell
  • ExtendedFieldsAccessControl
  • ExtendedFieldSet
  • ExtendedFieldSetHelper
  • ExtendedFieldsParser
  • ExtendedFormHelper
  • ExtendedHasManyAppModel
  • ExtendedOperationsBehavior
  • FieldDefinition
  • FieldRowDefinition
  • FieldSetDefinition
  • FieldSetLayoutHelper
  • FileOperations
  • FileOperations_Rename
  • FileOperations_SymLink
  • FileOperations_Touch
  • FileOperations_Unlink
  • FileSystem
  • FixConfigurationKeysPrimaryKey
  • FixSettedConfigurationKeysPrimaryKey
  • HasManyUtilsBehavior
  • HtmlDocument
  • HtmlGrid
  • HtmlGrid_Cell
  • HttpClient
  • HttpResponse
  • ImapClient
  • ImapMailBox
  • ImapParserShell
  • IncludePath
  • InputMasked
  • InputSearchable
  • InputsOnSubmit
  • InstallShell
  • JenkinsBuildShell
  • Journal
  • JournalDetail
  • JournalizedBehavior
  • JsonResponseComponent
  • LayoutsHelper
  • Ldap
  • LdapUtils
  • ListFieldSet
  • ListFieldSetHelper
  • ListsHelper
  • MailParser
  • Make
  • MenuHelper
  • MigrationAllPluginsShell
  • ModelOperations
  • ModelOperations_Delete
  • ModelOperations_Save
  • ModelTraverser
  • MysqlDumper
  • OpenLdapUtils
  • PaginatorUtilComponent
  • PaginatorUtilComponentFilter
  • PaginatorUtilHelper
  • Plugin
  • PluginManager
  • Reflections
  • RenameEnabledToActiveFromUsersTable
  • RunShellCallShell
  • ScaffoldUtilComponent
  • ScaffoldUtilHelper
  • Scheduling
  • SchedulingConfigurableShellCall
  • SchedulingConfigurableShellCallsController
  • SchedulingShellCallLog
  • SchedulingShellCallLogsController
  • SettedConfigurationKey
  • StuffreposPluginsRename
  • TimeZoneBehavior
  • TransactionModel
  • TransactionOperation
  • Translator
  • TranslatorShell
  • User
  • UserAuthenticationComponent
  • UserChangePassword
  • UserResetPassword
  • UserResetPasswordRequest
  • UserResetPasswordRequestSubmission
  • UsersController
  • ViewUtilHelper

Interfaces

  • AccessControlFilter
  • CommitableOperation
  • DatasourceDumper
  • MakeListener
  • SchedulingInstaller
  • TasksObject
  • UndoableOperation

Exceptions

  • LdapObjectNotWritableException
  • ModelTraverserException
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: App::import('Model', 'LdapUser');
 4: 
 5: class UserChangePassword extends AppModel {
 6: 
 7:     const MIN_PASSWORD_LENGTH = 6;
 8:     const MAX_PASSWORD_LENGTH = 30;
 9: 
10:     var $useTable = false;
11:     var $validate = array(
12:         'user_id' => array(
13:             'rule' => array('userIdValidacao'),
14:             'message' => 'Usuário e/ou requisição não existente',
15:             'required' => true,
16:         ),
17:         'senha_atual' => array(
18:             'rule' => array('senhaAtualValidacao'),
19:             'message' => 'Senha informada não corresponde à atual',
20:             'required' => true,
21:         ),
22:         'nova_senha' => array(
23:             'rule' => array('novaSenhaValidacao'),
24:             'message' => 'Nova senha inválida',
25:             'required' => true,
26:         ),
27:         'confirmacao_senha' => array(
28:             'rule' => array('confirmacaoSenhaValidacao'),
29:             'message' => 'Confirmação não confere com nova senha',
30:             'required' => true,
31:         )
32:     );
33: 
34:     public function __construct($id = false, $table = null, $ds = null) {
35:         parent::__construct($id, $table, $ds);
36:         $this->UserResetPasswordRequest = ClassRegistry::init('Authentication.UserResetPasswordRequest');
37:         $this->AuthenticationUser = ClassRegistry::init('Authentication.AuthenticationUser');
38:     }
39: 
40:     public function save($data = null, $validate = true, $fieldList = array()) {
41:         $this->set($data);
42:         if ($this->validates()) {
43:             $this->AuthenticationUser->changePassword(
44:                     $this->data[$this->alias]['user_id']
45:                     , $this->data[$this->alias]['nova_senha']
46:             );
47:             return true;
48:         }
49:         return false;
50:     }
51: 
52:     public function userIdValidacao($check) {
53:         return $this->_findUser();
54:     }
55: 
56:     public function senhaAtualValidacao($check) {
57:         $user = $this->_findUser();
58:         if (empty($user)) {
59:             return false;
60:         } else {
61:             $senhaAtualHash = Security::hash($check['senha_atual'], null, true);
62:             return $senhaAtualHash == $user['AuthenticationUser']['password'];
63:         }
64:     }
65: 
66:     public function novaSenhaValidacao($check) {
67:         foreach ($check as $password) {
68:             $password = trim($password);
69:             if (strlen($password) < self::MIN_PASSWORD_LENGTH || strlen($password) > self::MAX_PASSWORD_LENGTH) {
70:                 return false;
71:             }
72:         }
73: 
74:         return true;
75:     }
76: 
77:     public function confirmacaoSenhaValidacao($check) {
78:         foreach ($check as $value) {
79:             if ($value != $this->data[$this->alias]['nova_senha']) {
80:                 return false;
81:             }
82:         }
83:         return true;
84:     }
85: 
86:     private function _findUser() {
87:         if (empty($this->data[$this->alias]['user_id'])) {
88:             throw new Exception("\$this->data[{$this->alias}]['user_id'] is empty");
89:         }
90:         $user = $this->AuthenticationUser->findById($this->data[$this->alias]['user_id']);
91:         if (empty($user)) {
92:             throw new Exception("User not found");
93:         }
94:         return $user;
95:     }
96: 
97: }
98: 
API documentation generated by ApiGen 2.8.0