Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration widget #913

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Module extends BaseModule
/** @var bool Enable the 'impersonate as another user' function */
public $enableImpersonateUser = true;

/** @var bool Enable gravatar profile avatars */
public $enableGravatar = true;

/** @var int Email changing strategy. */
public $emailChangeStrategy = self::STRATEGY_DEFAULT;

Expand Down
43 changes: 5 additions & 38 deletions views/registration/register.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/*
* This file is part of the Dektrium project.
*
Expand All @@ -8,47 +7,15 @@
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

use yii\helpers\Html;
use yii\widgets\ActiveForm;

use dektrium\user\widgets\Register;
/**
* @var yii\web\View $this
* @var dektrium\user\models\User $model
* @var dektrium\user\Module $module
*/

$this->title = Yii::t('user', 'Sign up');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?= Html::encode($this->title) ?></h3>
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin([
'id' => 'registration-form',
'enableAjaxValidation' => true,
'enableClientValidation' => false,
]); ?>

<?= $form->field($model, 'email') ?>

<?= $form->field($model, 'username') ?>

<?php if ($module->enableGeneratingPassword == false): ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?php endif ?>

<?= Html::submitButton(Yii::t('user', 'Sign up'), ['class' => 'btn btn-success btn-block']) ?>

<?php ActiveForm::end(); ?>
</div>
</div>
<p class="text-center">
<?= Html::a(Yii::t('user', 'Already registered? Sign in!'), ['/user/security/login']) ?>
</p>
</div>
</div>
echo Register::widget([
'model' => $model,
'title' => $this->title,
'enableGeneratingPassword' => $module->enableGeneratingPassword]);
4 changes: 2 additions & 2 deletions views/settings/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
)
); ?>

<?= $form
<?= ($this->context->module->enableGravatar)? $form
->field($model, 'gravatar_email')
->hint(Html::a(Yii::t('user', 'Change your avatar at Gravatar.com'), 'http://gravatar.com')) ?>
->hint(Html::a(Yii::t('user', 'Change your avatar at Gravatar.com'), 'http://gravatar.com')) : null ?>

<?= $form->field($model, 'bio')->textarea() ?>

Expand Down
93 changes: 93 additions & 0 deletions widgets/Register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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.md
* file that was distributed with this source code.
*/

namespace dektrium\user\widgets;

use dektrium\user\models\RegistrationForm;
use yii\base\Widget;

/**
* Login for widget.
*
* @author Dmitry Erofeev <[email protected]>
*/
class Register extends Widget
{

/**
* @var \dektrium\user\models\RegistrationForm
*/
public $model;

/**
* @var string
*/
public $id = 'registration-form';

/**
* @var string
*/
public $title = "";

/**
* @var bool
*/
public $validate = true;

/**
* @var bool
*/
public $enableGeneratingPassword = null;

/**
* @var bool
*/
public $displayLoginLink = true;

/**
* @var bool
*/
public $panel = true;

/**
* @var string
*/
public $panelType = 'default';

public function init()
{
parent::init();

if (!$this->model) {
$this->model = \Yii::createObject(RegistrationForm::className());
}
if ($this->enableGeneratingPassword === null) {
$this->enableGeneratingPassword = Yii::$app->getModule('user')->enableGeneratingPassword;
}
}

/**
* @inheritdoc
*/
public function run()
{
return $this->render('register', [
'model' => $this->model,
'id' => $this->id,
'title' => $this->title,
'validate' => $this->validate,
'enableGeneratingPassword' => $this->enableGeneratingPassword,
'displayLoginLink' => $this->displayLoginLink,
'panel' => $this->panel,
'panelType' => $this->panelType,
]);
}
}
62 changes: 62 additions & 0 deletions widgets/views/register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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.md
* file that was distributed with this source code.
*/

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;

/**
* @var yii\web\View $this
* @var dektrium\user\models\User $model
* @var dektrium\user\Module $module
*/

?>
<div class="row">
<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3">
<?php if ($panel): ?>
<div class="panel panel-<?= $panelType ?>">
<div class="panel-heading">
<h3 class="panel-title"><?= Html::encode($title) ?></h3>
</div>
<div class="panel-body">
<?php elseif ($title) : ?>
<h3><?= Html::encode($title) ?></h3>
<?php endif; ?>
<?php $form = ActiveForm::begin([
'id' => $id,
'action' => Url::to(['/user/register']),
'enableAjaxValidation' => true,
'enableClientValidation' => false,
]); ?>

<?= $form->field($model, 'email') ?>

<?= $form->field($model, 'username') ?>

<?php if ($enableGeneratingPassword == false): ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?php endif ?>

<?= Html::submitButton(Yii::t('user', 'Sign up'), ['class' => 'btn btn-success btn-block']) ?>

<?php ActiveForm::end(); ?>
<?php if ($panel): ?>
</div>
</div>
<?php endif; ?>
<?php if ($displayLoginLink) : ?>
<p class="text-center">
<?= Html::a(Yii::t('user', 'Already registered? Sign in!'), ['/user/security/login']) ?>
</p>
<?php endif; ?>
</div>
</div>