Skip to content

Instantly share code, notes, and snippets.

@77web
Created June 6, 2011 00:38
Show Gist options
  • Save 77web/1009593 to your computer and use it in GitHub Desktop.
Save 77web/1009593 to your computer and use it in GitHub Desktop.
OpenPNE3.xで外部ログインページ(静的HTML,他システム…)にjavascriptでログインフォームを埋め込む
<?php
class jsLoginAction extends sfAction
{
public function execute($request)
{
if(!$this->getUser()->hasCredential('SNSMember'))
{
$this->forms = $this->getUser()->getAuthForms();
foreach($this->forms as $form)
{
$form->getWidget('next_uri')->setAttribute('value', '@homepage');
$form->setDefault('next_uri', '@homepage');
}
}
return sfView::SUCCESS;
}
}
<?php slot('js'); ?>
<?php if($sf_user->hasCredential('SNSMember')): ?>
<?php echo $sf_user->getMember()->getName(); ?>
<?php else: ?>
<?php foreach($forms as $form): ?>
<?php include_login_parts('Login', $form, 'member/login'); ?>
<?php endforeach; ?>
<?php endif; ?>
<?php end_slot(); ?>
document.write('<?php echo str_replace(array("\r", "\n"), '', get_slot('js')); ?>');
all:
is_secure: true
credentials: SNSMember
registerInput:
credentials: [[SNSRegisterBegin, SNSRegisterFinish]]
configComplete:
is_secure: false
changeLanguage:
is_secure: false
registerMobileToRegisterEnd:
credentials: SNSRegisterFinish
registerMobileToRegisterEndFinish:
is_secure: false
jsLogin:
is_secure: false
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test page</title>
</head>
<body>
<div id="testLoginForm">
↓ここにログインフォームが埋め込まれます↓
<script type="text/javascript" src="http://opskinfacebookplugin.77-web.com/member/jsLogin"></script>
↑ここにログインフォームが埋め込まれます↑
</div>
<pre>
設置方法
0.SNS設定を「外部ログインページ利用」に変更しておく
1.このgistのusage.html以外のファイルを下記のように配置
apps/pc_frontend/modules/member/actions/jsLoginAction.class.php
apps/pc_frontend/modules/member/templates/jsLoginSuccess.php
apps/pc_frontend/modules/member/config/security.yml
apps/pc_frontend/modules/member/config/view.yml
2.キャッシュクリア
php symfony ccまたはpc_backend>SNS設定>キャッシュクリア で実行。
3.ログインフォームを設置したい場所にscriptタグを設置
&lt;script type="text/javascript" src="http://(SNSのURL)/member/jsLogin"&gt;&lt;/script&gt;
</pre>
</body>
</html>
homeSuccess:
javascripts: [%SF_PROTOTYPE_WEB_DIR%/js/prototype, util]
layout: layoutA
customize:
cautionAboutFriendPre:
template: [friend, cautionAboutFriendPre]
parts : [information]
target : [bodyBottom]
cautionAboutCommunityMemberPre:
template : [community, cautionAboutCommunityMemberPre]
parts : [information]
target : [bodyBottom]
is_component: true
cautionAboutChangeAdminRequest:
template : [community, cautionAboutChangeAdminRequest]
parts : [information]
target : [bodyBottom]
is_component: true
cautionAboutSubAdminRequest:
template : [community, cautionAboutSubAdminRequest]
parts : [information]
target : [bodyBottom]
is_component: true
profileSuccess:
layout: layoutA
configSuccess:
layout: layoutB
loginSuccess:
layout: layoutA
jsLoginSuccess:
has_layout: false
http_metas:
content-type: text/javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment