Skip to content

Commit

Permalink
added support to new register page (for 3.5.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kousuke Ebihara committed Apr 29, 2010
1 parent 6bbabd5 commit 34d1a6f
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 7 deletions.
Expand Up @@ -27,13 +27,13 @@ public function executeRequestRegisterURL($request)

$this->forward404Unless(opToolkit::isEnabledRegistration());

$this->form = new InviteForm(null, array('authMode' => 'MailAddress'));
$this->form = new opRequestRegisterURLForm(null, array('authMode' => 'MailAddress'));
if ($request->isMethod('post'))
{
$this->form->bind($request->getParameter('member_config'));
$this->form->bind($request->getParameter('request_register_url'));
if ($this->form->isValid())
{
$this->form->save();
$this->form->sendMail();

return sfView::SUCCESS;
}
Expand All @@ -47,7 +47,7 @@ public function executeRegister($request)
$this->getUser()->setCurrentAuthMode('MailAddress');

$token = $request->getParameter('token');
$memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndValue('pc_address_token', $token);
$memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndValue('register_token', $token);
$this->forward404Unless($memberConfig, 'This URL is invalid.');

opActivateBehavior::disable();
Expand All @@ -63,6 +63,6 @@ public function executeRegister($request)
$this->getUser()->setMemberId($memberConfig->getMemberId());
$this->getUser()->setIsSNSRegisterBegin(true);

$this->redirect('member/registerInput');
$this->redirect('member/registerInput?token='.$token);
}
}
@@ -0,0 +1,16 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

class opAuthMailAddressComponents extends sfComponents
{
public function executeRegisterBox($request)
{
}
}
@@ -1,3 +1,2 @@
registerEnd:
is_secure: on
credentials: SNSRegisterFinish
is_secure: false
@@ -0,0 +1,7 @@
<?php op_include_parts('ButtonBox', 'opAuthMailAddressPluginRegisterBox', array(
'title' => 'メールアドレスで登録する',
'body' => '以下のボタンをクリックすると、招待されたメールアドレスで登録をおこないます。',
'button' => 'プロフィール入力ページへ',
'url' => url_for($sf_user->getRegisterInputAction()),
'method' => 'get',
)) ?>
1 change: 1 addition & 0 deletions lib/form/opAuthRegisterFormMailAddress.class.php
Expand Up @@ -49,6 +49,7 @@ public function doSave()
}

$memberConfig->save();

return $memberConfig;
}
}
130 changes: 130 additions & 0 deletions lib/form/opRequestRegisterURLForm.class.php
@@ -0,0 +1,130 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
*
*
* @package opAuthMailAddressPlugin
* @subpackage form
* @author Kousuke Ebihara <ebihara@tejimaya.com>
*/
class opRequestRegisterURLForm extends BaseForm
{
protected $doNotSend = false;

public function configure()
{
$this->disableLocalCSRFProtection();

$this->setWidget('mail_address', new sfWidgetFormInputText());
$this->setValidator('mail_address', new sfValidatorPass());

$callback = new sfValidatorCallback(array(
'callback' => array($this, 'validate'),
));
$callback->setMessage('invalid', 'invalid e-mail address');
$this->validatorSchema->setPostValidator($callback);

if (sfConfig::get('op_is_use_captcha', false))
{
$this->embedForm('captcha', new opCaptchaForm());
}

$this->widgetSchema->setNameFormat('request_register_url[%s]');
}

public function validate($validator, $values, $arguments = array())
{
if (opToolkit::isMobileEmailAddress($values['mail_address']))
{
$mailValidator = new sfValidatorMobileEmail();
$values['mobile_address'] = $mailValidator->clean($values['mail_address']);
$mode = 'mobile';
}
else
{
$mailValidator = new opValidatorPCEmail();
$values['pc_address'] = $mailValidator->clean($values['mail_address']);
$mode = 'pc';
}

if (!opToolkit::isEnabledRegistration($mode))
{
throw new sfValidatorError($validator, 'invalid');
}

if (!empty($values['mobile_address']) && !$this->validateAddress('mobile_address', $values['mobile_address']))
{
$this->doNotSend = true;
}
if (!empty($values['pc_address']) && !$this->validateAddress('pc_address', $values['pc_address']))
{
$this->doNotSend = true;
}

return $values;
}

protected function validateAddress($configName, $configValue)
{
if ($config = Doctrine::getTable('MemberConfig')->retrieveByNameAndValue($configName, $configValue))
{
return false;
}
elseif ($config = Doctrine::getTable('MemberConfig')->retrieveByNameAndValue($configName.'_pre', $configValue))
{
return false;
}

return true;
}

public function sendMail()
{
if ($this->doNotSend)
{
return null;
}

$address = '';

$member = Doctrine::getTable('Member')->createPre();

if ($this->getValue('pc_address'))
{
$address = $this->getValue('pc_address');

$member->setConfig('pc_address_pre', $address);
}
elseif ($this->getValue('mobile_address'))
{
$address = $this->getValue('mobile_address');

$member->setConfig('mobile_address_pre', $address);
}

$token = $member->generateRegisterToken();

$authMode = $this->getOption('authMode', null);
if (!$authMode)
{
$authMode = sfContext::getInstance()->getUser()->getCurrentAuthMode();
}
$member->setConfig('register_auth_mode', $authMode);

$params = array(
'token' => $token,
'authMode' => 'MailAddress',
'isMobile' => opToolkit::isMobileEmailAddress($address),
'subject' => opConfig::get('sns_name').'招待状',
);
opMailSend::sendTemplateMail('notifyRegisterURL', $address, opConfig::get('admin_mail_address'), $params);
}
}
12 changes: 12 additions & 0 deletions templates/mail/mobile/_notifyRegisterURL.php
@@ -0,0 +1,12 @@
<?php $snsName = $op_config['sns_name'] ?>
<?php echo __('Hello! This is information from %1%.', array('%1%' => $snsName)) ?>

<?php echo __('If you register(free) of member by the following URL,%br%you can participate in %1%.', array('%1%' => $snsName, '%br%' => "\n")) ?>

<?php echo __('* Participate in %1%', array('%1%' => $snsName)) ?>

<?php if ($isMobile) : ?>
<?php echo app_url_for('mobile_frontend', sprintf('opAuthMailAddress/register?token=%s&authMode=%s', $token, $authMode), true) ?>
<?php else: ?>
<?php echo app_url_for('pc_frontend', sprintf('opAuthMailAddress/register?token=%s&authMode=%s', $token, $authMode), true) ?>
<?php endif; ?>
14 changes: 14 additions & 0 deletions templates/mail/pc/_notifyRegisterURL.php
@@ -0,0 +1,14 @@
<?php $snsName = $op_config['sns_name'] ?>
<?php echo __('Hello! This is information from %1%.', array('%1%' => $snsName)) ?>

<?php echo __('If you register(free) of member by the following URL,%br%you can participate in %1%.', array('%1%' => $snsName, '%br%' => "\n")) ?>

<?php echo __('* Participate in %1%', array('%1%' => $snsName)) ?>



<?php if ($isMobile) : ?>
<?php echo app_url_for('mobile_frontend', sprintf('opAuthMailAddress/register?token=%s&authMode=%s', $token, $authMode), true) ?>
<?php else: ?>
<?php echo app_url_for('pc_frontend', sprintf('opAuthMailAddress/register?token=%s&authMode=%s', $token, $authMode), true) ?>
<?php endif; ?>

0 comments on commit 34d1a6f

Please sign in to comment.