Jump to content

modulo registro


davlinares

Recommended Posts

El archivo que veo que pertenece al modulo es solo este...y supongo que ahi no sera.

<?php

global $_MODULE;
$_MODULE = array();
$_MODULE['<{activationbymail}amaltea>info_8cf04a9734132302f96da8e113e80ce5'] = 'Desde el Bacoffice';
$_MODULE['<{activationbymail}amaltea>info_ef5872ccb6ea77c26a046f51371a6043'] = 'Activacion de la cuenta';
$_MODULE['<{activationbymail}amaltea>info_6873d17dfc95b69866d59374fe666355'] = 'Su cuenta ha sido creada y se le ha enviado un correo con el enlace para activarla.';

Link to comment
Share on other sites

Ahora si lo encontre.

<?php

/*********** Erico ***************/

// Todo : Add a time limit to activation

// Todo : Add an email domain blacklist

// Todo : Add a "email me again" function                        <-- Done     (Mellow)

// Todo : Manual activation of pending users                     <-- Can be achieve in back office     (Mellow)

// Todo : Add a warning if the module is not in the last position (because of its redirection)

// Todo : alternative activation mode (copy/paste code)          <-- Text added in the mail sent to customer     (Mellow)

// Todo : obfuscate the customer id in the confirmation link     <-- No more customer_id used, juste a md5 key !  (Mellow)



/******************************************** Mellow ***********************************************/

// Added : Only one mail sent (need to add file /override/controllers/AuthController.php)

// Added : Cart recovery after activation and connexion

// Added : Auto connexion after activation

// Added : Notification to admin after account activation (config set in backoffice)

// Added : Activation link can be resent if a customer tries to login before activating is account 

/***************************************************************************************************/



if (!defined('_PS_VERSION_'))

  exit;



class EmailVerify extends Module

{

	public function __construct() {

		$this->name = 'emailverify';

		$this->tab = 'administration';

		$this->version = '1.4';

                $this->author = 'Erico, Mellow971 (PrestaShop Forum Members)';



                parent::__construct();



                $this->displayName = $this->l('Customer email verification');

                $this->description = $this->l('Send an account activation link in the welcome email to the new registered customers');

		$this->confirmUninstall = $this->l('Pending verifications will be lost');

	}

	

        public function install() {

                if (!parent::install()

                || !$this->registerHook('createAccount')

                || !$this->registerHook('beforeAuthentication')

                || !Db::getInstance()->Execute('ALTER TABLE '._DB_PREFIX_.'customer ADD act_key CHAR(32)'))

                    return false;

                Configuration::updateValue('emailverify_notifyadmin', 0);

		Configuration::updateValue('emailverify_adminmail', '');

                return true;

        }



        public function uninstall() {

		Configuration::deleteByName('emailverify_notifyadmin');

		Configuration::deleteByName('emailverify_adminmail');

                if (!parent::uninstall()

                || !$this->unregisterHook('createAccount')

                || !$this->unregisterHook('beforeAuthentication')

                || !Db::getInstance()->Execute('ALTER TABLE '._DB_PREFIX_.'customer DROP act_key'))

                    return false;

                return true;

        }



	public function hookCreateAccount($params) {

                global  $smarty, $cookie, $cart;



                $customer=new Customer($params['newCustomer']->id);

                $customer->getFields();

                

                $err=2;

        	$id_lang = $cookie->id_lang;

                $actkey = md5($customer->email);           // La clé d'activation est un md5 de l'adresse mail du client

                $domain = Tools::getShopDomain(true);

                $actlink = $domain.__PS_BASE_URI__.'modules/emailverify/activate.php?id_lang='.$id_lang.'&actkey='.$actkey;



                // On rend le compte inactif et on enregistre la clé dans la base de donnée

                Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET active=0, act_key="'.$actkey.'" WHERE id_customer="'.$customer->id.'"') ;



                // Envoie du mail

                if (!Mail::Send((int)$cookie->id_lang,

                   'emailverify',

                   Mail::l('Welcome!', (int)$cookie->id_lang),

                   array('{firstname}' => $customer->firstname,

                   '{lastname}' => $customer->lastname,

                   '{email}' => $customer->email,

                   '{passwd}' =>  Tools::getValue('passwd'),

                   '{actlink}' => $actlink),

                   $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL, dirname(__FILE__).'/mails/')

                   )

                     $err=1;   // si le mail n'est pas parti on le signalera au client



                $cart->id_customer = (int)($customer->id);          // Récupération du panier en lui affectant l'id du nouveau compte

                $cart->update();



        	$cookie->logout();                                   // On déconnecte le client puisque son compte n'est pas encore actif



                if (Tools::isSubmit('ajax')) {

                  return;

                  //$redirecturl = Tools::getShopDomain(true).__PS_BASE_URI__.'modules/emailverify/notify.php?id_lang='.$id_lang.'&err='.$err;

                  //echo '<script type="text/javascript"> window.location.href = '.$redirecturl.';</script>';

                }

                else

                  self::redirectmod('modules/emailverify/notify.php?id_lang='.$id_lang.'&err='.$err);



        }



        private function isValidMd5($str) {

                return !empty($str) && preg_match('/^[a-f0-9]{32}$/', $str);

        }



