HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: /var/www/html/coreplad/sites/all/modules/corepla_user/customer.reset.inc
<?php


function corepla_user_customer_reset_form($form, &$form_state) {
	    
    $form['#id'] = array("frm_user_reset");
    $form['#method'] =  array("post");
	
	$form['campo_email'] = array(
	  '#type' => 'textfield', 
	  '#title' => t('E-mail'), 
	  '#title_display' => 'invisible',
	  '#default_value' => "", 
	  '#attributes' => array(
		'placeholder' => t( 'E-mail address *' )),
	  '#size' => 60, 
	  '#maxlength' => 128, 
	  '#required' => TRUE,
	);
	
	$form["links"]["#markup"] = '<div class="login--passlost">
			<p>Insert your e-mail address for recive the new password</p>
		</div>';

	$form['#validate'] = array('corepla_user_customer_reset_form_validate');
    $form['actions'] = array('#type' => 'actions');
	
    $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('E-mail to Reset'));
	$form['actions']['submit']['#attributes']['class'][] = 'btn btn-q8 btn-q8_green btn-block btn-lg';
  
    $form['#submit'][] = 'corepla_user_customer_reset_form_submit';
    return $form;
}

function corepla_user_customer_reset_form_validate($form, &$form_state) {
    
	if ($error = user_validate_mail($form_state['values']['campo_email'])) {
        form_set_error('campo_email', $error);
    }
}


//SALVATAGGIO
function corepla_user_customer_reset_form_submit($form, &$form_state)
{
	
	//cerco email
	$parEmail = trim($form_state['values']['campo_email']);
	$result = db_query('SELECT id, username, rag_soc FROM {corepla_user} WHERE sede_leg_email = :mail AND stato = :status', array(':mail' => $parEmail, ':status' => 1));
	$record = $result->fetchObject();  
	
	if(isset($record->id)) {
		$token = $record->id."/".md5(date("Y-m-d")."@".$record->username);
		$pathSend = variable_get("site_base").'customer/change-psw/'.$token;
		
		$params = array();
		$params['subject'] = "Corepla - Reset Password";
				 
		$body = "Spett.le ".$record->rag_soc.',<br /><br />				
			Recentemente è stata fatta una richiesta di accesso a Corepla.it.<br />
			Ora puoi accedere facendo clic su questo collegamento o copiandolo e incollandolo nel browser:<br /><br />
			'.$pathSend.'<br /><br />
			Questo link ti condurrà a una pagina dove potrai impostare la tua nuova password. Scade dopo un giorno e non succede nulla se non viene utilizzato.<br /><br /><br />
			Il Team Corepla';
		
		$params['body'] = $body;
		//to
		//drupal_mail("corepla_user", "accept", $parEmail, "it", $params, NULL);
		//drupal_mail("corepla_user", "accept", "ermete78@gmail.com", "it", $params, NULL);	
		drupal_mail("corepla_user", "accept", "falchi.roberto@gmail.com", "it", $params, NULL);		
		drupal_goto("customer/message/5");
		//drupal_set_message(t('An email has been sent with the instructions necessary to change the password'), 'status');
	}else{
		//drupal_set_message(t('User not found in archive'), 'status');
		drupal_goto("customer/message/7");
	}
	drupal_goto("");
}


//cambio


function corepla_user_customer_psw_form($form, &$form_state, $idUser, $token) {
	
	$result = db_query('SELECT id, username, rag_soc FROM {corepla_user} WHERE id = :idUser AND stato = :status', array(':idUser' => $idUser, ':status' => 1));
	$record = $result->fetchObject();  
	
	if(!isset($record->username)){
		drupal_goto("customer/message/6");
		//drupal_goto("");
	}else{
		//esiste
		$tokenGen = md5(date("Y-m-d")."@".$record->username);
		if($tokenGen != $token) {
			drupal_goto("customer/message/6");
			//drupal_goto("");
		}
	}
	
	$form['#id'] = array("frm_user_change_psw");
    $form['#method'] =  array("post");
	
	$form['campo_user_id'] = array(
		'#type' => 'hidden', 
		'#title' => "Id", 
		'#size' => 25,
		'#value' => $record->id,
		'#required' => TRUE,
	);
	
	$form['campo_username'] = array(
		'#type' => 'hidden', 
		'#title' => "Username", 
		'#size' => 25,
		'#value' => $record->username,
		'#required' => TRUE,
	);
		
	$form['pass'] = array(
	  '#type' => 'password', 
	  '#title' => t('Password'), 
	  '#default_value' => "", 
	  '#size' => 60, 
	  '#maxlength' => 128, 
	  '#required' => TRUE,
	);
	
	$form['pass2'] = array(
	  '#type' => 'password', 
	  '#title' => t('Conferma Password'), 
	  '#default_value' => "", 
	  '#size' => 60, 
	  '#maxlength' => 128, 
	  '#required' => TRUE,
	);
	
	$form['#validate'] = array('corepla_user_customer_psw_form_validate');
	$form['actions'] = array('#type' => 'actions');
	
    $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Password Confirm'));
	//$form['actions']['submit']['#attributes']['class'][] = 'btn btn-q8 btn-q8_green btn-block btn-lg';
	 $form['#submit'][] = 'corepla_user_customer_psw_form_submit';
	
	return $form;
}



