parent
							
								
									76dca6eb4a
								
							
						
					
					
						commit
						4c0780aa76
					
				@ -0,0 +1,33 @@ | 
				
			||||
<?php | 
				
			||||
/* For licensing terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
namespace Application\Migrations\Schema\V110; | 
				
			||||
 | 
				
			||||
use Application\Migrations\AbstractMigrationChamilo; | 
				
			||||
use Doctrine\DBAL\Schema\Schema; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Class Version20150803171220 | 
				
			||||
 * | 
				
			||||
 * @package Application\Migrations\Schema\V110 | 
				
			||||
 */ | 
				
			||||
class Version20150803171220 extends AbstractMigrationChamilo | 
				
			||||
{ | 
				
			||||
    /** | 
				
			||||
     * @param Schema $schema | 
				
			||||
     */ | 
				
			||||
    public function up(Schema $schema) | 
				
			||||
    { | 
				
			||||
        $this->addSql('ALTER TABLE user ADD confirmation_token VARCHAR(255) NULL'); | 
				
			||||
        $this->addSql('ALTER TABLE user ADD password_requested_at DATETIME DEFAULT NULL'); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * @param Schema $schema | 
				
			||||
     */ | 
				
			||||
    public function down(Schema $schema) | 
				
			||||
    { | 
				
			||||
        $this->addSql('ALTER TABLE user DROP confirmation_token'); | 
				
			||||
        $this->addSql('ALTER TABLE user DROP password_requested_at'); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,68 @@ | 
				
			||||
<?php | 
				
			||||
/* For license terms, see /license.txt */ | 
				
			||||
 | 
				
			||||
use ChamiloSession as Session; | 
				
			||||
 | 
				
			||||
require_once '../inc/global.inc.php'; | 
				
			||||
 | 
				
			||||
$token = isset($_GET['token']) ? $_GET['token'] : ''; | 
				
			||||
 | 
				
			||||
if (!ctype_alnum($token)) { | 
				
			||||
    $token = ''; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$tpl = new Template(null); | 
				
			||||
 | 
				
			||||
// Build the form | 
				
			||||
$form = new FormValidator('reset', 'POST', api_get_self().'?token='.$token); | 
				
			||||
$form->addElement('header', get_lang('ResetPassword')); | 
				
			||||
$form->addHidden('token', $token); | 
				
			||||
$form->addElement('password', 'pass1', get_lang('Password')); | 
				
			||||
$form->addElement('password', 'pass2', get_lang('Confirmation'), array('id' => 'pass2', 'size' => 20, 'autocomplete' => 'off')); | 
				
			||||
$form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required'); | 
				
			||||
$form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required'); | 
				
			||||
$form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare'); | 
				
			||||
$form->addButtonSave(get_lang('Update')); | 
				
			||||
 | 
				
			||||
$ttl = api_get_configuration_value('user_reset_password_token_limit'); | 
				
			||||
if (empty($ttl)) { | 
				
			||||
    $ttl = 3600; | 
				
			||||
} | 
				
			||||
 | 
				
			||||
if ($form->validate()) { | 
				
			||||
    $em = Database::getManager(); | 
				
			||||
    $values = $form->exportValues(); | 
				
			||||
    $password = $values['pass1']; | 
				
			||||
    $token = $values['token']; | 
				
			||||
 | 
				
			||||
    /** @var \Chamilo\UserBundle\Entity\User $user */ | 
				
			||||
    $user = UserManager::getManager()->findUserByConfirmationToken($token); | 
				
			||||
    if ($user) { | 
				
			||||
        if (!$user->isPasswordRequestNonExpired($ttl)) { | 
				
			||||
            Display::addFlash(Display::return_message(get_lang('LinkExpired')), 'warning'); | 
				
			||||
            header('Location: '.api_get_path(WEB_CODE_PATH).'auth/lostPassword.php'); | 
				
			||||
            exit; | 
				
			||||
        } | 
				
			||||
 | 
				
			||||
        $user->setPlainPassword($password); | 
				
			||||
        $userManager = UserManager::getManager(); | 
				
			||||
        $userManager->updateUser($user, true); | 
				
			||||
 | 
				
			||||
        Display::addFlash(Display::return_message(get_lang('Updated'))); | 
				
			||||
        header('Location: '.api_get_path(WEB_PATH)); | 
				
			||||
        exit; | 
				
			||||
    } else { | 
				
			||||
 | 
				
			||||
        if (empty($user)) { | 
				
			||||
            Display::addFlash( | 
				
			||||
                Display::return_message(get_lang('UserDoesNotExist')) | 
				
			||||
            ); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
 | 
				
			||||
$tpl->assign('form', $form->toHtml()); | 
				
			||||
$content = $tpl->get_template('auth/set_temp_password.tpl'); | 
				
			||||
$tpl->assign('content', $tpl->fetch($content)); | 
				
			||||
$tpl->display_one_col_template(); | 
				
			||||
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue