mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Can check the validity of a password reset token
This commit is contained in:
		@@ -310,6 +310,32 @@ class AccountComponent {
 | 
			
		||||
		return cs()->db->updateDB(self::USER_TABLE, "ID = ?", $modifs, array($userID));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Associate password reset token with user ID
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param string $token The token to associate
 | 
			
		||||
	 * @return int The ID of the user / -1 in case of failure
 | 
			
		||||
	 */
 | 
			
		||||
	public function getUserIDfromResetToken(string $token) : int {
 | 
			
		||||
 | 
			
		||||
		//Prepare database query
 | 
			
		||||
		$conditions = "WHERE password_reset_token = ? AND password_reset_token_time_create > ?";
 | 
			
		||||
		$values = array(
 | 
			
		||||
			$token,
 | 
			
		||||
			time()-60*60*24 //Maximum validity : 24 hours
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		//Query the database
 | 
			
		||||
		$results = cs()->db->select(self::USER_TABLE, $conditions, $values);
 | 
			
		||||
 | 
			
		||||
		//Check if there is not any result
 | 
			
		||||
		if(count($results) == 0)
 | 
			
		||||
			return -1;
 | 
			
		||||
		
 | 
			
		||||
		//Return first result user ID
 | 
			
		||||
		return $results[0]["ID"];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Crypt user password
 | 
			
		||||
	 *
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user