public function actionAfficheSearch($month,$year);
Url::to(['/perform/affiche-search','month' => 12, 'year' => '2015']);
'show?month=<month>&year=<year>' => 'perform/affichesearch',
'show'=> 'perform/afficheindex',
>.<
<?=Yii::t('message.model','NAME_ATTR')?>
public $enableCsrfValidation = false;
public function actions()
{
return [
'social' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'successCallback'],
],
];
}
/**
* @param $client
*/
public function successCallback($client)
{
$day = 86400;
$client_id = Yii::$app->request->get('authclient');
$attributes = $client->getUserAttributes();
// VK
if($client instanceof VKontakte)
{
$auth_params = $client->getAccessToken()->getParams();
$email = ArrayHelper::getValue($auth_params,'email','');
// Аватарка из VK да ПОБОЛЬШЕ!!!
$vk_data_response = $client->api('users.get','POST',['uids'=> $attributes['id'] , 'fields'=> 'photo_max_orig']);
if($vk_data_response = ArrayHelper::getValue($vk_data_response,'response',false))
{
$vk_data = array_shift($vk_data_response);
Yii::$app->session->setFlash('social_avatar', $vk_data['photo_max_orig']);
}
}
//...
}
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@app/mail',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'email-smtp.us-west-2.amazonaws.com',
'username' => 'anu4yzgRtf3YP6Vq431QA6iqlatm',
'password' => 'erBYPWIDq/banu4yzgRtf',
'port' => '587',
'encryption' => 'tls',
],
//'useFileTransport' => true,
],
$HTML = \Yii::$app->view->render('@app/mail/remind', [
'token' => $user->password_reset_token,
'email' => $user->email,
'url' => $url
]);
Yii::$app->mailer->compose()
->setFrom('ОТ кого')
->setTo('Кому')
->setSubject('Тема')
->setHtmlBody( $HTML )
->send();
Yii::$app->mailer->compose('contact/html')
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
$connection = new \yii\db\Connection([
'dsn' => $dsn,
'username' => $username,
'password' => $password,
]);
$connection->open();
public function actions()
{
return [
'social' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'successCallback'],
],
];
}
/**
* @param $client
*/
public function successCallback($client)
{
$day = 86400;
$client_id = Yii::$app->request->get('authclient');
$attributes = $client->getUserAttributes();
$email = '';
$sex = 0;
// VK
if($client instanceof VKontakte)
{
$auth_params = $client->getAccessToken()->getParams();
$email = ArrayHelper::getValue($auth_params,'email','');
// Аватарка из соц сети
$vk_data_response = $client->api('users.get','POST',['uids'=> $attributes['id'] , 'fields'=> 'photo_max_orig']);
if($vk_data_response = ArrayHelper::getValue($vk_data_response,'response',false))
{
$vk_data = array_shift($vk_data_response);
Yii::$app->session->setFlash('social_avatar', $vk_data['photo_max_orig']);
}
}
if($client instanceof YandexOAuth)
{
$ya_data_response = $client->api('info','GET',['format'=>'json']);
$email = array_shift($ya_data_response['emails']);
Yii::$app->session->setFlash('social_avatar', "https://avatars.yandex.net/get-yapic/{$ya_data_response['default_avatar_id']}/islands");
if(!empty($ya_data_response['sex']))
{
$sex = $ya_data_response['sex'] == 'female' ? UserProfile::SEX_FEMALE : UserProfile::SEX_MALE;
}
}
if($client instanceof Odnoklassniki)
{
$od_data_response =$client->api('','GET',[
'method' => 'users.getCurrentUser',
'application_key' => $client->application_public_key
]);
$sex = $od_data_response['gender'] == 'female' ? UserProfile::SEX_FEMALE : UserProfile::SEX_MALE;
if(isset($od_data_response['pic_1']))
{
Yii::$app->session->setFlash('social_avatar', $od_data_response['pic_1']);
}
}
if($client instanceof Facebook) {
try
{
$curl = new Curl;
$fb_curl_result = $curl->get("https://graph.facebook.com/{$attributes['id']}/picture?width=300&redirect=false");
$fb_data_responce = Json::decode($fb_curl_result);
if (isset($fb_data_responce['data'])) {
Yii::$app->session->setFlash('social_avatar', $fb_data_responce['data']['url']);
}
}
catch (Exception $e) {};
}
$user_social = UserSocial::findOne([
'client' => $client_id ,
'internal_id' => $attributes['id']
]);
if(!$user_social)
{
$user = new User;
if(!empty($email) && !$user = User::find()->where(['email'=>$email])->one())
{
$user = new User;
$user->email = $email;
}
// тут я шаманил у меня соц пользователи не имеют логина и пароля через валидатор авторизации они не пройдут так как пустые.
$user->scenario = 'social';
if($user->isNewRecord)
{
$user->username = '';
$user->password_hash = '';
}
// регистрируем в User
if($user->register())
{
$user_social = new UserSocial;
$user_social->user_id = $user->id;
$user_social->client = $client_id;
$user_social->internal_id = (string)$attributes['id'];
$user_social->save();
// $this->referralRegistration($user->id);
}
//$this->setSocialAvatarToProfile($user->id);
Yii::$app->session->set('auth_social',[
'client' => $client_id,
'attributes' => $attributes,
'token' => ''
]);
}
$user = $user_social->user;
Yii::$app->user->login($user , $day * 366);
}
<?php
namespace app\models\traits;
use app\models\User;
/**
* Class UserRelationUserId
*
* @package app\models\traits
* @property \app\models\User $user
*/
trait UserRelationUserId
{
/**
* Relationship get user
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
/**@var \yii\db\ActiveRecord $this */
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
}
source config_mysite
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = mysql
sql_db = new_db
sql_port = 3306
sql_query_pre = SET NAMES utf8
sql_query_pre = SET CHARACTER SET utf8
}
source mysite_selposts :config_mysite
{
sql_query = \
SELECT `id`, `text` FROM sel_posts
sql_field_string = text
}
namespace app\controllers\base;
use Yii;
class BaseController extends \yii\web\Controller
{
/**
* @param string $id
* @param \yii\base\Module $module
* @param array $config
*/
public function __construct($id, $module, $config = [])
{
// DI
Yii::$container->set('yii\widgets\LinkPager', ['maxButtonCount' => 5]);
return parent::__construct($id,$module,$config);
}
}
namespace app\controllers;
use Yii;
class SiteController extends base\BaseController
{
//...
}
public function init() {
Yii::$container->set('yii\widgets\LinkPager', ['maxButtonCount' => 5]);
}