[MERGE] signup
bzr revid: al@openerp.com-20120725204606-x8rxuasn52z0ps97
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import res_config
|
||||
import signup
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
'name': 'Signup',
|
||||
'description': 'Allow users to sign up',
|
||||
'author': 'OpenERP SA',
|
||||
'version': '1.0',
|
||||
'category': 'Tools',
|
||||
'website': 'http://www.openerp.com',
|
||||
'installable': True,
|
||||
'depends': ['anonymous', 'base_setup'],
|
||||
'data': [
|
||||
'res_config.xml',
|
||||
'signup.xml',
|
||||
],
|
||||
'js': [
|
||||
'static/src/js/signup.js',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/signup.xml',
|
||||
],
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
from openerp.osv import osv, fields
|
||||
|
||||
class base_config_settings(osv.TransientModel):
|
||||
_inherit = 'base.config.settings'
|
||||
|
||||
_columns = {
|
||||
'signup_template_user_id': fields.many2one('res.users', 'Template user for signup')
|
||||
}
|
||||
|
||||
def get_default_signup(self, cr, uid, fields, context=None):
|
||||
icp = self.pool.get('ir.config_parameter')
|
||||
return {
|
||||
'signup_template_user_id': icp.get_param(cr, uid, 'signup.template_user_id', 0) or False
|
||||
}
|
||||
|
||||
def set_signup(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.template_user_id', config.signup_user_template_id.id)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_general_configuration" model="ir.ui.view">
|
||||
<field name="name">base.config.settings.signup</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_template_user_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
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_signup(osv.TransientModel):
|
||||
_name = 'signup.signup'
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64),
|
||||
'email': fields.char('Email', size=64),
|
||||
'password': fields.char('Password', size=64),
|
||||
'password_confirmation': 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)
|
||||
if values['password'] != values['password_confirmation']:
|
||||
raise osv.except_osv('Error', 'Passwords missmatch')
|
||||
|
||||
new_user = {
|
||||
'name': values['name'],
|
||||
'login': values['email'],
|
||||
'user_email': values['email'],
|
||||
'password': values['password'],
|
||||
'active': True,
|
||||
}
|
||||
|
||||
user_template_id = self.pool.get('ir.config_parameter').get_param(cr, uid, 'signup.user_template_id', 0)
|
||||
if user_template_id:
|
||||
self.pool.get('res.users').copy(cr, 1, user_template_id, new_user, context=context)
|
||||
else:
|
||||
self.pool.get('res.users').create(cr, 1, new_user, context=context)
|
||||
|
||||
# Dont store the password
|
||||
values = {'state': 'done'}
|
||||
return super(signup_signup, 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'}}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="signup_form_view" model="ir.ui.view">
|
||||
<field name="name">signup.signup.form</field>
|
||||
<field name="model">signup.signup</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="password" required='1' on_change="onchange_pw(password,password_confirmation)"/>
|
||||
<field name="password_confirmation" required='1' on_change="onchange_pw(password,password_confirmation)"/>
|
||||
<group colspan="4" states="missmatch">
|
||||
<div>Passwords missmatch</div>
|
||||
</group>
|
||||
<group colspan="2" col="1">
|
||||
<button string="Sign Up" name="signup" 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="signup_action" model="ir.actions.act_window">
|
||||
<field name="name">signup.signup</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">signup.signup</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -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.signup',
|
||||
views: [[false, 'form']],
|
||||
target: 'new',
|
||||
name: 'Sign Up'
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user