ورود و ثبت نام با گوگل

ساخت وبلاگ
چند تا پلاگین را تست کردم اما این بهترین بود : kartik-v/yii2-social

روش نصب با composer : 

php composer.phar require kartik-v/yii2-social "dev-master"

این را به در فایل web.php وارد کنید :
'modules' => [ 'social' => [ // the module class 'class' => 'kartiksocialModule', // the global settings for the Disqus widget 'disqus' => [ 'settings' => ['shortname' => 'DISQUS_SHORTNAME'] // default settings ], // the global settings for the Facebook plugins widget 'facebook' => [ 'appId' => 'FACEBOOK_APP_ID', 'secret' => 'FACEBOOK_APP_SECRET', ], // the global settings for the Google+ Plugins widget 'google' => [ 'clientId' => 'GOOGLE_API_CLIENT_ID', 'pageId' => 'GOOGLE_PLUS_PAGE_ID', 'profileId' => 'GOOGLE_PLUS_PROFILE_ID', ], // the global settings for the Google Analytics plugin widget 'googleAnalytics' => [ 'id' => 'TRACKING_ID', 'domain' => 'TRACKING_DOMAIN', ], // the global settings for the Twitter plugin widget 'twitter' => [ 'screenName' => 'TWITTER_SCREEN_NAME' ], // the global settings for the GitHub plugin widget 'github' => [ 'settings' => ['user' => 'GITHUB_USER', 'repo' => 'GITHUB_REPO'] ], ], // your other modules
]

توی view تون هم این کد را بگذارید .
use kartiksocialGooglePlugin;
/** * If any parameters are not passed, the widget will use settings from the social * module wherever possible. For example `clientId`, `pageId`, and `profileId` will * be referred from the module settings. */
echo GooglePlugin::widget([ 'type'=>GooglePlugin::SIGNIN, 'tag'=>'span', 'signinOptions'=>['id'=>'signinButton'], 'settings' => [ 'callback'=>'signinCallback', 'cookiepolicy' => 'single_host_origin', 'requestvisibleactions' => 'http://schemas.google.com/AddActivity', 'scope'=>'https://www.googleapis.com/auth/plus.login' ]
]);
/** * The callback client script */
function signinCallback(authResult) { if (authResult['status']['signed_in']) { // Update the app to reflect a signed in user // Hide the sign-in button now that the user is authorized, for example: document.getElementById('signinButton').setAttribute('style', 'display: none'); } else { // Update the app to reflect a signed out user // Possible error values: // "user_signed_out" - User is signed-out // "access_denied" - User denied access to your app // "immediate_failed" - Could not automatically log in the user console.log('Sign-in state: ' + authResult['error']); }
}
منبع :‌ http://demos.krajee.com/social

- - , .

برنامه نویس...
ما را در سایت برنامه نویس دنبال می کنید

برچسب : نویسنده : خنجی prog بازدید : 167 تاريخ : سه شنبه 11 اسفند 1394 ساعت: 3:31

خبرنامه