%PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
| Server IP : 14.207.165.8 / Your IP : 216.73.216.26 Web Server : Apache/2.4.18 (Ubuntu) System : Linux 246 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : root ( 0) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/thread-self/root/var/www/html/ppaobm/vendor/dektrium/yii2-user/models/ |
Upload File : |
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dektrium\user\models;
use dektrium\user\traits\ModuleTrait;
use Yii;
use yii\base\Model;
/**
* Registration form collects user input on registration process, validates it and creates new User model.
*
* @author Dmitry Erofeev <dmeroff@gmail.com>
*/
class RegistrationForm extends Model
{
use ModuleTrait;
/**
* @var string User email address
*/
public $email;
/**
* @var string Username
*/
public $username;
/**
* @var string Password
*/
public $password;
/**
* @inheritdoc
*/
public function rules()
{
$user = $this->module->modelMap['User'];
return [
// username rules
'usernameTrim' => ['username', 'trim'],
'usernameLength' => ['username', 'string', 'min' => 3, 'max' => 255],
'usernamePattern' => ['username', 'match', 'pattern' => $user::$usernameRegexp],
'usernameRequired' => ['username', 'required'],
'usernameUnique' => [
'username',
'unique',
'targetClass' => $user,
'message' => Yii::t('user', 'This username has already been taken')
],
// email rules
'emailTrim' => ['email', 'trim'],
'emailRequired' => ['email', 'required'],
'emailPattern' => ['email', 'email'],
'emailUnique' => [
'email',
'unique',
'targetClass' => $user,
'message' => Yii::t('user', 'This email address has already been taken')
],
// password rules
'passwordRequired' => ['password', 'required', 'skipOnEmpty' => $this->module->enableGeneratingPassword],
'passwordLength' => ['password', 'string', 'min' => 6, 'max' => 72],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'email' => Yii::t('user', 'Email'),
'username' => Yii::t('user', 'Username'),
'password' => Yii::t('user', 'Password'),
];
}
/**
* @inheritdoc
*/
public function formName()
{
return 'register-form';
}
/**
* Registers a new user account. If registration was successful it will set flash message.
*
* @return bool
*/
public function register()
{
if (!$this->validate()) {
return false;
}
/** @var User $user */
$user = Yii::createObject(User::className());
$user->setScenario('register');
$this->loadAttributes($user);
if (!$user->register()) {
return false;
}
Yii::$app->session->setFlash(
'info',
Yii::t(
'user',
'Your account has been created and a message with further instructions has been sent to your email'
)
);
return true;
}
/**
* Loads attributes to the user model. You should override this method if you are going to add new fields to the
* registration form. You can read more in special guide.
*
* By default this method set all attributes of this model to the attributes of User model, so you should properly
* configure safe attributes of your User model.
*
* @param User $user
*/
protected function loadAttributes(User $user)
{
$user->setAttributes($this->attributes);
}
}