Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/trieyouth/basic into dcc
Browse files Browse the repository at this point in the history
# Conflicts:
#	controllers/LoginController.php
#	models/User.php
  • Loading branch information
cxqz520 committed Dec 16, 2015
2 parents dfd610f + dabca46 commit 2ed6504
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=horder',
'username' => 'root',
'password' => 'standno58no',
'password' => '',
'charset' => 'utf8',
];
25 changes: 24 additions & 1 deletion controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,36 @@
use app\util\IntentUtil;
use Yii;
use yii\base\Controller;
use yii\filters\AccessControl;

class HomeController extends Controller
{
public $layout = "@app/views/layouts/base.php";

public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['index'],
'rules' => [
[
'allow' => true,
'actions' => [],
'roles' => ['?'],
],
[
'allow' => true,
'actions' => ['index'],
'roles' => ['@'],
],
],
],
];
}

public function actionIndex()
{
$this->layout = "@app/views/layouts/base.php";
IntentUtil::sendParams('youth','@web/img/welcome.png');
return $this->render('index');
}
Expand Down
22 changes: 11 additions & 11 deletions controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace app\controllers;

use app\models\LoginForm;
use app\models\User;
use Yii;
use yii\base\Controller;
use yii\filters\AccessControl;
Expand All @@ -25,10 +26,10 @@ public function behaviors()//行为验证 是登陆状态还是登出状态 要
'class' => AccessControl::className(),
'only' => ['login', 'logout', 'signup'],
'denyCallback' => function ($rule, $action) {
if(strcmp($action->id,'logout')==0){
if (strcmp($action->id, 'logout') == 0) {
throw new \Exception('您还没有登陆');
}
if(strcmp($action->id,'login')==0 || strcmp($action->id,'signup')==0){
if (strcmp($action->id, 'login') == 0 || strcmp($action->id, 'signup') == 0) {
throw new \Exception('您已经登陆');
}
},
Expand All @@ -55,27 +56,26 @@ public function actionIndex()

public function actionLogin()
{
if(!Yii::$app->user->isGuest){//看是否已经登陆
return Yii::$app->response->redirect(['home/index']);//controller之间的调用

if (!Yii::$app->user->isGuest) {
return Yii::$app->response->redirect(['home/index']);
}

$login = new LoginForm();

if($login->load(Yii::$app->request->post()) && $login->validate()){
if ($login->load(Yii::$app->request->post()) && $login->login()) {
return Yii::$app->response->redirect(['home/index']);
}else{
return $this->render('login',[
'model' => $login,
]);
} else {
return $this->render('login', [
'model' => $login,
]);
}

}

public function actionLogout()
{
if(YII::$app->user->isGuest){

}
}

public function actionSignUp()
Expand Down
4 changes: 2 additions & 2 deletions models/LoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function rules()
[['username', 'password'], 'required','message'=>'不能为空'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword','message'=>'密码或用户名错误'],
['username','email','message'=>'用户名格式不正确'],
['password','string','max'=>18, 'min'=>6, 'tooLong'=>'密码请输入长度为6-18位字符', 'tooShort'=>'密码请输入长度为6-18位字符'],
// password is validated by validatePassword()
['password', 'validatePassword','message'=>'密码或用户名错误'],
];
}

Expand Down
25 changes: 11 additions & 14 deletions models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

namespace app\models;

use yii\base\Object;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;

class User extends ActiveRecord implements IdentityInterface
{

public static function tableName()
{
return 'store';
}//会去找这个表名
}

/**
* @inheritdoc
*/
public static function findIdentity($id)//在当前表中寻找当前$id 默认在主键
public static function findIdentity($id)
{
$user = static::findOne($id);
if($user === null) {

}else{
}
$user = User::findOne($id);
return $user;
}

Expand All @@ -31,18 +29,18 @@ public static function findIdentity($id)//在当前表中寻找当前$id 默认

public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['token'=>$token]);
return static::findOne(['token' => $token]);
}

/**
* Finds user by username
*
* @param string $username
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['name'=>$username]);
return static::findOne(['name' => $username]);
}

/**
Expand All @@ -58,26 +56,25 @@ public function getId()
*/
public function getAuthKey()
{
return $this->authKey;
return $this->auth_key;
}

/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
return $this->auth_key === $authKey;
}

/**
* Validates password
*
* @param string $password password to validate
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
$user = $this->find();
return $this->pwd === $password;
}
}
2 changes: 1 addition & 1 deletion util/IntentUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function sendParams($name,$head){
throw new \Exception("util IntentUtil sendParams方法的head参数不可以是空");
}
$view = \Yii::$app->view;
$view->params['name']=$name;
$view->params['name']=\Yii::$app->user->getId().'ddddd';
$view->params['head']=Url::to($head,true);
$view->params['back']=Url::to('@web/img/fond.png',true);
}
Expand Down

0 comments on commit 2ed6504

Please sign in to comment.