function corepla_user_customer_psw_form_validate($form, &$form_state) {
		
		
	if(($form_state['values']['pass']) != ($form_state['values']['pass2']))
	{
		$errorLenPassw = "Il campo Password non coincide con il campo Conferma Password";
		form_set_error('pass', $errorLenPassw);
	}
	
	if(strlen($form_state['values']['pass']) < 8)
	{
		$errorLenPassw = "Il campo Password deve contenere un minimo di 8 caratteri";
		form_set_error('pass', $errorLenPassw);
	}
    
	//controlla se almeno un numerico 
	if (!preg_match('#[0-9]#',$form_state['values']['pass'])){
	  
		$errorNumPass = "Il campo Password deve contenere almeno un carattere numerico";
		form_set_error('pass', $errorNumPass);
	} 
    
	//controlla se almeno una lettera
	if (!preg_match('#[a-zA-Z]#',$form_state['values']['pass'])){
	  
		$errorLetterPass = "Il campo Password deve contenere almeno un carattere alfanumerico";
		form_set_error('pass', $errorLetterPass);
	} 
	
}

function corepla_user_customer_psw_form_submit($form, &$form_state) {
	
	
	$userId = $form_state['values']['campo_user_id'];
	$username = $form_state['values']['campo_username'];
	$newPsw = trim($form_state['values']['pass']);
	
	$account = user_load_by_name($username);
	if(isset($account->uid)) {		
        $newUser = array(
			'pass' =>  $newPsw // note: do not md5 the 
		);      
      
		//save
		user_save($account, $newUser);
		//watchdog('user', t('Changed password ').$account->name);
	
		//istud_auth_change_psw_validate($account,$username, $newPsw);
		
		//insertMsgBacheca($account->getIdUser(), 'Change password');
	}
	
	drupal_goto("customer/message/3");
	
}


function corepla_user_customer_psw_int_form($form, &$form_state) {
	
		
	$form['#id'] = array("frm_user_change_psw_int");
    $form['#method'] =  array("post");	
		
	$form['pass'] = array(
	  '#type' => 'password', 
	  '#title' => t('Password'), 
	  '#default_value' => "", 
	  '#size' => 60, 
	  '#maxlength' => 128, 
	  '#required' => TRUE,
	);
	
	$form['pass2'] = array(
	  '#type' => 'password', 
	  '#title' => t('Conferma Password'), 
	  '#default_value' => "", 
	  '#size' => 60, 
	  '#maxlength' => 128, 
	  '#required' => TRUE,
	);
	
	$form['#validate'] = array('corepla_user_customer_psw_form_validate');
	$form['actions'] = array('#type' => 'actions');
	
    $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Password Confirm'));
	//$form['actions']['submit']['#attributes']['class'][] = 'btn btn-q8 btn-q8_green btn-block btn-lg';
	 $form['#submit'][] = 'corepla_user_customer_psw_int_form_submit';
	
	return $form;
}

function corepla_user_customer_psw_int_form_submit($form, &$form_state) {
	
	global $user;
	
	$username = $form_state['values']['campo_username'];
	$newPsw = trim($form_state['values']['pass']);
	
	if(isset($user->uid)) {		
        $newUser = array(
			'pass' =>  $newPsw // note: do not md5 the 
		);      
      
		//save
		user_save($user, $newUser);
		//watchdog('user', t('Changed password ').$account->name);
	
		//istud_auth_change_psw_validate($account,$username, $newPsw);
		
		//insertMsgBacheca($account->getIdUser(), 'Change password');
	}
	
	drupal_goto("user/logout");
	
}