[ADD] signup addon

bzr revid: chs@openerp.com-20120625122630-ce6hywabt512xbh6
This commit is contained in:
Christophe Simonis 2012-06-25 14:26:30 +02:00
parent 0a22debf5f
commit ff4342dc4f
9 changed files with 203 additions and 0 deletions

View File

@ -4,10 +4,12 @@
<templates id="template" xml:space="preserve">
<t t-name="UserMenu.anonymous">
<div>
<a href="#" class="oe_user_menu oe_topbar_item oe_topbar_anonymous_login">
<img class="oe_topbar_avatar" t-att-src="_s + '/web/static/src/img/icons/gtk-dialog-authentication.png'"/>
Login
</a>
</div>
</t>
</templates>

View File

@ -0,0 +1,2 @@
import signup_wizard
import res_config

View File

@ -0,0 +1,23 @@
{
'name': 'Signup',
'description': 'Allow users to register',
'author': 'OpenERP SA',
'version': '1.0',
'category': 'Tools',
'website': 'http://www.openerp.com',
'installable': True,
'depends': ['anonymous', 'base_setup'],
'data': [
'signup_wizard.xml',
'res_config.xml',
],
'js': [
'static/src/js/signup.js',
],
#'css': [
# 'static/src/css/reset_password.css',
#],
'qweb': [
'static/src/xml/signup.xml',
],
}

View File

@ -0,0 +1,19 @@
from openerp.osv import osv, fields
class ResConfig(osv.TransientModel):
_inherit = 'base.config.settings'
_columns = {
'signup_user_template_id': fields.many2one('res.users', 'Template user for account creation')
}
def get_default_user_tpl(self, cr, uid, fields, context=None):
icp = self.pool.get('ir.config_parameter')
return {
'signup_user_template_id': icp.get_param(cr, uid, 'signup.user_template_id', 0) or False
}
def set_user_template(self, cr, uid, ids, context=None):
config = self.browse(cr, uid, ids[0], context=context)
icp = self.pool.get('ir.config_parameter')
icp.set_param(cr, uid, 'signup.user_template_id', config.signup_user_template_id.id)

View File

@ -0,0 +1,16 @@
<openerp>
<data>
<record id="view_gen_conf_inherit" model="ir.ui.view">
<field name="name">Inherit General Settings</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="module_portal" position="after">
<field name="signup_user_template_id"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,65 @@
from functools import partial
from openerp.osv import osv, fields
class res_users(osv.Model):
_inherit = 'res.users'
_sql_constraints = [
('email_uniq', 'UNIQUE (user_email)', 'You can not have two users with the same email!')
]
class signup_wizard(osv.TransientModel):
_name = 'signup.wizard'
_columns = {
'name': fields.char('Name', size=64),
'email': fields.char('Email', size=64),
'pw': fields.char('Password', size=64),
'cpw': fields.char('Confirm Password', size=64),
'state': fields.selection([(x, x) for x in 'draft done missmatch'.split()], required=True),
}
_defaults = {
'state': 'draft',
}
def create(self, cr, uid, values, context=None):
# NOTE here, invalid values raises exceptions to avoid storing
# sensitive data into the database (which then are available to anyone)
name = values.get('name')
email = values.get('email')
pw = values.get('pw')
cpw = values.get('cpw')
if pw != cpw:
raise osv.except_osv('Error', 'Passwords missmatch')
Users = self.pool.get('res.users')
user_template_id = self.pool.get('ir.config_parameter').get_param(cr, uid, 'signup.user_template_id', 0)
if user_template_id:
func = partial(Users.copy, cr, 1, user_template_id, context=context)
else:
func = partial(Users.create, cr, 1, context=context)
func({
'name': name,
'login': email,
'user_email': email,
'password': pw,
'active': True,
})
values = {'state': 'done'}
return super(signup_wizard, self).create(cr, uid, values, context)
def signup(self, cr, uid, ids, context=None):
return {
'type': 'ir.actions.client',
'tag': 'login',
}
def onchange_pw(self, cr, uid, ids, pw, cpw, context=None):
if pw != cpw:
return {'value': {'state': 'missmatch'}}
return {'value': {'state': 'draft'}}

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="signup_wizard_form_view" model="ir.ui.view">
<field name="name">signup.wizard.form</field>
<field name="model">signup.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Signup" version="7.0">
<field name="state" invisible="1"/>
<group colspan="4" states="draft,missmatch">
<field name="name" required="1"/>
<field name="email" required="1"/>
<field name="pw" required='1' on_change="onchange_pw(pw,cpw)"/>
<field name="cpw" required='1' on_change="onchange_pw(pw,cpw)"/>
<group colspan="4" states="missmatch">
<div>Passwords missmatch</div>
</group>
<group colspan="2" col="1">
<button string="Sign Up" name="signup" icon="gtk-connect" attrs="{'readonly': [('state', '=', 'missmatch')]}" type="object"/>
</group>
</group>
<group colspan="4" states="done" col="1">
<div>You can now login.</div>
<button special="cancel" string="Close"/>
</group>
</form>
</field>
</record>
<record id="action_reset" model="ir.actions.act_window">
<field name="name">Reset Password</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">signup.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,21 @@
openerp.signup = function(instance) {
instance.web.UserMenu.include({
start: function() {
var self = this;
this._super.apply(this, arguments);
this.$element.find('a.oe_topbar_signup').click(function() {
var p = self.getParent();
var am = p.action_manager;
am.do_action({
type:'ir.actions.act_window',
res_model: 'signup.wizard',
views: [[false, 'form']],
target: 'new',
name: 'Sign Up'
});
});
}
});
};

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-extend="UserMenu.anonymous">
<t t-jquery="a" t-operation="after">
<a href="#" class="oe_user_menu oe_topbar_item oe_topbar_signup">
<img class="oe_topbar_avatar" t-att-src="_s + '/web/static/src/img/user_menu_avatar.png'"/>
Sign Up
</a>
</t>
</t>
</templates>