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
2c67fabe
Commit
2c67fabe
authored
May 06, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge cms
parent
c54b300b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
300 additions
and
113 deletions
+300
-113
backend/config/main.php
backend/config/main.php
+3
-0
backend/controllers/SiteController.php
backend/controllers/SiteController.php
+30
-1
backend/views/site/login.php
backend/views/site/login.php
+69
-102
backend/views/site/recovery.php
backend/views/site/recovery.php
+67
-0
common/mail/passwordResetToken-html.php
common/mail/passwordResetToken-html.php
+2
-2
common/mail/passwordResetToken-text.php
common/mail/passwordResetToken-text.php
+2
-2
common/models/RecoveryForm.php
common/models/RecoveryForm.php
+90
-0
common/modules/users/models/User.php
common/modules/users/models/User.php
+37
-6
No files found.
backend/config/main.php
View file @
2c67fabe
...
...
@@ -35,6 +35,9 @@ return [
'analyticsSchool'
=>
[
'class'
=>
'common\modules\analyticsSchool\Module'
,],
],
'components'
=>
[
'mailer'
=>
[
'class'
=>
'yii\swiftmailer\Mailer'
,
],
'session'
=>
[
'class'
=>
'yii\web\Session'
,
],
...
...
backend/controllers/SiteController.php
View file @
2c67fabe
...
...
@@ -4,7 +4,9 @@ namespace backend\controllers;
use
Yii
;
use
yii\filters\AccessControl
;
use
yii\web\Controller
;
use
common\models\LoginForm
;
use
common\models\RecoveryForm
;
use
common\modules\users\models\User
;
/**
...
...
@@ -24,7 +26,7 @@ class SiteController extends Controller
'class'
=>
AccessControl
::
className
(),
'rules'
=>
[
[
'actions'
=>
[
'login'
,
'error'
],
'actions'
=>
[
'login'
,
'
recovery'
,
'
error'
],
'allow'
=>
true
,
],
[
...
...
@@ -81,6 +83,33 @@ class SiteController extends Controller
}
}
public
function
actionRecovery
()
{
if
(
!
\Yii
::
$app
->
user
->
isGuest
)
{
return
$this
->
goHome
();
}
$this
->
page_title
=
'Востановление пароля'
;
$this
->
layout
=
"blank"
;
$success
=
false
;
$model
=
new
RecoveryForm
();
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
())
&&
$model
->
validate
())
{
$model
->
recovery
();
$success
=
true
;
}
return
$this
->
render
(
'recovery'
,
[
'model'
=>
$model
,
'success'
=>
$success
,
]);
}
public
function
actionLogout
()
{
Yii
::
$app
->
user
->
logout
();
...
...
backend/views/site/login.php
View file @
2c67fabe
...
...
@@ -6,116 +6,83 @@ use yii\bootstrap\ActiveForm;
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */
$this
->
title
=
'Login'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<!--
<div class="site-login">
<h1>
<?=
Html
::
encode
(
$this
->
title
)
?>
</h1>
<p>Please fill out the following fields to login:</p>
<div class="row">
<div class="col-lg-5">
<?php
$form
=
ActiveForm
::
begin
([
'id'
=>
'login-form'
]);
?>
<?=
$form
->
field
(
$model
,
'username'
)
?>
<?=
$form
->
field
(
$model
,
'password'
)
->
passwordInput
()
?>
<?=
$form
->
field
(
$model
,
'rememberMe'
)
->
checkbox
()
?>
<div class="form-group">
<?=
Html
::
submitButton
(
'Login'
,
[
'class'
=>
'btn btn-primary'
,
'name'
=>
'login-button'
])
?>
</div>
<?php
ActiveForm
::
end
();
?>
<!-- begin login -->
<div
class=
"login login-v2"
data-pageload-addclass=
"animated flipInX"
>
<!-- begin brand -->
<div
class=
"login-header"
>
<div
class=
"brand"
>
<img
src=
"/img/logo.png"
>
<small>
Авторизация
</small>
</div>
<div
class=
"icon"
>
<i
class=
"fa fa-sign-in"
></i>
</div>
</div>
</div>
-->
<!-- end brand -->
<div
class=
"login-content"
>
<?php
$form
=
ActiveForm
::
begin
([
'enableClientValidation'
=>
true
,
'id'
=>
'login-form'
,
'options'
=>
[
'class'
=>
'margin-bottom-0'
],
'fieldConfig'
=>
[
'template'
=>
'{input}{error}'
,
],
]);
?>
<div
class=
"form-group m-b-20"
>
<?=
$form
->
field
(
$model
,
'username'
,
[
'inputOptions'
=>
[
'class'
=>
'form-control input-lg'
,
'placeholder'
=>
'Укажи свой e-mail для того чтобы зайти'
,
]
]
)
->
label
(
false
)
?>
</div>
<div
class=
"form-group m-b-20"
style=
"margin-bottom: 0 !important; margin-bottom: 0;"
>
<?=
$form
->
field
(
$model
,
'password'
,
[
'inputOptions'
=>
[
'class'
=>
'form-control input-lg'
,
'placeholder'
=>
'Пароль'
,
<!-- begin login -->
<div
class=
"login login-v2"
data-pageload-addclass=
"animated flipInX"
>
<!-- begin brand -->
<div
class=
"login-header"
>
<div
class=
"brand"
>
<img
src=
"/img/logo.png"
>
<small>
Virtual intelligence exists
</small>
<!-- Микрокредит
<small>Микрокредит Микрокредит Микрокредит</small>-->
</div>
<div
class=
"icon"
>
<i
class=
"fa fa-sign-in"
></i>
</div>
],
'options'
=>
[
'style'
=>
'margin-bottom: 0 !important;'
,
],
]
)
->
passwordInput
()
->
label
(
false
)
?>
</div>
<!-- end brand -->
<div
class=
"login-content"
>
<?php
$form
=
ActiveForm
::
begin
([
'enableClientValidation'
=>
true
,
'id'
=>
'login-form'
,
'options'
=>
[
'class'
=>
'margin-bottom-0'
],
'fieldConfig'
=>
[
'template'
=>
'{input}{error}'
,
],
]);
?>
<div
class=
"form-group m-b-20"
>
<div
class=
"checkbox m-b-20"
style=
"margin-top: 0; margin-bottom: 0 !important;"
>
<label>
<?=
$form
->
field
(
$model
,
'username'
,
[
'inputOptions'
=>
[
'class'
=>
'form-control input-lg'
,
'placeholder'
=>
'Укажи свой e-mail для того чтобы зайти'
,
]
]
)
->
label
(
false
)
?>
</div>
<div
class=
"form-group m-b-20"
style=
"margin-bottom: 0 !important; margin-bottom: 0;"
>
<?=
$form
->
field
(
$model
,
'password'
,
[
'inputOptions'
=>
[
'class'
=>
'form-control input-lg'
,
'placeholder'
=>
'Пароль'
,
],
'options'
=>
[
'style'
=>
'margin-bottom: 0 !important;'
,
],
]
)
->
passwordInput
()
->
label
(
false
)
?>
</div>
<div
class=
"checkbox m-b-20"
style=
"margin-top: 0; margin-bottom: 0 !important;"
>
<label>
<?=
$form
->
field
(
$model
,
'rememberMe'
,
[
'labelOptions'
=>
[
'style'
=>
'padding-left: 0;'
]
]
)
->
checkbox
()
->
label
(
'Запомнить мой компьютер.'
)
?>
</label>
</div>
<div
class=
"login-buttons"
>
<?=
Html
::
submitButton
(
'Войти'
,
[
'class'
=>
'btn btn-success btn-block btn-lg'
,
'name'
=>
'login-button'
])
?>
</div>
<!--div class="m-t-20">
Забыли свой пароль? Нажмите <a href="#">здесь</a> чтобы восстановить.
</div-->
<?php
ActiveForm
::
end
();
?>
$model
,
'rememberMe'
,
[
'labelOptions'
=>
[
'style'
=>
'padding-left: 0;'
]
]
)
->
checkbox
()
->
label
(
'Запомнить мой компьютер.'
)
?>
</label>
</div>
</div>
<!-- end login -->
<!--
<ul class="login-bg-list">
<li class="active"><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-1.jpg" alt="" /></a></li>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-2.jpg" alt="" /></a></li>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-3.jpg" alt="" /></a></li>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-4.jpg" alt="" /></a></li>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-5.jpg" alt="" /></a></li>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-6.jpg" alt="" /></a></li>
</ul>
-->
<div
class=
"login-buttons"
>
<?=
Html
::
submitButton
(
'Войти'
,
[
'class'
=>
'btn btn-success btn-block btn-lg'
,
'name'
=>
'login-button'
])
?>
</div>
<div
class=
"m-t-20"
>
Забыли свой пароль? Нажмите
<?=
Html
::
a
(
'здесь'
,
[
'recovery'
])
?>
чтобы восстановить.
</div>
<?php
ActiveForm
::
end
();
?>
</div>
</div>
<!-- end login -->
<?php
$this
->
registerJsFile
(
'/js/login-v2.demo.min.js'
,
[
'position'
=>
\yii\web\View
::
POS_END
]);
...
...
backend/views/site/recovery.php
0 → 100644
View file @
2c67fabe
<?php
use
yii\helpers\Html
;
use
yii\bootstrap\ActiveForm
;
?>
<!-- begin login -->
<div
class=
"login login-v2"
data-pageload-addclass=
"animated flipInX"
>
<!-- begin brand -->
<div
class=
"login-header"
>
<div
class=
"brand"
>
<img
src=
"/img/logo.png"
>
<small>
Востановление пароля
</small>
</div>
<div
class=
"icon"
>
<i
class=
"fa fa-sign-in"
></i>
</div>
</div>
<!-- end brand -->
<div
class=
"login-content"
>
<?php
if
(
$success
)
:
?>
<center>
На указанные e-mail отправлено письмо для подтверждения.
<br>
<?=
Html
::
a
(
'Вернуться к авторизации'
,
[
'login'
])
?>
</center>
<?php
else
:
?>
<?php
$form
=
ActiveForm
::
begin
([
'enableClientValidation'
=>
true
,
'id'
=>
'login-form'
,
'options'
=>
[
'class'
=>
'margin-bottom-0'
],
'fieldConfig'
=>
[
'template'
=>
'{input}{error}'
,
],
]);
?>
<div
class=
"form-group m-b-20"
>
<?=
$form
->
field
(
$model
,
'email'
,
[
'inputOptions'
=>
[
'class'
=>
'form-control input-lg'
,
'placeholder'
=>
'Укажи свой e-mail'
,
]
]
)
->
label
(
false
)
?>
</div>
<div
class=
"login-buttons"
>
<?=
Html
::
submitButton
(
'Востановить'
,
[
'class'
=>
'btn btn-success btn-block btn-lg'
,
'name'
=>
'login-button'
])
?>
</div>
<?php
ActiveForm
::
end
();
?>
<div
class=
"m-t-20"
>
<center>
<?=
Html
::
a
(
'Вернуться к авторизации'
,
[
'login'
])
?>
</center>
</div>
<?php
endif
;
?>
</div>
</div>
<!-- end login -->
<?php
$this
->
registerJsFile
(
'/js/login-v2.demo.min.js'
,
[
'position'
=>
\yii\web\View
::
POS_END
]);
$this
->
registerJs
(
'App.init();LoginV2.init();'
,
\yii\web\View
::
POS_READY
);
?>
\ No newline at end of file
common/mail/passwordResetToken-html.php
View file @
2c67fabe
...
...
@@ -4,10 +4,10 @@ use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $user common\models\User */
$resetLink
=
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
([
'site/reset-password'
,
'token'
=>
$user
->
password_
reset_token
]);
$resetLink
=
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
([
'site/reset-password'
,
'token'
=>
$user
->
password_
change_code
]);
?>
<div
class=
"password-reset"
>
<p>
Hello
<?=
Html
::
encode
(
$user
->
username
)
?>
,
</p>
<p>
Hello
<?=
Html
::
encode
(
$user
->
fio
)
?>
,
</p>
<p>
Follow the link below to reset your password:
</p>
...
...
common/mail/passwordResetToken-text.php
View file @
2c67fabe
...
...
@@ -3,9 +3,9 @@
/* @var $this yii\web\View */
/* @var $user common\models\User */
$resetLink
=
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
([
'site/reset-password'
,
'token'
=>
$user
->
password_
reset_token
]);
$resetLink
=
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
([
'site/reset-password'
,
'token'
=>
$user
->
password_
change_code
]);
?>
Hello
<?=
$user
->
username
?>
,
Hello
<?=
$user
->
fio
?>
,
Follow the link below to reset your password:
...
...
common/models/RecoveryForm.php
0 → 100644
View file @
2c67fabe
<?php
namespace
common\models
;
use
Yii
;
use
yii\base\Model
;
use
common\models\Settings
;
use
common\modules\users\models\User
;
class
RecoveryForm
extends
Model
{
public
$email
;
private
$_user
=
null
;
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[
'email'
,
'filter'
,
'filter'
=>
'trim'
],
[[
'email'
],
'required'
,
'message'
=>
'Укажи свой e-mail для восстановления пароля.'
],
[[
'email'
],
'email'
,
'message'
=>
'Некорректный формат.'
],
[
'email'
,
'validateEmail'
],
];
}
public
function
validateEmail
(
$attribute
,
$params
)
{
if
(
!
$this
->
hasErrors
())
{
$user
=
$this
->
getUser
();
if
(
!
$user
)
{
$this
->
addError
(
$attribute
,
'Такой пользователь не найден.'
);
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return boolean whether the user is logged in successfully
*/
public
function
recovery
()
{
$user
=
$this
->
getUser
();
if
(
!
User
::
isPasswordResetTokenValid
(
$user
->
password_change_code
))
{
$user
->
generatePasswordResetToken
();
}
if
(
$user
->
save
())
{
return
Yii
::
$app
->
mailer
->
compose
([
'html'
=>
'passwordResetToken-html'
,
'text'
=>
'passwordResetToken-text'
],
[
'user'
=>
$user
])
->
setFrom
(
Settings
::
getValue
(
'content-support-email'
))
->
setTo
(
$this
->
email
)
->
setSubject
(
'Восстановление пароля'
)
->
send
();
}
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public
function
getUser
()
{
if
(
$this
->
_user
===
null
)
{
$this
->
_user
=
User
::
findOne
([
'status'
=>
User
::
STATUS_ACTIVE
,
'email'
=>
$this
->
email
,
]);
}
return
$this
->
_user
;
}
public
function
attributeLabels
()
{
return
[
'email'
=>
'E-mail'
,
];
}
}
common/modules/users/models/User.php
View file @
2c67fabe
...
...
@@ -202,11 +202,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
[[
'password'
],
'safe'
,
'on'
=>
[
self
::
SCENARIO_UPDATE
,
]],
/*[['email'], 'email', 'message' => $this->emailErrorMessage(), 'on'=> [
self::SCENARIO_RECOVER_PASSWORD,
self::SCENARIO_SEND_NEW_PASSWORD,
self::SCENARIO_LOGIN,
]],*/
[[
'email'
],
'unique'
,
'on'
=>
[
self
::
SCENARIO_REGISTRATION
,
self
::
SCENARIO_CREATE
,
...
...
@@ -308,10 +303,45 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
}
return
static
::
findOne
([
'password_
reset_token
'
=>
$token
,
'password_
change_code
'
=>
$token
,
'status'
=>
self
::
STATUS_ACTIVE
,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return boolean
*/
public
static
function
isPasswordResetTokenValid
(
$token
)
{
if
(
empty
(
$token
))
{
return
false
;
}
$timestamp
=
(
int
)
substr
(
$token
,
strrpos
(
$token
,
'_'
)
+
1
);
$expire
=
Yii
::
$app
->
params
[
'user.passwordResetTokenExpire'
];
return
$timestamp
+
$expire
>=
time
();
}
/**
* Generates new password reset token
*/
public
function
generatePasswordResetToken
()
{
$this
->
password_change_code
=
Yii
::
$app
->
security
->
generateRandomString
()
.
'_'
.
time
();
$this
->
password_change_date
=
date
(
'Y-m-d H:i:s'
);
}
/**
* Removes password reset token
*/
public
function
removePasswordResetToken
()
{
$this
->
password_change_code
=
null
;
}
public
function
getPost
()
{
...
...
@@ -588,6 +618,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
return
$result
;
}
public
function
beforeDelete
()
{
if
(
parent
::
beforeDelete
())
...
...
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