mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
specified proper namespaces
This commit is contained in:
@ -12,7 +12,7 @@ return array(
|
||||
'id' => 'change-me',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'preload' => array('log'),
|
||||
'controllerNamespace' => 'app\controllers',
|
||||
'controllerNamespace' => 'backstage\controllers',
|
||||
'modules' => array(
|
||||
),
|
||||
'components' => array(
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
namespace backstage\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
*/
|
||||
class ContactForm extends Model
|
||||
{
|
||||
public $name;
|
||||
public $email;
|
||||
public $subject;
|
||||
public $body;
|
||||
public $verifyCode;
|
||||
|
||||
/**
|
||||
* @return array the validation rules.
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return array(
|
||||
// name, email, subject and body are required
|
||||
array('name, email, subject, body', 'required'),
|
||||
// email has to be a valid email address
|
||||
array('email', 'email'),
|
||||
// verifyCode needs to be entered correctly
|
||||
array('verifyCode', 'captcha'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array customized attribute labels
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return array(
|
||||
'verifyCode' => 'Verification Code',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email to the specified email address using the information collected by this model.
|
||||
* @param string $email the target email address
|
||||
* @return boolean whether the model passes validation
|
||||
*/
|
||||
public function contact($email)
|
||||
{
|
||||
if ($this->validate()) {
|
||||
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?=';
|
||||
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?=';
|
||||
$headers = "From: $name <{$this->email}>\r\n" .
|
||||
"Reply-To: {$this->email}\r\n" .
|
||||
"MIME-Version: 1.0\r\n" .
|
||||
"Content-type: text/plain; charset=UTF-8";
|
||||
mail($email, $subject, $this->body, $headers);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* LoginForm is the model behind the login form.
|
||||
*/
|
||||
class LoginForm extends Model
|
||||
{
|
||||
public $username;
|
||||
public $password;
|
||||
public $rememberMe = true;
|
||||
|
||||
/**
|
||||
* @return array the validation rules.
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return array(
|
||||
// username and password are both required
|
||||
array('username, password', 'required'),
|
||||
// password is validated by validatePassword()
|
||||
array('password', 'validatePassword'),
|
||||
// rememberMe must be a boolean value
|
||||
array('rememberMe', 'boolean'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the password.
|
||||
* This method serves as the inline validation for password.
|
||||
*/
|
||||
public function validatePassword()
|
||||
{
|
||||
$user = User::findByUsername($this->username);
|
||||
if (!$user || !$user->validatePassword($this->password)) {
|
||||
$this->addError('password', 'Incorrect username or password.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()) {
|
||||
$user = User::findByUsername($this->username);
|
||||
Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
namespace common\models;
|
||||
|
||||
class User extends \yii\base\Object implements \yii\web\Identity
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ return array(
|
||||
'id' => 'change-me',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'preload' => array('log'),
|
||||
'controllerNamespace' => 'app\controllers',
|
||||
'controllerNamespace' => 'console\controllers',
|
||||
'modules' => array(
|
||||
),
|
||||
'components' => array(
|
||||
|
@ -12,7 +12,7 @@ return array(
|
||||
'id' => 'change-me',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'preload' => array('log'),
|
||||
'controllerNamespace' => 'app\controllers',
|
||||
'controllerNamespace' => 'frontend\controllers',
|
||||
'modules' => array(
|
||||
),
|
||||
'components' => array(
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
namespace frontend\models;
|
||||
|
||||
use yii\base\Model;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
namespace frontend\models;
|
||||
|
||||
class User extends \yii\base\Object implements \yii\web\Identity
|
||||
{
|
||||
|
Reference in New Issue
Block a user