Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
79ef690f
Commit
79ef690f
authored
Feb 08, 2016
by
difox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Social plugin
parent
058ab648
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
347 additions
and
83 deletions
+347
-83
common/modules/eauth/components/FacebookOAuth2Service.php
common/modules/eauth/components/FacebookOAuth2Service.php
+9
-8
common/modules/eauth/components/GoogleOAuth2Service.php
common/modules/eauth/components/GoogleOAuth2Service.php
+13
-11
common/modules/eauth/components/ServiceTrait.php
common/modules/eauth/components/ServiceTrait.php
+15
-1
common/modules/eauth/components/TwitterOAuth1Service.php
common/modules/eauth/components/TwitterOAuth1Service.php
+9
-8
common/modules/eauth/components/VkOAuth2Service.php
common/modules/eauth/components/VkOAuth2Service.php
+11
-9
common/modules/eauth/models/UserEAuth.php
common/modules/eauth/models/UserEAuth.php
+153
-0
common/modules/eauth/widgets/SocialWidget.php
common/modules/eauth/widgets/SocialWidget.php
+1
-1
common/modules/eauth/widgets/views/widget.php
common/modules/eauth/widgets/views/widget.php
+1
-0
common/modules/school/views/course/index.php
common/modules/school/views/course/index.php
+8
-1
common/modules/school/views/course/view.php
common/modules/school/views/course/view.php
+3
-4
common/modules/school/views/lesson/view.php
common/modules/school/views/lesson/view.php
+5
-4
common/modules/users/controllers/UserController.php
common/modules/users/controllers/UserController.php
+5
-3
common/modules/users/models/User.php
common/modules/users/models/User.php
+28
-21
common/modules/users/widgets/UserBoxWidget.php
common/modules/users/widgets/UserBoxWidget.php
+26
-0
common/modules/users/widgets/views/UserBoxWidget.php
common/modules/users/widgets/views/UserBoxWidget.php
+8
-0
console/migrations/m160207_204809_create_eauth_table.php
console/migrations/m160207_204809_create_eauth_table.php
+24
-0
frontend/config/main.php
frontend/config/main.php
+2
-1
frontend/controllers/SiteController.php
frontend/controllers/SiteController.php
+9
-9
frontend/web/css/custom.css
frontend/web/css/custom.css
+15
-0
frontend/web/css/screen.css
frontend/web/css/screen.css
+2
-2
No files found.
common/modules/eauth/components/FacebookOAuth2Service.php
View file @
79ef690f
...
@@ -24,18 +24,19 @@ class FacebookOAuth2Service extends \nodge\eauth\services\FacebookOAuth2Service
...
@@ -24,18 +24,19 @@ class FacebookOAuth2Service extends \nodge\eauth\services\FacebookOAuth2Service
]
]
]);
]);
$this
->
attributes
[
'id'
]
=
$info
[
'id'
];
$profile
=
[
$this
->
attributes
[
'name'
]
=
$info
[
'name'
];
$this
->
attributes
[
'url'
]
=
$info
[
'link'
];
$this
->
attributes
[
'profile'
]
=
[
'id'
=>
$info
[
'id'
],
'id'
=>
$info
[
'id'
],
'email'
=>
$info
[
'email'
],
'email'
=>
$info
[
'email'
],
// 'firstname' => $info['first_name'],
'name'
=>
$info
[
'name'
],
// 'lastname' => $info['last_name'],
'fullname'
=>
$info
[
'name'
],
'locale'
=>
$info
[
'locale'
],
'locale'
=>
$info
[
'locale'
],
];
];
$this
->
attributes
[
'id'
]
=
$info
[
'id'
];
$this
->
attributes
[
'name'
]
=
$info
[
'name'
];
$this
->
attributes
[
'url'
]
=
$info
[
'link'
];
$this
->
attributes
[
'profile'
]
=
$profile
;
$this
->
setSocialProfile
(
$profile
);
return
true
;
return
true
;
}
}
...
...
common/modules/eauth/components/GoogleOAuth2Service.php
View file @
79ef690f
...
@@ -4,25 +4,27 @@ namespace common\modules\eauth\components;
...
@@ -4,25 +4,27 @@ namespace common\modules\eauth\components;
class
GoogleOAuth2Service
extends
\nodge\eauth\services\GoogleOAuth2Service
class
GoogleOAuth2Service
extends
\nodge\eauth\services\GoogleOAuth2Service
{
{
use
ServiceTrait
;
use
ServiceTrait
;
protected
$name
=
'google'
;
protected
function
fetchAttributes
()
protected
function
fetchAttributes
()
{
{
$info
=
$this
->
makeSignedRequest
(
'https://www.googleapis.com/oauth2/v1/userinfo'
);
$info
=
$this
->
makeSignedRequest
(
'https://www.googleapis.com/oauth2/v1/userinfo'
);
echo
'<pre>'
;
die
(
var_dump
(
$info
));
echo
'</pre>'
;
$this
->
attributes
[
'id'
]
=
$info
[
'id'
];
$this
->
attributes
[
'name'
]
=
$info
[
'name'
];
if
(
!
empty
(
$info
[
'link'
]))
{
$profile
=
[
$this
->
attributes
[
'url'
]
=
$info
[
'link'
];
}
$this
->
attributes
[
'profile'
]
=
[
'id'
=>
$info
[
'id'
],
'id'
=>
$info
[
'id'
],
'email'
=>
$info
[
'email'
],
'email'
=>
$info
[
'email'
],
// 'firstname' => $info['given_name'],
'name'
=>
$info
[
'name'
],
// 'lastname' => $info['family_name'],
'fullname'
=>
$info
[
'name'
],
'locale'
=>
$info
[
'locale'
],
'locale'
=>
$info
[
'locale'
],
];
];
$this
->
attributes
[
'id'
]
=
$info
[
'id'
];
$this
->
attributes
[
'name'
]
=
$info
[
'name'
];
$this
->
attributes
[
'url'
]
=
$info
[
'link'
];
$this
->
attributes
[
'profile'
]
=
$profile
;
$this
->
setSocialProfile
(
$profile
);
return
true
;
}
}
}
}
common/modules/eauth/components/ServiceTrait.php
View file @
79ef690f
...
@@ -6,6 +6,8 @@ namespace common\modules\eauth\components;
...
@@ -6,6 +6,8 @@ namespace common\modules\eauth\components;
*/
*/
trait
ServiceTrait
trait
ServiceTrait
{
{
protected
$socialProfile
;
/**
/**
* Logout from Oauth
* Logout from Oauth
*/
*/
...
@@ -14,8 +16,20 @@ trait ServiceTrait
...
@@ -14,8 +16,20 @@ trait ServiceTrait
$this
->
getProxy
()
->
getStorage
()
->
clearToken
(
$this
->
getServiceName
());
$this
->
getProxy
()
->
getStorage
()
->
clearToken
(
$this
->
getServiceName
());
}
}
public
function
getSocialProfile
()
{
return
$this
->
socialProfile
;
}
public
function
setSocialProfile
(
$profile
)
{
$this
->
socialProfile
=
$profile
;
}
public
function
checkAttributes
()
public
function
checkAttributes
()
{
{
die
(
'1'
);
if
(
!
$this
->
socialProfile
[
'email'
])
{
die
(
'Невозможно получить email'
);
}
}
}
}
}
common/modules/eauth/components/TwitterOAuth1Service.php
View file @
79ef690f
...
@@ -11,19 +11,20 @@ class TwitterOAuth1Service extends \nodge\eauth\services\TwitterOAuth1Service
...
@@ -11,19 +11,20 @@ class TwitterOAuth1Service extends \nodge\eauth\services\TwitterOAuth1Service
'include_email'
=>
1
'include_email'
=>
1
]);
]);
$this
->
attributes
[
'id'
]
=
$info
[
'id'
];
$profile
=
[
$this
->
attributes
[
'name'
]
=
$info
[
'name'
];
$this
->
attributes
[
'url'
]
=
'http://twitter.com/account/redirect_by_id?id='
.
$info
[
'id_str'
];
$this
->
attributes
[
'profile'
]
=
[
'id'
=>
$info
[
'id'
],
'id'
=>
$info
[
'id'
],
'email'
=>
$info
[
'email'
],
'email'
=>
$info
[
'email'
],
// 'firstname' => $info['name'],
'name'
=>
$info
[
'name'
],
// 'lastname' => $info['name'],
'fullname'
=>
$info
[
'name'
],
'locale'
=>
$info
[
'lang'
],
'locale'
=>
$info
[
'lang'
],
];
];
$this
->
attributes
[
'id'
]
=
$info
[
'id'
];
$this
->
attributes
[
'name'
]
=
$info
[
'name'
];
$this
->
attributes
[
'url'
]
=
'http://twitter.com/account/redirect_by_id?id='
.
$info
[
'id_str'
];
$this
->
attributes
[
'profile'
]
=
$profile
;
$this
->
setSocialProfile
(
$profile
);
return
true
;
return
true
;
}
}
}
}
common/modules/eauth/components/VkOAuth2Service.php
View file @
79ef690f
...
@@ -4,6 +4,8 @@ namespace common\modules\eauth\components;
...
@@ -4,6 +4,8 @@ namespace common\modules\eauth\components;
class
VkOAuth2Service
extends
\nodge\eauth\services\VKontakteOAuth2Service
class
VkOAuth2Service
extends
\nodge\eauth\services\VKontakteOAuth2Service
{
{
use
ServiceTrait
;
use
ServiceTrait
;
protected
$name
=
'vk'
;
/*
/*
* Scopes MUST be declarated for use
* Scopes MUST be declarated for use
...
@@ -20,22 +22,22 @@ class VkOAuth2Service extends \nodge\eauth\services\VKontakteOAuth2Service
...
@@ -20,22 +22,22 @@ class VkOAuth2Service extends \nodge\eauth\services\VKontakteOAuth2Service
'fields'
=>
'uid, name, nickname, first_name, last_name, email'
,
// uid, first_name and last_name is always available
'fields'
=>
'uid, name, nickname, first_name, last_name, email'
,
// uid, first_name and last_name is always available
],
],
]);
]);
$info
=
$info
[
'response'
][
0
];
$info
=
$info
[
'response'
][
0
];
$this
->
attributes
[
'id'
]
=
$info
[
'uid'
];
$profile
=
[
$this
->
attributes
[
'name'
]
=
$info
[
'first_name'
]
.
' '
.
$info
[
'last_name'
];
$this
->
attributes
[
'url'
]
=
'http://vk.com/id'
.
$info
[
'uid'
];
$this
->
attributes
[
'profile'
]
=
[
'id'
=>
$tokenData
[
'params'
][
'user_id'
],
'id'
=>
$tokenData
[
'params'
][
'user_id'
],
'email'
=>
$tokenData
[
'params'
][
'email'
],
'email'
=>
$tokenData
[
'params'
][
'email'
],
// 'firstname' => $info['first_name'],
'name'
=>
$info
[
'first_name'
]
.
' '
.
$info
[
'last_name'
],
// 'lastname' => $info['last_name'],
'fullname'
=>
$info
[
'first_name'
]
.
' '
.
$info
[
'last_name'
],
'locale'
=>
'ru'
,
'locale'
=>
'ru'
,
];
];
$this
->
attributes
[
'id'
]
=
$info
[
'uid'
];
$this
->
attributes
[
'name'
]
=
$info
[
'first_name'
]
.
' '
.
$info
[
'last_name'
];
$this
->
attributes
[
'url'
]
=
'http://vk.com/id'
.
$info
[
'uid'
];
$this
->
attributes
[
'profile'
]
=
$profile
;
$this
->
setSocialProfile
(
$profile
);
return
true
;
return
true
;
}
}
}
}
common/modules/eauth/models/UserEAuth.php
0 → 100644
View file @
79ef690f
<?php
namespace
common\modules\eauth\models
;
use
Yii
;
use
yii\base\NotSupportedException
;
use
yii\db\ActiveRecord
;
use
yii\data\ActiveDataProvider
;
use
common\modules\users\models\User
;
use
common\modules\rbac\models\AuthAssignment
;
class
UserEAuth
extends
\common\components\ActiveRecordModel
{
public
$created_at
;
public
$updated_at
;
public
function
attributeLabels
()
{
$attrs
=
array_merge
(
parent
::
attributeLabels
(),
array
(
"id"
=>
"ID"
,
));
return
$attrs
;
}
public
function
rules
()
{
return
[
[[
'user_id'
],
'required'
],
[[
'google_id'
,
'twitter_id'
,
'vk_id'
,
'facebook_id'
],
'integer'
,
'integerOnly'
=>
true
],
];
}
public
static
function
model
(
$className
=
__CLASS__
)
{
return
parent
::
model
(
$className
);
}
public
static
function
tableName
()
{
return
'users_eauth'
;
}
public
function
name
()
{
return
"Социальные аккаунты пользователя"
;
}
public
static
function
findById
(
$id
)
{
return
static
::
findOne
([
'id'
=>
$id
]);
}
/**
* Finds user by user id
*
* @param string $user_id
* @return static|null
*/
public
static
function
findByUserId
(
$user_id
)
{
return
static
::
findOne
([
'user_id'
=>
$user_id
]);
}
public
function
relations
()
{
return
array
(
'user'
=>
array
(
self
::
BELONGS_TO
,
'User'
,
'user_id'
)
);
}
/**
* @param \nodge\eauth\ServiceBase $service
* @return User
* @throws ErrorException
*/
public
function
getByEAuth
(
$service
)
{
/*if (!$service->getIsAuthenticated()) {
throw new ErrorException('EAuth user should be authenticated before creating identity.');
}*/
$userModel
=
new
User
();
$socialProfile
=
$service
->
getSocialProfile
();
$eauthField
=
$service
->
getServiceName
()
.
'_id'
;
// Check is User EAuth service token exists
if
(
$this
->
isEAuthExists
(
$service
))
{
// Get existing user model
return
$userModel
->
getByEAuth
(
$service
);
}
// Check is User with such email exists - assign Eauth token to him
elseif
(
$userModel
->
isUserEmailExists
(
$socialProfile
[
'email'
]))
{
$model
=
User
::
findByUsername
(
$socialProfile
[
'email'
]);
// Assign service token
$modelEAuth
=
$model
->
eauth
;
$modelEAuth
->
{
$eauthField
}
=
$socialProfile
[
'id'
];
$modelEAuth
->
update
(
false
,
[
$eauthField
]);
return
$model
;
}
else
{
// Create and save new user
$model
=
new
User
();
$model
->
scenario
=
User
::
SCENARIO_SOCIAL_REGISTRATION
;
$model
->
email
=
$socialProfile
[
'email'
];
$model
->
name
=
$socialProfile
[
'name'
];
$model
->
status
=
User
::
STATUS_ACTIVE
;
$model
->
activate_date
=
date
(
'Y-m-d H:i:s'
);
if
(
$model
->
save
())
{
// Assign role
$assignment
=
new
AuthAssignment
();
$assignment
->
item_name
=
'user'
;
$assignment
->
user_id
=
$model
->
id
;
$assignment
->
save
();
// Assign EAuth data
$eauth
=
new
UserEAuth
();
$eauth
->
user_id
=
$model
->
id
;
$eauth
->
{
$eauthField
}
=
$socialProfile
[
'id'
];
$eauth
->
save
();
return
$model
;
}
else
{
echo
'<pre>'
;
die
(
var_dump
(
$model
->
getErrors
()));
echo
'</pre>'
;
}
return
false
;
}
/*$id = $service->getServiceName().'-'.$service->getId();
$attributes = [
'id' => $id,
'username' => $service->getAttribute('name'),
'authKey' => md5($id),
'profile' => $service->getAttributes(),
];
$attributes['profile']['service'] = $service->getServiceName();
Yii::$app->getSession()->set('user-'.$id, $attributes);*/
}
public
function
isEAuthExists
(
$service
)
{
$socialProfile
=
$service
->
getSocialProfile
();
$eauthField
=
$service
->
getServiceName
()
.
'_id'
;
return
(
bool
)
static
::
find
()
->
where
(
$eauthField
.
' = :eauth'
,
[
':eauth'
=>
$socialProfile
[
'id'
]])
->
count
();
}
}
common/modules/eauth/widgets/Widget.php
→
common/modules/eauth/widgets/
Social
Widget.php
View file @
79ef690f
<?php
<?php
namespace
common\modules\eauth\widgets
;
namespace
common\modules\eauth\widgets
;
class
Widget
extends
\nodge\eauth\Widget
class
Social
Widget
extends
\nodge\eauth\Widget
{
{
/**
/**
* Executes the widget.
* Executes the widget.
...
...
common/modules/eauth/widgets/views/widget.php
View file @
79ef690f
...
@@ -23,6 +23,7 @@ if ($popup) {
...
@@ -23,6 +23,7 @@ if ($popup) {
?>
?>
<div
class=
"eauth"
id=
"
<?php
echo
$id
;
?>
"
>
<div
class=
"eauth"
id=
"
<?php
echo
$id
;
?>
"
>
<p>
Войти, используя соцсети:
</p>
<ul
class=
"eauth-list"
>
<ul
class=
"eauth-list"
>
<?php
<?php
foreach
(
$services
as
$name
=>
$service
)
{
foreach
(
$services
as
$name
=>
$service
)
{
...
...
common/modules/school/views/course/index.php
View file @
79ef690f
<?php
use
common\modules\eauth\widgets
;
?>
<section
class=
"sh_kurs"
>
<section
class=
"sh_kurs"
>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"row"
>
<div
class=
"row"
>
...
@@ -45,6 +48,8 @@
...
@@ -45,6 +48,8 @@
</div>
</div>
</div>
</div>
</section>
</section>
<?php
if
(
Yii
::
$app
->
user
->
isGuest
)
:
?>
<section
class=
"sh_ft"
>
<section
class=
"sh_ft"
>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"row"
>
<div
class=
"row"
>
...
@@ -52,7 +57,7 @@
...
@@ -52,7 +57,7 @@
<?php
<?php
echo
$form
;
echo
$form
;
?>
?>
<?php
echo
\common\modules\eauth\widgets\
Widget
::
widget
([
'action'
=>
'/site/login'
]);
?>
<?php
echo
common\modules\eauth\widgets\Social
Widget
::
widget
([
'action'
=>
'/site/login'
]);
?>
<div
class=
"usl"
>
Проходя регистрацию вы подтверждаете
<br><a
href=
"#"
>
согласие на обработку персональных данных.
</a></div>
<div
class=
"usl"
>
Проходя регистрацию вы подтверждаете
<br><a
href=
"#"
>
согласие на обработку персональных данных.
</a></div>
</div>
</div>
<div
class=
"col-md-8 col-xs-6 col-sm-12"
>
<div
class=
"col-md-8 col-xs-6 col-sm-12"
>
...
@@ -63,6 +68,8 @@
...
@@ -63,6 +68,8 @@
</div>
</div>
</div>
</div>
</section>
</section>
<?php
endif
?>
<div
class=
"tr_foot"
></div>
<div
class=
"tr_foot"
></div>
<footer>
<footer>
<div
class=
"container"
>
<div
class=
"container"
>
...
...
common/modules/school/views/course/view.php
View file @
79ef690f
<?php
<?php
use
yii\helpers\Url
;
use
yii\helpers\Url
;
use
common\modules\users\widgets
;
?>
?>
<section
class=
"ks_header"
>
<section
class=
"ks_header"
>
<div
class=
"container"
>
<div
class=
"container"
>
...
@@ -11,10 +12,8 @@
...
@@ -11,10 +12,8 @@
<div
class=
"ball_hover"
>
Текст как увеличить,
<br>
текст как увеличить,
</div>
<div
class=
"ball_hover"
>
Текст как увеличить,
<br>
текст как увеличить,
</div>
</div>
</div>
</div>
</div>
<div
class=
"col-md-3 col-md-offset-4 col-xs-5 col-sm-12"
>
<div
class=
"col-md-5 col-md-offset-2 col-xs-5 col-sm-12"
>
<div
class=
"prof_block"
>
<?php
echo
\common\modules\users\widgets\UserBoxWidget
::
widget
()
?>
<span
class=
"prof_name"
>
Дмитрий
</span><a
href=
"#"
>
Выход
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
common/modules/school/views/lesson/view.php
View file @
79ef690f
<?php
use
common\modules\users\widgets
;
?>
<section
class=
"ks_header"
>
<section
class=
"ks_header"
>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"row"
>
<div
class=
"row"
>
...
@@ -8,10 +11,8 @@
...
@@ -8,10 +11,8 @@
<div
class=
"ball_hover"
>
Текст как увеличить,
<br>
текст как увеличить,
</div>
<div
class=
"ball_hover"
>
Текст как увеличить,
<br>
текст как увеличить,
</div>
</div>
</div>
</div>
</div>
<div
class=
"col-md-3 col-md-offset-4 col-xs-5 col-sm-12"
>
<div
class=
"col-md-5 col-md-offset-2 col-xs-5 col-sm-12"
>
<div
class=
"prof_block"
>
<?php
echo
UserBoxWidget
::
widget
()
?>
<span
class=
"prof_name"
>
Дмитрий
</span><a
href=
"#"
>
Выход
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
common/modules/users/controllers/UserController.php
View file @
79ef690f
...
@@ -102,9 +102,11 @@ class UserController extends \common\components\BaseController {
...
@@ -102,9 +102,11 @@ class UserController extends \common\components\BaseController {
}
}
public
function
actionLogout
()
{
public
function
actionLogout
()
Yii
::
app
()
->
user
->
logout
();
{
$this
->
redirect
(
Yii
::
app
()
->
homeUrl
);
Yii
::
$app
->
user
->
logout
();
return
$this
->
goHome
();
}
}
...
...
common/modules/users/models/User.php
View file @
79ef690f
...
@@ -11,10 +11,14 @@ use himiklab\sortablegrid\SortableGridBehavior;
...
@@ -11,10 +11,14 @@ use himiklab\sortablegrid\SortableGridBehavior;
use
\common\components\validators\RuEmailValidator
;
use
\common\components\validators\RuEmailValidator
;
use
\common\modules\rbac\models\AuthItem
;
use
\common\modules\rbac\models\AuthItem
;
use
\common\modules\rbac\models\AuthAssignment
;
use
\common\modules\rbac\models\AuthAssignment
;
use
\common\modules\eauth\models\UserEAuth
;
class
User
extends
\common\components\ActiveRecordModel
implements
IdentityInterface
class
User
extends
\common\components\ActiveRecordModel
implements
IdentityInterface
{
{
public
$created_at
;
public
$updated_at
;
const
PAGE_SIZE
=
10
;
const
PAGE_SIZE
=
10
;
const
OCCUPATION_CHIEF_IT
=
1
;
const
OCCUPATION_CHIEF_IT
=
1
;
...
@@ -49,6 +53,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
...
@@ -49,6 +53,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
const
SCENARIO_SEARCH
=
'Search'
;
const
SCENARIO_SEARCH
=
'Search'
;
const
SCENARIO_CSV_IMPORT
=
'CSV_IMPORT'
;
const
SCENARIO_CSV_IMPORT
=
'CSV_IMPORT'
;
const
SCENARIO_RECOVER_PASSWORD
=
'RecoverPassword'
;
const
SCENARIO_RECOVER_PASSWORD
=
'RecoverPassword'
;
const
SCENARIO_SOCIAL_REGISTRATION
=
'SocialRegistration'
;
// public $email;
// public $email;
public
$role
;
public
$role
;
...
@@ -121,6 +126,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
...
@@ -121,6 +126,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
self
::
SCENARIO_CREATE
,
self
::
SCENARIO_CREATE
,
self
::
SCENARIO_LOGIN
,
self
::
SCENARIO_LOGIN
,
self
::
SCENARIO_REGISTRATION
,
self
::
SCENARIO_REGISTRATION
,
self
::
SCENARIO_SOCIAL_REGISTRATION
,
self
::
SCENARIO_UPDATE
,
self
::
SCENARIO_UPDATE
,
self
::
SCENARIO_SEND_NEW_PASSWORD
,
self
::
SCENARIO_SEND_NEW_PASSWORD
,
self
::
SCENARIO_RECOVER_PASSWORD
self
::
SCENARIO_RECOVER_PASSWORD
...
@@ -131,6 +137,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
...
@@ -131,6 +137,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
],
'message'
=>
'Пожалуйста, укажите Ваше имя'
],
],
'message'
=>
'Пожалуйста, укажите Ваше имя'
],
[[
'name'
],
'required'
,
'on'
=>
[
[[
'name'
],
'required'
,
'on'
=>
[
self
::
SCENARIO_REGISTRATION
,
self
::
SCENARIO_REGISTRATION
,
self
::
SCENARIO_SOCIAL_REGISTRATION
,
],
'message'
=>
'Пожалуйста, укажите Ваше имя'
],
],
'message'
=>
'Пожалуйста, укажите Ваше имя'
],
[[
'phone'
],
'required'
,
'on'
=>
[
[[
'phone'
],
'required'
,
'on'
=>
[
self
::
SCENARIO_CREATE
,
self
::
SCENARIO_CREATE
,
...
@@ -373,10 +380,16 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
...
@@ -373,10 +380,16 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
{
{
return
array
(
return
array
(
'assignment'
=>
array
(
self
::
HAS_ONE
,
'AuthAssignment'
,
'user_id'
),
'assignment'
=>
array
(
self
::
HAS_ONE
,
'AuthAssignment'
,
'user_id'
),
'city'
=>
array
(
self
::
BELONGS_TO
,
'City'
,
'city_id'
)
'city'
=>
array
(
self
::
BELONGS_TO
,
'City'
,
'city_id'
),
//'eauth' => array(self::HAS_ONE, 'UserEAuth', 'user_id'),
);
);
}
}
public
function
getEauth
()
{
return
$this
->
hasOne
(
UserEAuth
::
className
(),
[
'user_id'
=>
'id'
]);
}
public
function
search
(
$params
)
public
function
search
(
$params
)
{
{
...
@@ -520,26 +533,20 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
...
@@ -520,26 +533,20 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
return
$granted
;
return
$granted
;
}
}
/**
public
function
getByEAuth
(
$service
)
* @param \nodge\eauth\ServiceBase $service
{
* @return User
$socialProfile
=
$service
->
getSocialProfile
();
* @throws ErrorException
$eauthField
=
$service
->
getServiceName
()
.
'_id'
;
*/
public
static
function
findByEAuth
(
$service
)
{
if
(
!
$service
->
getIsAuthenticated
())
{
throw
new
ErrorException
(
'EAuth user should be authenticated before creating identity.'
);
}
$id
=
$service
->
getServiceName
()
.
'-'
.
$service
->
getId
();
return
static
::
find
()
$attributes
=
[
->
joinWith
(
'eauth'
)
'id'
=>
$id
,
->
where
(
'users_eauth.'
.
$eauthField
.
' = :eauthId'
,
[
':eauthId'
=>
$socialProfile
[
'id'
]])
'username'
=>
$service
->
getAttribute
(
'name'
),
->
one
();
'authKey'
=>
md5
(
$id
),
}
'profile'
=>
$service
->
getAttributes
(),
];
public
function
isUserEmailExists
(
$email
)
$attributes
[
'profile'
][
'service'
]
=
$service
->
getServiceName
();
{
Yii
::
$app
->
getSession
()
->
set
(
'user-'
.
$id
,
$attributes
);
return
(
bool
)
static
::
find
([
'email'
=>
$email
])
->
count
();
return
new
self
(
$attributes
);
}
}
}
}
common/modules/users/widgets/UserBoxWidget.php
0 → 100644
View file @
79ef690f
<?php
namespace
common\modules\users\widgets
;
use
yii\base\Widget
;
use
Yii
;
class
UserBoxWidget
extends
Widget
{
public
$user
;
/**
* Executes the widget.
* This method is called by {@link CBaseController::endWidget}.
*/
public
function
run
()
{
$this
->
setUser
();
echo
$this
->
render
(
'UserBoxWidget'
,
[
'user'
=>
$this
->
user
]);
}
public
function
setUser
()
{
$this
->
user
=
Yii
::
$app
->
user
->
getIdentity
();
}
}
\ No newline at end of file
common/modules/users/widgets/views/UserBoxWidget.php
0 → 100644
View file @
79ef690f
<?php
use
yii\helpers\Html
;
use
yii\web\View
;
?>
<div
class=
"prof_block"
>
<span
class=
"prof_name"
>
<?php
echo
$user
->
name
?>
</span>
<?php
echo
Html
::
a
(
'Выход'
,
[
'/site/logout'
])
?>
</div>
\ No newline at end of file
console/migrations/m160207_204809_create_eauth_table.php
0 → 100644
View file @
79ef690f
<?php
use
yii\db\Migration
;
use
yii\db\Schema
;
class
m160207_204809_create_eauth_table
extends
Migration
{
public
function
up
()
{
$this
->
createTable
(
'users_eauth'
,
[
'id'
=>
Schema
::
TYPE_PK
,
'user_id'
=>
Schema
::
TYPE_INTEGER
.
'(11) NOT NULL'
,
'google_id'
=>
Schema
::
TYPE_STRING
.
'(100) NOT NULL'
,
'vk_id'
=>
Schema
::
TYPE_STRING
.
'(100) NOT NULL'
,
'twitter_id'
=>
Schema
::
TYPE_STRING
.
'(100) NOT NULL'
,
'facebook_id'
=>
Schema
::
TYPE_STRING
.
'(100) NOT NULL'
,
]);
}
public
function
down
()
{
$this
->
dropTable
(
'eauth_table'
);
}
}
frontend/config/main.php
View file @
79ef690f
...
@@ -156,7 +156,8 @@ return [
...
@@ -156,7 +156,8 @@ return [
'school/course/<id>'
=>
'school/course/view'
,
'school/course/<id>'
=>
'school/course/view'
,
'school/lesson/<id>'
=>
'school/lesson/view'
,
'school/lesson/<id>'
=>
'school/lesson/view'
,
'login/eauth/<service_eauth:google|facebook|vk|twitter>'
=>
'site/login'
,
'login/eauth/<service_eauth:google|facebook|vk|twitter>'
=>
'site/login'
,
'login'
=>
'site/login'
,
'login'
=>
'site/login'
,
'logout'
=>
'site/logout'
,
'<page:(/)>'
=>
'content/page/view'
,
'<page:(/)>'
=>
'content/page/view'
,
'<_m>/<_c>/<_a>/<id:\d+>'
=>
'<_m>/<_c>/<_a>'
,
'<_m>/<_c>/<_a>/<id:\d+>'
=>
'<_m>/<_c>/<_a>'
,
...
...
frontend/controllers/SiteController.php
View file @
79ef690f
...
@@ -24,6 +24,7 @@ use \yii\widgets\ActiveForm;
...
@@ -24,6 +24,7 @@ use \yii\widgets\ActiveForm;
use
common\modules\scoring\models\ScClient
;
use
common\modules\scoring\models\ScClient
;
use
common\models\LoginForm
;
use
common\models\LoginForm
;
use
common\modules\eauth\components\GoogleOAuth2Service
;
use
common\modules\eauth\components\GoogleOAuth2Service
;
use
common\modules\eauth\models\UserEAuth
;
/**
/**
* Site controller
* Site controller
...
@@ -140,21 +141,21 @@ class SiteController extends BaseController
...
@@ -140,21 +141,21 @@ class SiteController extends BaseController
try
{
try
{
if
(
$eauth
->
authenticate
())
{
if
(
$eauth
->
authenticate
())
{
$eauth
->
getAttributes
();
// get EAuth info
// Добавить проверку обязательных полей - если нет какого-то
// Добавить проверку обязательных полей - если нет какого-то
// обязательного поля, то предлагать другой сервис.
// обязательного поля, то выводить форму для заполнения
// $eauth->checkAttributes();
$eauth
->
checkAttributes
();
echo
'<pre>'
;
die
(
var_dump
(
$eauth
->
getAttributes
()));
echo
'</pre>'
;
$identity
=
User
::
findByEAuth
(
$eauth
);
$userEAuthModel
=
new
UserEAuth
();
$identity
=
$userEAuthModel
->
getByEAuth
(
$eauth
);
Yii
::
$app
->
getUser
()
->
login
(
$identity
);
Yii
::
$app
->
getUser
()
->
login
(
$identity
);
// special redirect with closing popup window
// special redirect with closing popup window
$eauth
->
redirect
();
$eauth
->
redirect
(
'/school'
);
}
}
else
{
else
{
// close popup window and redirect to cancelUrl
// close popup window and redirect to cancelUrl
$eauth
->
cancel
();
$eauth
->
cancel
(
'/school'
);
}
}
}
}
catch
(
\nodge\eauth\ErrorException
$e
)
{
catch
(
\nodge\eauth\ErrorException
$e
)
{
...
@@ -163,8 +164,7 @@ class SiteController extends BaseController
...
@@ -163,8 +164,7 @@ class SiteController extends BaseController
Yii
::
$app
->
getSession
()
->
setFlash
(
'error'
,
'EAuthException: '
.
$e
->
getMessage
());
Yii
::
$app
->
getSession
()
->
setFlash
(
'error'
,
'EAuthException: '
.
$e
->
getMessage
());
// close popup window and redirect to cancelUrl
// close popup window and redirect to cancelUrl
// $eauth->cancel();
$eauth
->
cancel
(
'/school'
);
$eauth
->
redirect
(
$eauth
->
getCancelUrl
());
}
}
}
}
...
...
frontend/web/css/custom.css
View file @
79ef690f
...
@@ -8,4 +8,19 @@
...
@@ -8,4 +8,19 @@
.has-error
input
{
.has-error
input
{
background
:
#fff
url(../images/icon-fail.png)
no-repeat
96%
center
;
background
:
#fff
url(../images/icon-fail.png)
no-repeat
96%
center
;
border
:
1px
solid
#E9A2A2
;
border
:
1px
solid
#E9A2A2
;
}
/* EAuth widget */
.eauth-service-id-vk
.eauth-service-link
:before
{
background-position
:
0
-136px
;
}
.eauth-service-id-google
.eauth-service-link
:before
{
background-position
:
0
-34px
;
}
.eauth-service
{
text-indent
:
-9999px
;
margin
:
0
!important
;
}
.eauth-list
{
margin
:
0
!important
;
margin-top
:
10px
!important
;
}
}
\ No newline at end of file
frontend/web/css/screen.css
View file @
79ef690f
...
@@ -3967,7 +3967,7 @@ footer {
...
@@ -3967,7 +3967,7 @@ footer {
-webkit-border-radius
:
50px
;
-webkit-border-radius
:
50px
;
-o-border-radius
:
50px
;
-o-border-radius
:
50px
;
-ms-border-radius
:
50px
;
-ms-border-radius
:
50px
;
margin-bottom
:
34
px
;
margin-bottom
:
10
px
;
color
:
#698387
;
color
:
#698387
;
font-size
:
16px
;
font-size
:
16px
;
padding
:
0px
18px
;
padding
:
0px
18px
;
...
@@ -11461,7 +11461,7 @@ h6 {
...
@@ -11461,7 +11461,7 @@ h6 {
list-style
:
none
;
list-style
:
none
;
}
}
.teltext-block
{
.teltext-block
{
margin-top
:
-40px
;
/*margin-top: -40px;*/
margin-bottom
:
15px
;
margin-bottom
:
15px
;
color
:
#698387
;
color
:
#698387
;
font-size
:
14px
;
font-size
:
14px
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment