Giter Club home page Giter Club logo

Comments (25)

webvimark avatar webvimark commented on July 30, 2024 2

For registration

  1. In config file you can redefine "registrationFormClass" property, so you need create your own registration from class (just copy-paste existsing and modify it for your needs)

  2. Use theming for registration view file

  3. ....

  4. Profit ? :)

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Basically you create some "profile" table witch has "user_id" as foreign key to "user" table. And the you just run gii generators.

P.S. I know that FAQ is needed, but right now I have not so much spare time :)

from user-management.

webvimark avatar webvimark commented on July 30, 2024

OK, the basic example:

user profile table with collumns:

id
user_id
age
pet_name

  1. Generate model UserProfile via gii somewhere in your app.
  2. Generate crud for this model via gii
  3. Now you can add data to this table. Lets say it will looks like this:

id => 1
user_id => 37
age => 8
pet_name => "Doggy"

Thats it, you now have some additional profile information for user with id "37"

from user-management.

glanisko avatar glanisko commented on July 30, 2024

ok, that's the place i know ;)
how merge this information to registration form, save them with user save on user-management/user/create ? ;)

from user-management.

webvimark avatar webvimark commented on July 30, 2024

If it's not helping, I'll create example tomorrow

from user-management.

glanisko avatar glanisko commented on July 30, 2024

ok so:

  • i have created table: user_profile
class m150130_190352_create_user_profile extends Migration
{
    public function up()
    {
        $this->createTable('user_profile', [
            'user_id' => 'pk',
            'name' => Schema::TYPE_STRING . ' NOT NULL',
            'number' => Schema::TYPE_STRING . ' NOT NULL',
        ]);
        $this->addForeignKey('fk_user_id', 'user_profile', 'user_id', 'user', 'id');   
    }
}
  • generated model and crud controller
  • added to conmponents config section
'UserManagmentModule' => [
    'class' => 'webvimark\modules\UserManagement\UserManagementModule',
    'registrationFormClass' => 'app\models\UserProfile',
],
  • copied view file to my repository
use webvimark\modules\UserManagement\models\User;
use webvimark\modules\UserManagement\UserManagementModule;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use webvimark\extensions\BootstrapSwitch\BootstrapSwitch;
/**
 * @var yii\web\View $this
 * @var webvimark\modules\UserManagement\models\User $model
 * @var yii\bootstrap\ActiveForm $form
 */
?>
<div class="user-form">
    <?php $form = ActiveForm::begin([
        'id'=>'user',
        'layout'=>'horizontal',
        'validateOnBlur' => false,
    ]); ?>
    <?= $form->field($model->loadDefaultValues(), 'status')
        ->dropDownList(User::getStatusList()) ?>
    <?= $form->field($model, 'username')->textInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>
    <?php if ( $model->isNewRecord ): ?>
        <?= $form->field($model, 'password')->passwordInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>
        <?= $form->field($model, 'repeat_password')->passwordInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>
    <?php endif; ?>
    <?php if ( User::hasPermission('bindUserToIp') ): ?>
        <?= $form->field($model, 'bind_to_ip')
            ->textInput(['maxlength' => 255])
            ->hint(UserManagementModule::t('back','For example: 123.34.56.78, 168.111.192.12')) ?>
    <?php endif; ?>
    <?php if ( User::hasPermission('editUserEmail') ): ?>
        <?= $form->field($model, 'email')->textInput(['maxlength' => 255]) ?>
        <?= $form->field($model, 'email_confirmed')->checkbox() ?>
    <?php endif; ?>
    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <?php if ( $model->isNewRecord ): ?>
                <?= Html::submitButton(
                    '<span class="glyphicon glyphicon-plus-sign"></span> ' . UserManagementModule::t('back', 'Create'),
                    ['class' => 'btn btn-success']
                ) ?>
            <?php else: ?>
                <?= Html::submitButton(
                    '<span class="glyphicon glyphicon-ok"></span> ' . UserManagementModule::t('back', 'Save'),
                    ['class' => 'btn btn-primary']
                ) ?>
            <?php endif; ?>
        </div>
    </div>
    <?php ActiveForm::end(); ?>
</div>
  • added two fileds to copied file in step 4
    <?= $form->field($model, 'name')->passwordInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>
    <?= $form->field($model, 'number')->passwordInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>
  • get Unknown Property Exception ;)
Getting unknown property: webvimark\modules\UserManagement\models\User::name

