![]() |
|
doAuthPlugin - 0.9.5authentication system |
|
![]() |
24
users
Sign-in
to change your status |
A brand new user management and authentication system |
A new easy-to-use developer-friendly new authorization and authorization system. Can be easy configurable and customizable. Applies standard user logic: registration, activation, password reset, sign in, remember user.
| Name | Status | |
|---|---|---|
|
|
lead | ten.rku <<ta>> trevad |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 0.9.5beta | MIT license | 0.9.0beta | 15/05/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 0.9.5beta | MIT license | 0.9.0beta | 15/05/2010 |
Inspired by sfGuardPlugin an easy-to-use new authorization system. doAuth is ready to work out of the box with just a few configuration changes. It takes all the common user functionality - User authorization by login and password, registration, activation by email, password reset. If you don't need sfGuard permissions system but a simple user module that works, you should try doAuth. Great for a new symfony 1.4 projects.
Coming Soon: doAccess plugin that adds a permissions functionality on top of doAuth plugin.
Install the plugin
$ symfony plugin:install doAuthPlugin
Build your model and forms:
$ symfony doctrine:build-model
$ symfony doctrine:build-forms
Update your database:
$ symfony doctrine:insert-sql
make myUser class typically located in app/frontend/lib to extend doAuthSecurityUser:
class myUser extends doAuthSecurityUser { }
Optionally add the "Remember Me" filter to filters.yml above the security filter:
remember_me:
class: doAuthRememberMeFilter
Enable [baseAuth] module in setting.yml of your frontend or skip it and start the customization.
Change the default login and secure modules in settings.yml
login_module: baseAuth
login_action: signin
secure_module: baseAuth
secure_action: secure
You are ready to use. Try to access /register, /login, /logout routes. By default doAuth automaticaly signs user is on registration and sends email with username and password.
Access your user model from a class User. (well, is very common thing, but should be noted for sfGuardUser users)
creating a user (example)
$user = new User(); $user->setUsername('davert'); $user->setPassword('symfony'); $user->setEmail('doAuth843@davert.mail.ua'); $user->save();
accessing user session class (example in controller)
$user = $this->getUser(); // retrieve current user object $user->getAccount(); // get user Id $user->getUserId(); // check if user is admin or superadmin $user->isAdmin();
Don't use baseAuth module. Create your own User module:
$ symfony generate:module frontend user
let userActions extend the doAuthActions class.
class userActions extends doAuthActions
userActions now implements common actions: signin, signout, register, activate, reset password.
activate the standard routes in your frontendConfiguration class:
class frontendConfiguration extends sfApplicationConfiguration { public function configure() { $this->dispatcher->connect('routing.load_configuration', array('doAuthRouting', 'listenToRoutingLoadConfigurationEvent')); } }
or create your own routes. Use a sample file located in plugins/doAuth/config/routing.samlpe.yml
don't forget to set symfony default actions, like we did for baseAuth module
login_module: user
login_action: signin
secure_module: user
secure_action: secure
You can extend registration form in your own way. Here are 2 typical cases.
To add custom widgets or validators to RegisterForm. Create new RegisterUserForm class in your lib/forms folder.
class RegisterUserForm extends BaseRegisterUserForm { public function configure() { parent::configure(); // extend your code here } }
Sometimes you need more complex schema. For example, register user with different profile types, for example: Client and Developer. In this case you need to embed a Client and Developer forms into RegistrationForm depending on request parameters. This can't be made just by extending registration class. In this case you can use an events to extend current Register action with your logic.
Use ['user.pre_register'] event to access registration action, get request parameters, extend form, do everything you need.
Add this line to your frontendConfiguration class
$this->dispatcher->connect('user.pre_register', array('UserListener', 'registerWithRoles'));
create your listener class (that will act as a controller) and make it handle this event
class UserListener { public static function registerWithRoles(sfEvent $event) { // here comes a userActions controller $controller = $event->getSubject(); // waiting for 'developer' or 'client' value $role = $controller->getRequest()->getParameter('role'); $user = $controller->form->getObject(); // all what we need for this example: $formclass = $role.'Form'; $embed_form = new $formclass($user->get(ucfirst($role))); $controller->form->embedForm('role',$embed_form); } }
doAuthPlugin generates hashes for remember filter, activation code, password reset code and a new password for user on request.
Here are the principles that doAuth follows to create user codes:
If you are unhappy with provided methods, you can override them, following this instructions:
symfony cc thing)(Great thanks to Laurent Bachelier and Andrei Dziahel)
This options are stored in plugins/doAuth/config/app.sample.yml. If you want to change some settings - copy them to your app.yml file.
all:
doAuth:
# password encrypting algorithm
algorithm_callable: sha1
# function for delegating password check
check_password_callable: false
# coookie
remember_cookie_name: doRemember
# expiration time (in secs), currently 1 year
remember_cookie_expiration_age: 31536000
# use user activation
activation: false
# where to redirect after request for password reset
reset_password_url: '@homepage'
# signin redirect
signin_url: '@homepage'
#signout url
signout_url: '@homepage'
# register standard routes
routes_register: true
doAuth_register:
# forward registration to next module
# syntax: [module, action]
forward: ~
# or redirect to current path
redirect_path: '@homepage'
# auto sign in after registration
signin: true
doAuth_email:
# activate by email if activation is on
activation: true
# send registration notification
registration: true
# sender email
from: mailer@currenthost.com
# module where email partials are stored.
# default is module from controller
module: false
Here is a list of all events that are fired by doAuthPlugin:
Basically 2 last events are used to send emails.
To extend user actions you don't have to assign listeners to events. You can also override this dummy methods in your controller.
Added several tasks for user management
All the messages and templates are I18n-ready. Please check doAuthMailer class to add translations to email subjects and doAuthActions to translate flash messages
You can always fork this project on Github. http://github.com/DavertMik/doAuthPlugin Bugfixes, enhancements, bugreports are always welcome.
