Initial commit,修正
This commit is contained in:
Executable
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
# @Author: fm453
|
||||
# @Date: 1970-01-01T08:00:00+08:00
|
||||
# @Email: fm43@hiluker.com
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-14T19:52:26+08:00
|
||||
|
||||
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\Member;
|
||||
|
||||
/**
|
||||
* Signup form
|
||||
*/
|
||||
class SignupForm extends Model
|
||||
{
|
||||
public $username;
|
||||
public $mobile;
|
||||
public $email;
|
||||
public $password;
|
||||
public $verifyCode;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['username', 'trim'],
|
||||
['username', 'required'],
|
||||
['username', 'unique', 'targetClass' => '\common\models\Member', 'message' => '该用户名已经有人注册了.'],
|
||||
['username', 'string', 'min' => 2, 'max' => 255],
|
||||
|
||||
['mobile', 'trim'],
|
||||
['mobile', 'required'],
|
||||
['mobile', 'string', 'length' => 11],
|
||||
['mobile', 'unique', 'targetClass' => '\common\models\Member', 'message' => '该手机号已经注册使用了.'],
|
||||
|
||||
['email', 'trim'],
|
||||
['email', 'required'],
|
||||
['email', 'email'],
|
||||
['email', 'string', 'max' => 255],
|
||||
['email', 'unique', 'targetClass' => '\common\models\Member', 'message' => '该邮箱地址已经有人使用了.'],
|
||||
|
||||
['verifyCode', 'captcha'],
|
||||
|
||||
['password', 'required'],
|
||||
['password', 'string', 'min' => 6],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'username' => Yii::t('frontend','Username'),
|
||||
'mobile' => Yii::t('frontend','Mobile'),
|
||||
'password' => Yii::t('frontend','Password'),
|
||||
'email' => Yii::t('frontend','Email'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs user up.
|
||||
*
|
||||
* @return User|null the saved model or null if saving fails
|
||||
*/
|
||||
public function signup()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = new Member();
|
||||
$user->username = $this->username;
|
||||
$user->mobile = $this->mobile;
|
||||
$user->email = $this->email;
|
||||
$user->setPassword($this->password);
|
||||
$user->generateAuthKey();
|
||||
|
||||
return $user->save() ? $user : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user