	public function activate() {

	    global $smarty, $cookie;

	    $errors = array();

	    $actkey=Tools::getValue('actkey');

	    $id_lang=Tools::getValue('id_lang');

	    $err=Tools::getValue('err');



	    if ($err == 'OK') { // si $err = 0 c'est qu'on reviens pour afficher le message de confirmation

	        ob_end_flush();

	        $smarty->assign('errors', $errors);

	        $smarty->display(dirname(__FILE__).'/activate.tpl');

	    } else {

                // On vérifie que la clé du lien est bien un md5 valide

                if (!$this->isValidMd5($actkey))

		        $errors[] = $this->l('Invalid activation key');



                // On vérifie qu'il y a bien un compte avec la clé d'activation correspondante

                elseif (!$cutomer_to_act = Db::getInstance()->getValue('SELECT id_customer FROM '._DB_PREFIX_.'customer WHERE act_key="'.$actkey.'"'))

		        $errors[] = $this->l('No account to activate. You may have already activated your account.');



                // Un compte correspond, alors on active le compte et on supprime la clé -> plus de réactivation ultérieur possible   

                elseif (Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET active=1, act_key=NULL WHERE act_key="'.$actkey.'"'))

                {

                        // Le compte a été activé, maintenant on va connecter le client et récupéré son panier

                        $customer = new Customer($cutomer_to_act);

                        $customer->getFields();

                        if ( $customer->id ) {

                              $cookie->logged = 1;

                              $cookie->id_customer = (int)($customer->id);

                              $cookie->customer_lastname = $customer->lastname;

                              $cookie->customer_firstname = $customer->firstname;

                              $cookie->passwd = $customer->passwd;

                              $cookie->email = $customer->email;



                              if ($cart_id = Db::getInstance()->getValue('SELECT id_cart FROM '._DB_PREFIX_.'cart WHERE id_customer='.(int)($customer->id).' ORDER BY id_cart DESC'))

                                  $cookie->id_cart = $cart_id;

                              

                              Module::hookExec('authentication');

                       }



                       // Le compte a été activé, notification à l'admin si l'option à été choisi

		       if(Configuration::get('emailverify_notifyadmin') == 1) {

                             $adminmail = ( Configuration::get('emailverify_adminmail') == '' ? Configuration::get('PS_SHOP_EMAIL') : Configuration::get('emailverify_adminmail'));

                             $adminlang = Configuration::get('PS_LANG_DEFAULT');



                             // Envoie du mail

                             Mail::Send((int)$adminlang, 'notifyadmin', $this->l('New customer registered!', false, (int)$adminlang),

                                         array('{firstname}' => '', '{lastname}' => ''),

                                         $adminmail, NULL, NULL, NULL, NULL, NULL, dirname(__FILE__).'/mails/');

                       }



                       // Ici on éfface le header chargé avant la connexion (pas encore affiché) pour le recharger avec les infos du client connecté

                       ob_clean();

                       self::redirectmod('modules/emailverify/activate.php?id_lang='.$id_lang.'&err=OK');

                }

	        ob_end_flush();

	        $smarty->assign('errors', $errors);

	        $smarty->display(dirname(__FILE__).'/activate.tpl');

	    }

	}



	public function notify($err) {

                global $smarty, $cookie;

                $errors = array();

                

                if ($err == 1) $errors[] = $this->l('Validation email could not be sent. Maybe you typed a wrong address...');

		

                else if (isset($_POST['email']) AND $_POST['email']) {

                    $mailtoresend = $_POST['email'];

                    $actkey = md5($mailtoresend);

                    // On revérifie qu'il existe bien un compte : NON ACTIF, correspondant à CETTE ADRESSE, et CETTE CLÉ !

                    if ($cutomer_to_act = Db::getInstance()->getValue('SELECT id_customer FROM '._DB_PREFIX_.'customer WHERE email="'.$mailtoresend.'" AND active=0 AND act_key="'.$actkey.'"')) {

                        $domain = Tools::getShopDomain(true);

                        $actlink = $domain.__PS_BASE_URI__.'modules/emailverify/activate.php?id_lang='.(int)$cookie->id_lang.'&actkey='.$actkey;

                        // Le compte existe, on renvoi la clé !

                        if (!Mail::Send((int)$cookie->id_lang, 'mailresend', $this->l('Account activation'),

                            array('{email}' => $mailtoresend, '{actlink}' => $actlink),

                            $mailtoresend, NULL, NULL, NULL, NULL, NULL, dirname(__FILE__).'/mails/'))



                              // le mail n'est pas parti on le signale au client

                              $errors[] = $this->l('Validation email could not be sent. Maybe you typed a wrong address...');



                        // le mail est bien parti

                        else $smarty->assign('mailresended', $_POST['email']);



                    }

                    // aucun compte ne correspond

                    else $errors[] = $this->l('No account matches your request !');

                }

                // pas d'erreur et pas d'email posté

                else if (!($err == 2)) $errors[] = $this->l('No account matches your request !');



                $smarty->assign('errors', $errors);

                return $this->display(__FILE__, 'notify.tpl');

	}



	public function hookBeforeAuthentication() {

                global  $cookie;

                if (Tools::isSubmit('ajax')) return;

	        $passwd = trim(Tools::getValue('passwd'));

	        $email = trim(Tools::getValue('email'));

	        if (empty($email) OR empty($passwd) OR !Validate::isEmail($email) OR !Validate::isPasswd($passwd))

	             return;

	        else {

                     $result = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'customer` WHERE `active` = 0

                     AND `email` = \''.pSQL($email).'\'

                     '.(isset($passwd) ? 'AND `passwd` = \''.md5(pSQL(_COOKIE_KEY_.$passwd)).'\'' : '').'

                     AND `act_key` = \''.md5(pSQL($email)).'\' AND `deleted` = 0 AND `is_guest` = 0');

                     if ($result) {

                       self::redirectmod('modules/emailverify/resend.php?email='.$email);

                     }

                }

	}



	private static function redirectmod($url, $baseUri = __PS_BASE_URI__)

	{

		if (isset($_SERVER['HTTP_REFERER']) && ($url == $_SERVER['HTTP_REFERER']))

			header('Location: '.$_SERVER['HTTP_REFERER']);

		else

			header('Location: '.$baseUri.$url);

		exit;

	}





	public function resendForm($email) {

                global  $smarty, $cookie;

            if ($email AND $email != "") {

		$this->_html .='

                        <div class="error">

                             <p>'.$this->l('Your account is not active yet !').'</p>

                             '.$this->l('Please check your mailbox, you should have received a link to activate your account.').'<br />

                             '.$this->l('If not, you can use the form below to resend the activation link at your mail address.').'<br />

                             '.$this->l('If you still doesn\'t receive it, your mail address may be wrong or unreachable.').'<br /><br />';

            } else {

		$this->_html .='

                        <div class="">

                             <h1>'.$this->l('You did not receive your activation link ?').'</h1>

                             '.$this->l('If you created an account on the site and you did not receive the activation link, you can use the form below to resend the activation link at your mail address.').'<br />

                             '.$this->l('If you still doesn\'t receive it, your mail address may be wrong or unreachable.').'<br /><br />';

            }

		$this->_html .='

			     <form action="notify.php" method="post">

		                  <label class="t" for="email">E-mail :</label>

                                  <input type="text" name="email" value="'.$email.'" size="30" /><br /><br />

                                  <input type="submit" name="submitResend" value="'.$this->l('Resend activation link').'" class="button_large" />

                             </form>

                        </div>';

		return $this->_html;

	}



	public function getContent() {

		$this->_html = '<h2>'.$this->displayName.'</h2>';

		$errors = '';

		

		if (Tools::isSubmit('submitConfig')) {

                        $email = trim(Tools::getValue('emailverify_adminmail'));

			if (!Configuration::updateValue('emailverify_notifyadmin', Tools::getValue('emailverify_notifyadmin')))

				$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';

			elseif (!empty($email) && !Validate::isEmail($email))

			        $this->_html .= '<div class="alert error">'.$this->l('Invalid e-mail:').' '.$email.'</div>';

                        elseif (!Configuration::updateValue('emailverify_adminmail', Tools::getValue('emailverify_adminmail')))

				$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';

                        else

				$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="" />'.$this->l('Settings updated').'</div>';

		}



		$this->_displayForm();

		return $this->_html;

        }



	private function _displayForm() {

		$this->_html .='

			<form action="'.$_SERVER['REQUEST_URI'].'" method="post">

				<fieldset>

					<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>

					<label>'.$this->l('Admin notification :').'</label>

					<div class="margin-form" style="padding-top:5px;">

						<input type="radio" name="emailverify_notifyadmin" id="emailverify_notifyadmin_on" value="1" '.(Tools::getValue('emailverify_notifyadmin', Configuration::get('emailverify_notifyadmin')) ? 'checked="checked" ' : '').'/>

						<label class="t" for="emailverify_notifyadmin_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>

						<input type="radio" name="emailverify_notifyadmin" id="emailverify_notifyadmin_off" value="0" '.(!Tools::getValue('emailverify_notifyadmin', Configuration::get('emailverify_notifyadmin')) ? 'checked="checked" ' : '').'/>

						<label class="t" for="emailverify_notifyadmin_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>

						<p class="clear">'.$this->l('Enable to notify admin of new customer registration (mail is sent once account is activated)').'</p>

					</div>

				        <div class="margin-form">

					        <input type="text" name="emailverify_adminmail" value="'.Configuration::get('emailverify_adminmail').'" size="50" />

					        <p class="clear">'.$this->l('E-mail address for admin notification (leave blanck to send to shop address)').'</p>

				        </div>

				        <div style="clear:both;"> </div>

				        <div class="margin-form">

                                                <input type="submit" name="submitConfig" value="'.$this->l('   Save   ').'" class="button" />

                                        </div>

				</fieldset>

			</form>';

        }

}

?>
Link to comment
Share on other sites

Hola, 

 

Tienes que añadir lo que sea a partir de la línea 151 cambia esto:

// Envoie du mail
Mail::Send((int)$adminlang, 'notifyadmin', $this->l('New customer registered!', false, (int)$adminlang),
           array('{firstname}' => '', '{lastname}' => ''),
           $adminmail, NULL, $customer->email, NULL, NULL, NULL, dirname(__FILE__).'/mails/');

Por esto: 

// Envoie du mail
Mail::Send((int)$adminlang, 'notifyadmin', $this->l('New customer registered!', false, (int)$adminlang),
           array('{firstname}' => '', '{lastname}' => ''),
           $adminmail, NULL, $customer->email, NULL, NULL, NULL, dirname(__FILE__).'/mails/');

Te añadirá el mail de registro del cliente como "de" en el mail, si lo quieres dentro del mail, tendrás que añadir más, cosas y esto es lo más sencillo. 

 

Saludos

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...