help(); } /** * Reset all emails - e.g. your admin email (for local development) * * @return void */ public function email() { $this->out('email:'); App::uses('Validation', 'Utility'); while (empty($email) || !Validation::email($email)) { $email = $this->in(__('New email address (must have a valid form at least)')); } $this->User = ClassRegistry::init(CLASS_USER); if (!$this->User->hasField('email')) { return $this->error(CLASS_USER . ' model doesnt have an email field!'); } $this->hr(); $this->out('resetting...'); Configure::write('debug', 2); $this->User->recursive = -1; $this->User->updateAll(array('User.email' => '\'' . $email . '\''), array('User.email !=' => $email)); $count = $this->User->getAffectedRows(); $this->out($count . ' emails resetted - DONE'); } /** * Reset all pwds to a simply pwd (for local development) * * @return void */ public function pwd() { $components = array('Tools.AuthExt', 'Auth'); foreach ($components as $component) { if (App::import('Component', $component)) { $component .= 'Component'; list($plugin, $component) = pluginSplit($component); $this->Auth = new $component(new ComponentCollection()); break; } } if (!is_object($this->Auth)) { return $this->error('No Auth Component found'); } $this->out('Using: ' . get_class($this->Auth) . ' (Abort with STRG+C)'); if (!empty($this->args[0]) && mb_strlen($this->args[0]) >= 2) { $pwToHash = $this->args[0]; } while (empty($pwToHash) || mb_strlen($pwToHash) < 2) { $pwToHash = $this->in(__('Password to Hash (2 characters at least)')); } $this->hr(); $this->out('pwd:'); $this->out($pwToHash); $pw = $this->Auth->password($pwToHash); $this->hr(); $this->out('hash:'); $this->out($pw); $this->hr(); $this->out('resetting...'); $this->User = ClassRegistry::init(CLASS_USER); if (!$this->User->hasField('password')) { return $this->error(CLASS_USER . ' model doesnt have a password field!'); } if (method_exists($this->User, 'escapeValue')) { $newPwd = $this->User->escapeValue($pw); } else { $newPwd = '\'' . $pw . '\''; } $this->User->recursive = -1; $this->User->updateAll(array('password' => $newPwd), array('password !=' => $pw)); $count = $this->User->getAffectedRows(); $this->out($count . ' pwds resetted - DONE'); } /** * ResetShell::help() * * @return void */ public function help() { $this->out('-- pwd: Hash and Reset all user passwords with Auth(Ext) Component --'); $this->out('-- email: Reset all user emails --'); } }