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
75917e2c
Commit
75917e2c
authored
May 25, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User and LoginForm are now common models, User is AR and Identity
parent
c4380f65
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
87 additions
and
186 deletions
+87
-186
main.php
apps/advanced/backstage/config/main.php
+1
-1
SiteController.php
apps/advanced/backstage/controllers/SiteController.php
+1
-29
main.php
apps/advanced/backstage/views/layouts/main.php
+0
-2
about.php
apps/advanced/backstage/views/site/about.php
+0
-16
contact.php
apps/advanced/backstage/views/site/contact.php
+0
-46
LoginForm.php
apps/advanced/common/models/LoginForm.php
+1
-1
User.php
apps/advanced/common/models/User.php
+81
-27
main.php
apps/advanced/frontend/config/main.php
+1
-1
SiteController.php
apps/advanced/frontend/controllers/SiteController.php
+2
-2
User.php
apps/advanced/frontend/models/User.php
+0
-61
No files found.
apps/advanced/backstage/config/main.php
View file @
75917e2c
...
...
@@ -19,7 +19,7 @@ return array(
'cache'
=>
$params
[
'components.cache'
],
'user'
=>
array
(
'class'
=>
'yii\web\User'
,
'identityClass'
=>
'
app
\models\User'
,
'identityClass'
=>
'
common
\models\User'
,
),
'assetManager'
=>
array
(
'bundles'
=>
require
(
__DIR__
.
'/assets.php'
),
...
...
apps/advanced/backstage/controllers/SiteController.php
View file @
75917e2c
...
...
@@ -4,20 +4,10 @@ namespace backstage\controllers;
use
Yii
;
use
yii\web\Controller
;
use
app\models\LoginForm
;
use
app\models\ContactForm
;
use
common\models\LoginForm
;
class
SiteController
extends
Controller
{
public
function
actions
()
{
return
array
(
'captcha'
=>
array
(
'class'
=>
'yii\web\CaptchaAction'
,
),
);
}
public
function
actionIndex
()
{
echo
$this
->
render
(
'index'
);
...
...
@@ -40,22 +30,4 @@ class SiteController extends Controller
Yii
::
$app
->
getUser
()
->
logout
();
Yii
::
$app
->
getResponse
()
->
redirect
(
array
(
'site/index'
));
}
public
function
actionContact
()
{
$model
=
new
ContactForm
;
if
(
$this
->
populate
(
$_POST
,
$model
)
&&
$model
->
contact
(
Yii
::
$app
->
params
[
'adminEmail'
]))
{
Yii
::
$app
->
session
->
setFlash
(
'contactFormSubmitted'
);
Yii
::
$app
->
response
->
refresh
();
}
else
{
echo
$this
->
render
(
'contact'
,
array
(
'model'
=>
$model
,
));
}
}
public
function
actionAbout
()
{
echo
$this
->
render
(
'about'
);
}
}
apps/advanced/backstage/views/layouts/main.php
View file @
75917e2c
...
...
@@ -31,8 +31,6 @@ $this->registerAssetBundle('app');
'options'
=>
array
(
'class'
=>
'nav'
),
'items'
=>
array
(
array
(
'label'
=>
'Home'
,
'url'
=>
array
(
'/site/index'
)),
array
(
'label'
=>
'About'
,
'url'
=>
array
(
'/site/about'
)),
array
(
'label'
=>
'Contact'
,
'url'
=>
array
(
'/site/contact'
)),
Yii
::
$app
->
user
->
isGuest
?
array
(
'label'
=>
'Login'
,
'url'
=>
array
(
'/site/login'
))
:
array
(
'label'
=>
'Logout ('
.
Yii
::
$app
->
user
->
identity
->
username
.
')'
,
'url'
=>
array
(
'/site/logout'
)),
...
...
apps/advanced/backstage/views/site/about.php
deleted
100644 → 0
View file @
c4380f65
<?php
use
yii\helpers\Html
;
/**
* @var yii\base\View $this
*/
$this
->
title
=
'About'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<h1>
<?php
echo
Html
::
encode
(
$this
->
title
);
?>
</h1>
<p>
This is the About page. You may modify the following file to customize its content:
</p>
<code>
<?php
echo
__FILE__
;
?>
</code>
apps/advanced/backstage/views/site/contact.php
deleted
100644 → 0
View file @
c4380f65
<?php
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
yii\widgets\Captcha
;
/**
* @var yii\base\View $this
* @var yii\widgets\ActiveForm $form
* @var app\models\ContactForm $model
*/
$this
->
title
=
'Contact'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<h1>
<?php
echo
Html
::
encode
(
$this
->
title
);
?>
</h1>
<?php
if
(
Yii
::
$app
->
session
->
hasFlash
(
'contactFormSubmitted'
))
:
?>
<div
class=
"alert alert-success"
>
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<?php
return
;
endif
;
?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<?php
$form
=
ActiveForm
::
begin
(
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
'fieldConfig'
=>
array
(
'inputOptions'
=>
array
(
'class'
=>
'input-xlarge'
)),
));
?>
<?php
echo
$form
->
field
(
$model
,
'name'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'email'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'subject'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'body'
)
->
textArea
(
array
(
'rows'
=>
6
));
?>
<?php
$field
=
$form
->
field
(
$model
,
'verifyCode'
);
echo
$field
->
begin
()
.
$field
->
label
()
.
Captcha
::
widget
()
.
Html
::
activeTextInput
(
$model
,
'verifyCode'
,
array
(
'class'
=>
'input-medium'
))
.
$field
->
error
()
.
$field
->
end
();
?>
<div
class=
"form-actions"
>
<?php
echo
Html
::
submitButton
(
'Submit'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
</div>
<?php
ActiveForm
::
end
();
?>
apps/advanced/
frontend
/models/LoginForm.php
→
apps/advanced/
common
/models/LoginForm.php
View file @
75917e2c
<?php
namespace
frontend
\models
;
namespace
common
\models
;
use
Yii
;
use
yii\base\Model
;
...
...
apps/advanced/common/models/User.php
View file @
75917e2c
<?php
namespace
common\models
;
class
User
extends
\yii\base\Object
implements
\yii\web\Identity
use
yii\db\ActiveRecord
;
use
yii\helpers\SecurityHelper
;
use
yii\web\Identity
;
/**
* Class User
* @package common\models
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $email
* @property string $auth_key
* @property integer $role
* @property integer $status
* @property integer $create_time
* @property integer $update_time
*/
class
User
extends
ActiveRecord
implements
Identity
{
public
$id
;
public
$username
;
/**
* @var string the raw password. Used to collect password input and isn't saved in database
*/
public
$password
;
public
$authKey
;
private
static
$users
=
array
(
'100'
=>
array
(
'id'
=>
'100'
,
'username'
=>
'admin'
,
'password'
=>
'admin'
,
'authKey'
=>
'test100key'
,
const
STATUS_DELETED
=
0
;
const
STATUS_ACTIVE
=
10
;
const
ROLE_USER
=
10
;
public
function
behaviors
()
{
return
array
(
'timestamp'
=>
array
(
'class'
=>
'yii\behaviors\AutoTimestamp'
,
'attributes'
=>
array
(
ActiveRecord
::
EVENT_BEFORE_INSERT
=>
'create_time'
,
ActiveRecord
::
EVENT_BEFORE_INSERT
=>
'update_time'
,
ActiveRecord
::
EVENT_BEFORE_UPDATE
=>
'update_time'
,
),
'101'
=>
array
(
'id'
=>
'101'
,
'username'
=>
'demo'
,
'password'
=>
'demo'
,
'authKey'
=>
'test101key'
,
),
);
}
public
static
function
findIdentity
(
$id
)
{
return
isset
(
self
::
$users
[
$id
])
?
new
self
(
self
::
$users
[
$id
])
:
null
;
return
static
::
find
(
$id
)
;
}
public
static
function
findByUsername
(
$username
)
{
foreach
(
self
::
$users
as
$user
)
{
if
(
strcasecmp
(
$user
[
'username'
],
$username
)
===
0
)
{
return
new
self
(
$user
);
}
}
return
null
;
return
static
::
find
(
array
(
'username'
=>
$username
,
'status'
=>
static
::
STATUS_ACTIVE
));
}
public
function
getId
()
...
...
@@ -46,16 +62,54 @@ class User extends \yii\base\Object implements \yii\web\Identity
public
function
getAuthKey
()
{
return
$this
->
auth
K
ey
;
return
$this
->
auth
_k
ey
;
}
public
function
validateAuthKey
(
$authKey
)
{
return
$this
->
auth
K
ey
===
$authKey
;
return
$this
->
auth
_k
ey
===
$authKey
;
}
public
function
validatePassword
(
$password
)
{
return
$this
->
password
===
$password
;
return
SecurityHelper
::
validatePassword
(
$password
,
$this
->
password_hash
);
}
public
function
rules
()
{
return
array
(
array
(
'username'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'username'
,
'required'
),
array
(
'username'
,
'length'
,
'min'
=>
2
,
'max'
=>
255
),
array
(
'email'
,
'filter'
,
'filter'
=>
'trim'
),
array
(
'email'
,
'required'
),
array
(
'email'
,
'email'
),
array
(
'email'
,
'unique'
,
'message'
=>
'This email address has already been taken.'
),
array
(
'password'
,
'required'
),
array
(
'password'
,
'length'
,
'min'
=>
6
),
);
}
public
function
scenarios
()
{
return
array
(
'signup'
=>
array
(
'username'
,
'email'
,
'password'
),
'login'
=>
array
(
'username'
,
'password'
),
);
}
public
function
beforeSave
(
$insert
)
{
if
(
parent
::
beforeSave
(
$insert
))
{
if
(
$this
->
isNewRecord
)
{
if
(
!
empty
(
$this
->
password
))
{
$this
->
password_hash
=
SecurityHelper
::
generatePasswordHash
(
$this
->
password
);
}
}
return
true
;
}
return
false
;
}
}
apps/advanced/frontend/config/main.php
View file @
75917e2c
...
...
@@ -19,7 +19,7 @@ return array(
'cache'
=>
$params
[
'components.cache'
],
'user'
=>
array
(
'class'
=>
'yii\web\User'
,
'identityClass'
=>
'
app
\models\User'
,
'identityClass'
=>
'
common
\models\User'
,
),
'assetManager'
=>
array
(
'bundles'
=>
require
(
__DIR__
.
'/assets.php'
),
...
...
apps/advanced/frontend/controllers/SiteController.php
View file @
75917e2c
...
...
@@ -4,8 +4,8 @@ namespace frontend\controllers;
use
Yii
;
use
yii\web\Controller
;
use
app
\models\LoginForm
;
use
app
\models\ContactForm
;
use
common
\models\LoginForm
;
use
frontend
\models\ContactForm
;
class
SiteController
extends
Controller
{
...
...
apps/advanced/frontend/models/User.php
deleted
100644 → 0
View file @
c4380f65
<?php
namespace
frontend\models
;
class
User
extends
\yii\base\Object
implements
\yii\web\Identity
{
public
$id
;
public
$username
;
public
$password
;
public
$authKey
;
private
static
$users
=
array
(
'100'
=>
array
(
'id'
=>
'100'
,
'username'
=>
'admin'
,
'password'
=>
'admin'
,
'authKey'
=>
'test100key'
,
),
'101'
=>
array
(
'id'
=>
'101'
,
'username'
=>
'demo'
,
'password'
=>
'demo'
,
'authKey'
=>
'test101key'
,
),
);
public
static
function
findIdentity
(
$id
)
{
return
isset
(
self
::
$users
[
$id
])
?
new
self
(
self
::
$users
[
$id
])
:
null
;
}
public
static
function
findByUsername
(
$username
)
{
foreach
(
self
::
$users
as
$user
)
{
if
(
strcasecmp
(
$user
[
'username'
],
$username
)
===
0
)
{
return
new
self
(
$user
);
}
}
return
null
;
}
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getAuthKey
()
{
return
$this
->
authKey
;
}
public
function
validateAuthKey
(
$authKey
)
{
return
$this
->
authKey
===
$authKey
;
}
public
function
validatePassword
(
$password
)
{
return
$this
->
password
===
$password
;
}
}
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