and now what to do? :D

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Awww, man it's easier for me to make example.
You do it wrong :0

from user-management.

glanisko avatar glanisko commented on July 30, 2024

ok, so i will wait for your example :)

from user-management.

glanisko avatar glanisko commented on July 30, 2024

ok, when the example will be done?;)

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Have no time right now :( Probably will do it till Wednesday.

Here is the start - https://github.com/webvimark/user-management/wiki/Profile-and-custom-registration

from user-management.

glanisko avatar glanisko commented on July 30, 2024

Can you manage to do it till Sunday? :) it's blocking issue in my project :(

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Ok, will do it tomorrow

from user-management.

webvimark avatar webvimark commented on July 30, 2024

You may see example here now - https://github.com/webvimark/user-management/wiki/Profile-and-custom-registration

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Sorry, I just noticed that I didn't upload last update to github (so example will not work) :(
Will do it when I'll be at home

from user-management.

glanisko avatar glanisko commented on July 30, 2024

OK :) i will wait :)

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Aaaand now it should work :)

from user-management.

glanisko avatar glanisko commented on July 30, 2024

Ok, now it works :) thanks :)

from user-management.

ik-j avatar ik-j commented on July 30, 2024

I want the User table to have a custom field i.e. school_id. I added to table, then to views and to webvimark\modules\UserManagement\models\User model class, but its value is not saved/updated from your extension. I know I can use profile but I would rather prefer it via User table. Please guide me.

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Try add this field to rules

from user-management.

ik-j avatar ik-j commented on July 30, 2024

Actually i hv 3 custome fields which I have added to rules n User class i.e. [['name', 'phone','school_id'],'required'],

from user-management.

webvimark avatar webvimark commented on July 30, 2024

Try

        echo "<pre>";
        var_dump($model->errors);
        echo "</pre>";

And see what errors you have

from user-management.

glanisko avatar glanisko commented on July 30, 2024

I have done it with something like this:
config/web.php

'components' => [
        'user' => [
            'class' => 'webvimark\modules\UserManagement\components\UserConfig',
            'identityClass' => 'app\models\User',
        ],
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@vendor/webvimark/module-user-management/views' => '@app/views/webvimark/module-user-management/',
                    '@vendor/webvimark/module-user-management/views/layouts/' => '@app/views/layouts/',
                ],
            ],
        ],
]

'modules'=>[
        'user-management' => [
            'class' => 'webvimark\modules\UserManagement\UserManagementModule',
            'controllerMap' => [
                'user' => 'app\controllers\UserController',
            ],
        ],
    ],

and app\models\User.php

<?php

namespace app\models;
use webvimark\modules\UserManagement\models\User as BaseUser;
use yii;
/**
* @property string $name
* @property string $surname
* @property string $telephone
*/
class User extends BaseUser
{

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return ArrayHelper::merge(parent::rules(), [
            [['name', 'surname'], 'required'],
            [['name', 'surname', 'telephone'], 'string', 'max' => 255],
                   ]);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return ArrayHelper::merge(parent::attributeLabels(), [
            'name' => Yii::t('app', 'Name'),
            'surname' => Yii::t('app', 'Surname'),
            'telephone'=> Yii::t('app', 'Telephone number'),
        ]);
    }    
}

and override user controller in this way:

<?php

namespace app\controllers;
use webvimark\modules\UserManagement\controllers\UserController as BaseUserController;
use Yii;
use yii\helpers\Url;

class UserController extends BaseUserController
{

    public $modelClass = 'app\models\User';
    public $modelSearchClass = 'app\models\UserSearch';

}

and it works without touching vendor module ;)

from user-management.

ik-j avatar ik-j commented on July 30, 2024

@glanisko, thanks buddy....your solution worked but only while updating a user. During creation [name,phone,school_id] doesnt get inserted into table :(

from user-management.

ik-j avatar ik-j commented on July 30, 2024

I was able to solve by making the following 2 changes in Webvimark User class:

  1. Added properties at the start of the class:
  1. Added to rules():
    [['name','phone','school_id'], 'required'],

from user-management.

ik-j avatar ik-j commented on July 30, 2024

I have a Yii2 app where I want the registered and logged in user to edit his user table custom fields like name, company_name etc.

I created a view "my-account.php" inside vendor->webvimark->module-user-management->views/auth/ folder. I added an action fuction (actionMyAccount() ) in webvimark->module-user-management->controller->authController class.

I am able to pull and show user custom columns data on view but am unable to update that data. Help needed.

from user-management.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.