yii2-user, manual del modulo yii2 user del yii2 framework

Upload: linqueartes

Post on 02-Jun-2018

274 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    1/21

    Yii2-user DocumentationRelease 0.6

    Dektrium project

    December 02, 2014

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    2/21

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    3/21

    Contents

    1 Getting started 31.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2 Basics 52.1 Conguration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 List of available actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.3 User management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.4 Overriding models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.5 Overriding views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.6 Overriding controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.7 Social auth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    3 How-to 133.1 Adding captcha to forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    4 Feedback 17

    i

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    4/21

    ii

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    5/21

    Yii2-user Documentation, Release 0.6

    Yii2-user is a exible user registration and authentication module for Yii2.

    Contents 1

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    6/21

    Yii2-user Documentation, Release 0.6

    2 Contents

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    7/21

    CHAPTER 1

    Getting started

    1.1 Overview

    Most of web applications provide a way for users to register, log in or reset their forgotten passwords. Rather thanre-implementing this on each application, you can use Yii2-user which is a exible user management module forYii2 that handles common tasks such as registration, authentication and password retrieval. Current version includesfollowing features:

    Registration, with an optional conrmation per mail

    Social auth

    Password retrieval

    Account and prole management

    Console commands

    User management interface

    Note: Module is in initial development. Anything may change at any time.

    Codeception is used for testing and Travis CI is used for continuous integration.

    Yii2-user is an open-source project and released under the MIT License . You are very welcome to contribute to themodule.

    Yii2-user is a part of Dektrium Project which has been started with aim to provide useful extensions to your Yii2application under one vendor namespace. We hope that by providing extensions to common requirements, we willhelp developers concentrate on the interesting things that their applications do.

    If you have any questions or comments, please use Google Group or Gitter . You can also get news and updates fromthe Blog .

    1.2 Installation

    This document will guide you through the process of installing Yii2-user using composer . Installation is a quick andeasy two-step process. Installation is fully automatic: you dont even need to congure module manually!

    Note: Before we start make sure that you have properly congured db and mail application components.

    3

    http://codeception.com/http://travis-ci.org/dektrium/yii2-userhttps://github.com/dektrium/yii2-user/blob/master/LICENSE.mdhttps://github.com/dektrium/yii2-user/blob/master/LICENSE.mdhttps://groups.google.com/group/yii2-userhttps://gitter.im/dektrium/yii2-userhttps://gitter.im/dektrium/yii2-userhttps://yii2-user.blogspot.com/https://yii2-user.blogspot.com/https://yii2-user.blogspot.com/https://gitter.im/dektrium/yii2-userhttps://groups.google.com/group/yii2-userhttps://github.com/dektrium/yii2-user/blob/master/LICENSE.mdhttp://travis-ci.org/dektrium/yii2-userhttp://codeception.com/
  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    8/21

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    9/21

    CHAPTER 2

    Basics

    2.1 Conguration

    This guide covers the basic conguration settings for the Yii2-user.

    2.1.1 Available conguration options

    enableRegistration Whether registration is enabled. Defaults to True .

    enableGeneratingPassword Whether password eld is not shown on signup page and password is generatedautomatically and sent to user via email. Defaults to False .

    enableConrmation Whether users have to conrm their accounts by clicking conrmation link sent them byemail. In order to enable this option you have to congure mail application component. Defaults to True .

    enableUnconrmedLogin Whether users are allowed to sign in without activating their accounts. Default toFalse .

    enablePasswordRecovery Whether users are allowed to recover their passwords. Defaults to True . enableEmailReconrmation Whether users have to reconrm their email after changing it on settings page.

    Defaults to False .

    conrmWithin The time in seconds before a conrmation token becomes invalid. After expiring this time userhave to request new conrmation token on special page. Defaults to 86400 (24 hours).

    rememberFor The time in seconds you want the user will be remembered without asking for credentials. De-faults to 1209600 (2 weeks).

    recoverWithin The time in seconds before a recovery token becomes invalid. After expiring this time user haveto request new recovery message. Defaults to 21600 (6 hours).

    admins An array of users usernames who can manage users from admin panel. Defaults to empty array.

    cost Cost parameter used by the Blowsh hash algorithm. Defaults to 10. urlPrex The prex for user module URL. Defaults to user .

    urlRules The rules to be used in URL management.

    2.1.2 Conguration example

    The conguration is done in the applications config/web.php le.

    5

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    10/21

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    11/21

    Yii2-user Documentation, Release 0.6

    ...];

    2.3.1 Show users

    Route /user/admin/index shows a list of registered users. You will be able to see a lot of useful information such asregistration time and ip address, conrmation and block status, etc.

    2.3.2 Create user

    Route /user/admin/create shows create user form. To create a new user account you have to ll username andemail elds. If you do not want to create password for user leave password eld empty, password will be generatedautomatically. After create a welcome message will be sent to email that you have used to create user. It will containusername and password.

    2.3.3 Update user

    Route /user/admin/update shows update user form. To access this route you should specify id query parameter.

    2.3.4 Delete user

    Route /user/admin/delete deletes an user account. To access this route you should specify id query parameter and doa POST request. Be careful, you will not be able to restore deleted account.

    2.4 Overriding models

    When you are creating application with Yii2-user you can nd that you need to override models or forms. Yii2-useris very extensible and allows you to override any model. Yii2-user does not create models using new statement,instead it uses component named ModelManager which creates requested models. Here is default model managerconguration:

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    12/21

    Yii2-user Documentation, Release 0.6

    resendFormClass => dektrium\user\models\ResendForm ,// Model that is used on logging inloginFormClass => dektrium\user\models\LoginForm ,// Model that is used on password recovery passwordRecoveryFormClass => dektrium\user\models\RecoveryForm ,// Model that is used on requesting password recovery passwordRecoveryRequestFormClass => dektrium\user\models\RecoveryRequestForm

    ],],

    ],...

    ],...

    ];

    2.4.1 Example

    Assume you decided to override user class and change registration process. Lets create new user class under@app/models .

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    13/21

    Yii2-user Documentation, Release 0.6

    2.5 Overriding views

    When you start using Yii2-user you will probably nd that you need to override the default views provided by themodule. Although view names are not congurable, Yii2 provides a way to override views using themes. To getstarted congure your view application component as follows:

    This view file has been overriden!

    2.5. Overriding views 9

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    14/21

    Yii2-user Documentation, Release 0.6

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    15/21

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    16/21

    Yii2-user Documentation, Release 0.6

    12 Chapter 2. Basics

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    17/21

    CHAPTER 3

    How-to

    3.1 Adding captcha to forms

    Adding captcha to forms is pretty easy and can be done in three steps:

    1. In the model you have to add captcha eld and validation rules.

    2. In the view you have to show captcha eld

    3. In the controller you have to add captcha action

    In this howto I would like to show you how to add captcha eld in the registration form but you can add captcha toany form following this steps.

    3.1.1 1. Adding eld and validation rules to model

    First of all you need to override Registration form as described in special guide. After this done you have to add publicproperty named captcha and validation rules.

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    18/21

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    19/21

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    20/21

    Yii2-user Documentation, Release 0.6

    16 Chapter 3. How-to

  • 8/10/2019 yii2-user, Manual del modulo Yii2 User del Yii2 framework

    21/21

    CHAPTER 4

    Feedback

    You are very welcome to help us improve the quality of Yii2-user documentation. Please contribute if you see anymistakes or actual errors. To get started you can read the Contributing guide .

    If you can not x the bug or mistake by yourself, please open an issue .

    Any kind of discussion about Yii2-user documentation is very welcome in our Google group or Gitter .

    https://github.com/dektrium/yii2-user-docs/blob/master/CONTRIBUTING.mdhttps://github.com/dektrium/yii2-user-docs/blob/master/CONTRIBUTING.mdhttps://github.com/dektrium/yii2-user-docs/issues/newhttps://github.com/dektrium/yii2-user-docs/issues/newhttps://groups.google.com/group/yii2-userhttps://gitter.im/dektrium/yii2-userhttps://gitter.im/dektrium/yii2-userhttps://gitter.im/dektrium/yii2-userhttps://groups.google.com/group/yii2-userhttps://github.com/dektrium/yii2-user-docs/issues/newhttps://github.com/dektrium/yii2-user-docs/blob/master/CONTRIBUTING.md