Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
6ad0d72a
Commit
6ad0d72a
authored
Jan 31, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extracted password-related code into User model methods
parent
71fba077
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
9 deletions
+34
-9
User.php
apps/advanced/common/models/User.php
+26
-0
PasswordResetRequestForm.php
...advanced/common/models/forms/PasswordResetRequestForm.php
+2
-2
ResetPasswordForm.php
apps/advanced/common/models/forms/ResetPasswordForm.php
+3
-3
SignupForm.php
apps/advanced/common/models/forms/SignupForm.php
+3
-4
No files found.
apps/advanced/common/models/User.php
View file @
6ad0d72a
...
...
@@ -97,6 +97,32 @@ class User extends ActiveRecord implements IdentityInterface
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public
function
setPassword
(
$password
)
{
$this
->
password_hash
=
Security
::
generatePasswordHash
(
$password
);
}
/**
* Generates new password reset token
*/
public
function
generatePasswordResetToken
()
{
$this
->
password_reset_token
=
Security
::
generateRandomKey
();
}
/**
* Removes password reset token
*/
public
function
removePasswordResetToken
()
{
$this
->
password_reset_token
=
''
;
}
/**
* @inheritdoc
*/
public
function
rules
()
...
...
apps/advanced/common/models/forms/PasswordResetRequestForm.php
View file @
6ad0d72a
...
...
@@ -3,7 +3,6 @@ namespace common\models\forms;
use
common\models\User
;
use
yii\base\Model
;
use
yii\helpers\Security
;
/**
* Password reset request form
...
...
@@ -31,6 +30,7 @@ class PasswordResetRequestForm extends Model
*/
public
function
sendEmail
()
{
/** @var User $user */
$user
=
User
::
find
([
'status'
=>
User
::
STATUS_ACTIVE
,
'email'
=>
$this
->
email
,
...
...
@@ -40,7 +40,7 @@ class PasswordResetRequestForm extends Model
return
false
;
}
$user
->
password_reset_token
=
Security
::
generateRandomKey
();
$user
->
generatePasswordResetToken
();
if
(
$user
->
save
())
{
return
\Yii
::
$app
->
mail
->
compose
(
'passwordResetToken'
,
[
'user'
=>
$user
])
->
setFrom
([
\Yii
::
$app
->
params
[
'supportEmail'
]
=>
\Yii
::
$app
->
name
.
' robot'
])
...
...
apps/advanced/common/models/forms/ResetPasswordForm.php
View file @
6ad0d72a
...
...
@@ -4,7 +4,6 @@ namespace common\models\forms;
use
common\models\User
;
use
yii\base\InvalidParamException
;
use
yii\base\Model
;
use
yii\helpers\Security
;
use
Yii
;
/**
...
...
@@ -27,6 +26,7 @@ class ResetPasswordForm extends Model
*/
public
function
__construct
(
$token
)
{
parent
::
__construct
();
if
(
empty
(
$token
)
||
!
is_string
(
$token
))
{
throw
new
InvalidParamException
(
'Password reset token cannot be blank.'
);
}
...
...
@@ -58,8 +58,8 @@ class ResetPasswordForm extends Model
{
$user
=
$this
->
_user
;
if
(
$user
->
validate
())
{
$user
->
password_hash
=
Security
::
generatePasswordHash
(
$this
->
password
);
$user
->
password_reset_token
=
''
;
$user
->
setPassword
(
$this
->
password
);
$user
->
removePasswordResetToken
()
;
return
$user
->
save
();
}
else
{
return
false
;
...
...
apps/advanced/common/models/forms/SignupForm.php
View file @
6ad0d72a
...
...
@@ -3,7 +3,6 @@ namespace common\models\forms;
use
common\models\User
;
use
yii\base\Model
;
use
yii\helpers\Security
;
use
Yii
;
/**
...
...
@@ -45,10 +44,10 @@ class SignupForm extends Model
$user
=
new
User
();
$user
->
username
=
$this
->
username
;
$user
->
email
=
$this
->
email
;
$user
->
password_hash
=
Security
::
generatePasswordHash
(
$this
->
password
);
$user
->
auth_key
=
Security
::
generateRandomKey
();
$user
->
setPassword
(
$this
->
password
);
$user
->
generatePasswordResetToken
();
$user
->
role
=
User
::
ROLE_USER
;
$user
->
status
=
U
S
er
::
STATUS_ACTIVE
;
$user
->
status
=
U
s
er
::
STATUS_ACTIVE
;
if
(
$user
->
save
())
{
return
$user
;
}
...
...
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