Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
8f6a9d34
Commit
8f6a9d34
authored
Oct 26, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
管理员登录
parent
8a9b6ee2
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
528 additions
and
336 deletions
+528
-336
main.php
src/backend/config/main.php
+1
-1
ClassesController.php
src/backend/controllers/ClassesController.php
+19
-0
CourseController.php
src/backend/controllers/CourseController.php
+19
-0
SiteController.php
src/backend/controllers/SiteController.php
+16
-3
LoginForm.php
src/backend/models/LoginForm.php
+113
-0
User.php
src/backend/models/User.php
+103
-0
back.php
src/backend/views/layouts/back.php
+199
-286
lte.php
src/backend/views/layouts/lte.php
+0
-4
login.php
src/backend/views/site/login.php
+42
-25
QiniuTranscode.php
src/common/libs/QiniuTranscode.php
+10
-15
params-local.php
src/environments/dev/common/config/params-local.php
+3
-1
params-local.php
src/environments/prod/common/config/params-local.php
+3
-1
No files found.
src/backend/config/main.php
View file @
8f6a9d34
...
@@ -17,7 +17,7 @@ return [
...
@@ -17,7 +17,7 @@ return [
'csrfParam'
=>
'_csrf-backend'
,
'csrfParam'
=>
'_csrf-backend'
,
],
],
'user'
=>
[
'user'
=>
[
'identityClass'
=>
'
common
\models\User'
,
'identityClass'
=>
'
backend
\models\User'
,
'enableAutoLogin'
=>
true
,
'enableAutoLogin'
=>
true
,
'identityCookie'
=>
[
'name'
=>
'_identity-backend'
,
'httpOnly'
=>
true
],
'identityCookie'
=>
[
'name'
=>
'_identity-backend'
,
'httpOnly'
=>
true
],
],
],
...
...
src/backend/controllers/ClassesController.php
View file @
8f6a9d34
...
@@ -13,6 +13,7 @@ use common\libs\Utils;
...
@@ -13,6 +13,7 @@ use common\libs\Utils;
use
common\models\Classes
;
use
common\models\Classes
;
use
common\models\User
;
use
common\models\User
;
use
Yii
;
use
Yii
;
use
yii\filters\AccessControl
;
use
yii\web\Controller
;
use
yii\web\Controller
;
class
ClassesController
extends
Controller
class
ClassesController
extends
Controller
...
@@ -20,6 +21,24 @@ class ClassesController extends Controller
...
@@ -20,6 +21,24 @@ class ClassesController extends Controller
public
$layout
=
'back'
;
public
$layout
=
'back'
;
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
'access'
=>
[
'class'
=>
AccessControl
::
className
(),
'rules'
=>
[
[
'allow'
=>
true
,
'roles'
=>
[
'@'
],
]
]
]
];
}
public
function
actionIndex
()
public
function
actionIndex
()
{
{
$status
=
Yii
::
$app
->
request
->
get
(
'status'
,
Classes
::
STATUS_OK
);
$status
=
Yii
::
$app
->
request
->
get
(
'status'
,
Classes
::
STATUS_OK
);
...
...
src/backend/controllers/CourseController.php
View file @
8f6a9d34
...
@@ -17,6 +17,7 @@ use common\models\TranscodeQueue;
...
@@ -17,6 +17,7 @@ use common\models\TranscodeQueue;
use
common\models\User
;
use
common\models\User
;
use
Yii
;
use
Yii
;
use
yii\base\ExitException
;
use
yii\base\ExitException
;
use
yii\filters\AccessControl
;
use
yii\web\Controller
;
use
yii\web\Controller
;
use
yii\web\NotFoundHttpException
;
use
yii\web\NotFoundHttpException
;
...
@@ -25,6 +26,24 @@ class CourseController extends Controller
...
@@ -25,6 +26,24 @@ class CourseController extends Controller
public
$layout
=
'back'
;
public
$layout
=
'back'
;
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
'access'
=>
[
'class'
=>
AccessControl
::
className
(),
'rules'
=>
[
[
'allow'
=>
true
,
'roles'
=>
[
'@'
],
]
]
]
];
}
public
function
actionIndex
()
public
function
actionIndex
()
{
{
$status
=
Yii
::
$app
->
request
->
get
(
'status'
,
Course
::
STATUS_OK
);
$status
=
Yii
::
$app
->
request
->
get
(
'status'
,
Course
::
STATUS_OK
);
...
...
src/backend/controllers/SiteController.php
View file @
8f6a9d34
<?php
<?php
namespace
backend\controllers
;
namespace
backend\controllers
;
use
backend\models\LoginForm
;
use
backend\models\User
;
use
common\libs\Utils
;
use
Yii
;
use
Yii
;
use
yii\web\Controller
;
use
yii\web\Controller
;
use
yii\filters\AccessControl
;
use
yii\filters\AccessControl
;
use
common\models\LoginForm
;
/**
/**
* Site controller
* Site controller
*/
*/
class
SiteController
extends
Controller
class
SiteController
extends
Controller
{
{
public
$layout
=
'lte'
;
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
...
@@ -53,7 +58,7 @@ class SiteController extends Controller
...
@@ -53,7 +58,7 @@ class SiteController extends Controller
*/
*/
public
function
actionIndex
()
public
function
actionIndex
()
{
{
return
$this
->
re
nder
(
'index'
);
return
$this
->
re
direct
([
'course/index'
]
);
}
}
/**
/**
...
@@ -63,6 +68,15 @@ class SiteController extends Controller
...
@@ -63,6 +68,15 @@ class SiteController extends Controller
*/
*/
public
function
actionLogin
()
public
function
actionLogin
()
{
{
//$user = new User();
//$user->username = 'admin';
//$user->password_hash = \Yii::$app->security->generatePasswordHash('111111');
//$user->ip = Utils::getRealIP();
//$user->logged_at = time();
//$user->save();
//
//print_r($user->errors);
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
return
$this
->
goHome
();
return
$this
->
goHome
();
}
}
...
@@ -85,7 +99,6 @@ class SiteController extends Controller
...
@@ -85,7 +99,6 @@ class SiteController extends Controller
public
function
actionLogout
()
public
function
actionLogout
()
{
{
Yii
::
$app
->
user
->
logout
();
Yii
::
$app
->
user
->
logout
();
return
$this
->
goHome
();
return
$this
->
goHome
();
}
}
}
}
src/backend/models/LoginForm.php
0 → 100644
View file @
8f6a9d34
<?php
namespace
backend\models
;
use
common\libs\Utils
;
use
Yii
;
use
yii\base\Model
;
/**
* Login form
*/
class
LoginForm
extends
Model
{
const
MAX_LOGIN_NUM
=
5
;
const
LOGIN_CYCLE
=
900
;
//second
const
REDIS_KEY_PREFIX
=
'yy_adminlogin_ip'
;
public
$username
;
public
$password
;
public
$rememberMe
=
true
;
private
$_user
;
public
function
formName
()
{
return
''
;
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
// username and password are both required
[[
'username'
,
'password'
],
'required'
],
// rememberMe must be a boolean value
// password is validated by validatePassword()
[
'password'
,
'validatePassword'
],
[
'username'
,
'string'
]
];
}
/**
* @return array
*/
public
function
attributeLabels
()
{
return
[
'username'
=>
'用户名'
,
'password'
=>
'密码'
,
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public
function
validatePassword
(
$attribute
,
$params
)
{
$redis
=
Yii
::
$app
->
redis
;
$key
=
self
::
REDIS_KEY_PREFIX
.
'::'
.
Utils
::
getRealIP
();
$value
=
$redis
->
get
(
$key
);
if
(
$value
===
NULL
)
{
$redis
->
setex
(
$key
,
self
::
LOGIN_CYCLE
,
self
::
MAX_LOGIN_NUM
);
}
else
{
if
(
$value
<=
0
)
{
$this
->
addError
(
'password'
,
'登陆已经被限制了.'
);
}
}
if
(
!
$this
->
hasErrors
())
{
$user
=
$this
->
getUser
();
if
(
!
$user
||
!
$user
->
validatePassword
(
$this
->
password
))
{
if
(
$value
!==
NULL
)
{
$redis
->
decr
(
$key
);
}
$this
->
addError
(
$attribute
,
'用户名或者密码错误'
);
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return boolean whether the user is logged in successfully
*/
public
function
login
()
{
if
(
$this
->
validate
())
{
return
Yii
::
$app
->
user
->
login
(
$this
->
getUser
(),
86400
*
7
);
}
else
{
return
false
;
}
}
/**
* Finds user by [[username]]
*
* @return User
*/
protected
function
getUser
()
{
if
(
$this
->
_user
===
NULL
)
{
$this
->
_user
=
User
::
findOne
([
'username'
=>
$this
->
username
]);
}
return
$this
->
_user
;
}
}
src/backend/models/User.php
0 → 100644
View file @
8f6a9d34
<?php
namespace
backend\models
;
use
yii\behaviors\TimestampBehavior
;
use
yii\db\ActiveRecord
;
/**
* 后台管理用户类
*
* @property integer $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property integer $status
* @property string $ip
* @property string $created_at
* @property string $updated_at
* @property string $logged_at
*/
class
User
extends
ActiveRecord
implements
\yii\web\IdentityInterface
{
public
static
function
tableName
()
{
return
'{{%admin_users}}'
;
}
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
[
'class'
=>
TimestampBehavior
::
className
(),
'attributes'
=>
[
ActiveRecord
::
EVENT_BEFORE_INSERT
=>
[
'created_at'
,
'updated_at'
],
ActiveRecord
::
EVENT_BEFORE_UPDATE
=>
[
'updated_at'
],
]
]
];
}
public
function
rules
()
{
return
[
[[
'username'
,
'password_hash'
,
'ip'
,
'logged_at'
],
'required'
],
[[
'id'
,
'status'
],
'integer'
],
[[
'created_at'
,
'updated_at'
,
'logged_at'
],
'safe'
],
[[
'username'
,
'auth_key'
,
'ip'
],
'string'
,
'max'
=>
32
],
[[
'password_hash'
],
'string'
,
'max'
=>
255
],
[
'status'
,
'default'
,
'value'
=>
1
]
];
}
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getAuthKey
()
{
return
$this
->
auth_key
;
}
public
function
validateAuthKey
(
$authKey
)
{
return
$this
->
getAuthKey
()
==
$authKey
;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public
function
validatePassword
(
$password
)
{
return
\Yii
::
$app
->
security
->
validatePassword
(
$password
,
$this
->
password_hash
);
}
public
function
beforeSave
(
$insert
)
{
if
(
parent
::
beforeSave
(
$insert
))
{
if
(
$this
->
isNewRecord
)
{
$this
->
auth_key
=
\Yii
::
$app
->
security
->
generateRandomString
();
}
return
true
;
}
return
false
;
}
public
static
function
findIdentity
(
$id
)
{
return
self
::
findOne
([
'id'
=>
$id
]);
}
public
static
function
findIdentityByAccessToken
(
$token
,
$type
=
null
)
{
throw
new
\yii\base\NotSupportedException
(
'"findIdentityByAccessToken" is not implemented.'
);
}
}
\ No newline at end of file
src/backend/views/layouts/back.php
View file @
8f6a9d34
This diff is collapsed.
Click to expand it.
src/backend/views/layouts/lte.php
View file @
8f6a9d34
...
@@ -24,12 +24,8 @@ AppAsset::register($this);
...
@@ -24,12 +24,8 @@ AppAsset::register($this);
<script src="http://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<script src="http://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<![endif]-->
</head>
</head>
<body
class=
"hold-transition skin-blue sidebar-mini"
>
<div
class=
"wrapper"
>
<?php
$this
->
beginBody
()
?>
<?php
$this
->
beginBody
()
?>
<?=
$content
?>
<?=
$content
?>
<?php
$this
->
endBody
()
?>
<?php
$this
->
endBody
()
?>
</div>
</body>
</html>
</html>
<?php
$this
->
endPage
()
?>
<?php
$this
->
endPage
()
?>
\ No newline at end of file
src/backend/views/site/login.php
View file @
8f6a9d34
<?php
<?php
/**
/* @var $this yii\web\View */
* @var $this yii\web\View
/* @var $form yii\bootstrap\ActiveForm */
* @var $form yii\bootstrap\ActiveForm
/* @var $model \common\models\LoginForm */
* @var $model \backend\models\LoginForm
*/
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\bootstrap\ActiveForm
;
use
yii\bootstrap\ActiveForm
;
$this
->
title
=
'Login'
;
$this
->
title
=
'Login'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
//$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'
)
->
textInput
([
'autofocus'
=>
true
])
?>
$usernameError
=
$model
->
getFirstError
(
'username'
);
$passwordError
=
$model
->
getFirstError
(
'password'
);
<?=
$form
->
field
(
$model
,
'password'
)
->
passwordInput
()
?>
?>
<?=
$form
->
field
(
$model
,
'rememberMe'
)
->
checkbox
()
?>
<div
class=
"form-group"
>
<body
class=
"hold-transition login-page"
>
<?=
Html
::
submitButton
(
'Login'
,
[
'class'
=>
'btn btn-primary'
,
'name'
=>
'login-button'
])
?>
<div
class=
"login-box"
>
<div
class=
"login-logo"
><b>
Admin
</b>
YunYa
</div>
<!-- /.login-logo -->
<div
class=
"login-box-body"
>
<p
class=
"login-box-msg"
>
Sign in to start your session
</p>
<?php
$form
=
ActiveForm
::
begin
([
'id'
=>
'login-form'
]);
?>
<div
class=
"form-group
<?php
if
(
$usernameError
)
{
?>
has-error
<?php
}
?>
"
>
<?php
if
(
$usernameError
)
{
?>
<label
class=
"control-label"
for=
"inputError"
>
<i
class=
"fa fa-times-circle-o"
></i>
<?=
$usernameError
?>
</label>
<?php
}
?>
<input
type=
"text"
name=
"username"
class=
"form-control"
placeholder=
"Username"
value=
"
<?=
$model
->
username
?>
"
>
<span
class=
"glyphicon glyphicon-user form-control-feedback"
></span>
</div>
<div
class=
"form-group
<?php
if
(
$passwordError
)
{
?>
has-error
<?php
}
?>
"
>
<?php
if
(
$passwordError
)
{
?>
<label
class=
"control-label"
for=
"inputError"
>
<i
class=
"fa fa-times-circle-o"
></i>
<?=
$passwordError
?>
</label>
<?php
}
?>
<input
type=
"password"
name=
"password"
class=
"form-control"
placeholder=
"Password"
value=
"
<?=
$model
->
password
?>
"
>
<span
class=
"glyphicon glyphicon-lock form-control-feedback"
></span>
</div>
<div
class=
"row"
>
<div
class=
"col-xs-8"
></div>
<div
class=
"col-xs-4"
>
<?=
Html
::
submitButton
(
'Sign In'
,
[
'class'
=>
'btn btn-primary btn-block btn-flat'
,
'name'
=>
'login-button'
])
?>
</div>
</div>
</div>
<?php
ActiveForm
::
end
();
?>
<?php
ActiveForm
::
end
();
?>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
src/common/libs/QiniuTranscode.php
View file @
8f6a9d34
...
@@ -53,20 +53,14 @@ class QiniuTranscode
...
@@ -53,20 +53,14 @@ class QiniuTranscode
$fops
=
self
::
transcodeFops
(
$avInfo
);
$fops
=
self
::
transcodeFops
(
$avInfo
);
$bucket
=
$qiniu
->
getStorageConfig
(
'video'
,
'bucket'
);
$bucket
=
$qiniu
->
getStorageConfig
(
'video'
,
'bucket'
);
$target
=
$bucket
.
':'
.
$targetKey
;
//存储位置
//存储位置
$target
=
$bucket
.
':'
.
$targetKey
;
$notifyUrl
=
YII_ENV
==
'dev'
?
'http://t.pp.cc/tmp/qiniu_callback.php'
:
Url
::
to
([
'qiniu-callback/transcode'
],
true
);;
/* @var $err null|\Qiniu\Http\Error */
/* @var $err null|\Qiniu\Http\Error */
if
(
$fops
)
{
if
(
$fops
)
{
$fops
.=
'|saveas/'
.
\Qiniu\base64_urlSafeEncode
(
$target
);
$fops
.=
'|saveas/'
.
\Qiniu\base64_urlSafeEncode
(
$target
);
//发送处理请求
//发送处理请求
$persistent
=
new
PersistentFop
(
$auth
,
$bucket
,
null
,
$notifyUrl
);
$persistent
=
new
PersistentFop
(
$auth
,
$bucket
,
null
,
self
::
getNotifyUrl
()
);
list
(
$presistendId
,
$err
)
=
$persistent
->
execute
(
$sourceKey
,
$fops
);
list
(
$presistendId
,
$err
)
=
$persistent
->
execute
(
$sourceKey
,
$fops
);
if
(
$err
)
{
if
(
$err
)
{
...
@@ -124,17 +118,11 @@ class QiniuTranscode
...
@@ -124,17 +118,11 @@ class QiniuTranscode
//存储位置
//存储位置
$target
=
$bucket
.
':'
.
$targetKey
;
$target
=
$bucket
.
':'
.
$targetKey
;
$fops
=
$fops
.
'/ss/0/t/'
.
(
$freeTime
*
60
)
.
'|saveas/'
.
\Qiniu\base64_urlSafeEncode
(
$target
);
$fops
=
$fops
.
'/ss/0/t/'
.
(
$freeTime
*
60
)
.
'|saveas/'
.
\Qiniu\base64_urlSafeEncode
(
$target
);
$notifyUrl
=
YII_ENV
==
'dev'
?
'http://t.pp.cc/tmp/qiniu_callback.php'
:
Url
::
to
([
'qiniu-callback/transcode'
],
true
);;
//发送处理请求
//发送处理请求
/* @var $err null|\Qiniu\Http\Error */
/* @var $err null|\Qiniu\Http\Error */
$persistent
=
new
PersistentFop
(
$auth
,
$bucket
,
null
,
$notifyUrl
);
$persistent
=
new
PersistentFop
(
$auth
,
$bucket
,
null
,
self
::
getNotifyUrl
()
);
list
(
$presistendId
,
$err
)
=
$persistent
->
execute
(
$standKey
,
$fops
);
list
(
$presistendId
,
$err
)
=
$persistent
->
execute
(
$standKey
,
$fops
);
if
(
$err
)
{
if
(
$err
)
{
...
@@ -211,5 +199,12 @@ class QiniuTranscode
...
@@ -211,5 +199,12 @@ class QiniuTranscode
return
$fops
;
return
$fops
;
}
}
protected
static
function
getNotifyUrl
()
{
return
YII_ENV
==
'dev'
?
'http://t.pp.cc/tmp/qiniu_callback.php'
:
Url
::
to
([
'qiniu-callback/transcode'
],
true
);
}
}
}
\ No newline at end of file
src/environments/dev/common/config/params-local.php
View file @
8f6a9d34
...
@@ -36,5 +36,7 @@ return [
...
@@ -36,5 +36,7 @@ return [
'mchid'
=>
'1399794002'
,
'mchid'
=>
'1399794002'
,
'key'
=>
'8934e7d15453e97507ef794cf7b0519d'
,
'key'
=>
'8934e7d15453e97507ef794cf7b0519d'
,
'appsecret'
=>
'7c18222c6ec31efa65d21606a629585d'
,
'appsecret'
=>
'7c18222c6ec31efa65d21606a629585d'
,
]
],
'fronend.baseUrl'
=>
'http://dev.zuiketang.com/'
,
'backend.baseUrl'
=>
'http://backend.zuiketang.com/'
];
];
src/environments/prod/common/config/params-local.php
View file @
8f6a9d34
...
@@ -36,5 +36,7 @@ return [
...
@@ -36,5 +36,7 @@ return [
'mchid'
=>
'1399794002'
,
'mchid'
=>
'1399794002'
,
'key'
=>
'8934e7d15453e97507ef794cf7b0519d'
,
'key'
=>
'8934e7d15453e97507ef794cf7b0519d'
,
'appsecret'
=>
'7c18222c6ec31efa65d21606a629585d'
,
'appsecret'
=>
'7c18222c6ec31efa65d21606a629585d'
,
]
],
'fronend.baseUrl'
=>
'http://c.pp.cc/'
,
'backend.baseUrl'
=>
'http://admin.c.pp.cc/'
];
];
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