[IMP] auth_signup: use a client action instead of a wizard
bzr revid: chs@openerp.com-20120807163619-bodnv40u7bz1t9ok
This commit is contained in:
parent
ccbc0df1dd
commit
953e1f0852
|
@ -8,7 +8,6 @@
|
|||
'installable': True,
|
||||
'depends': ['auth_anonymous', 'base_setup'],
|
||||
'data': [
|
||||
'auth_signup.xml',
|
||||
'res_config.xml',
|
||||
],
|
||||
'js': [
|
||||
|
|
|
@ -9,22 +9,17 @@ class res_users(osv.Model):
|
|||
|
||||
class signup_signup(osv.TransientModel):
|
||||
_name = 'auth.signup'
|
||||
|
||||
# TODO add captcha
|
||||
_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'],
|
||||
|
@ -40,17 +35,5 @@ class signup_signup(osv.TransientModel):
|
|||
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'}}
|
||||
# Dont store anything
|
||||
return 0
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="signup_form_view" model="ir.ui.view">
|
||||
<field name="name">auth.signup.form</field>
|
||||
<field name="model">auth.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">auth.signup</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">auth.signup</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -4,7 +4,7 @@ openerp.auth_signup = function(instance) {
|
|||
instance.web.Login.include({
|
||||
start: function() {
|
||||
var self = this;
|
||||
|
||||
|
||||
this.$('a.oe_signup').click(function() {
|
||||
var db = self.$("form [name=db]").val();
|
||||
if (!db) {
|
||||
|
@ -32,17 +32,74 @@ openerp.auth_signup = function(instance) {
|
|||
|
||||
_signup: function() {
|
||||
this.do_action({
|
||||
type:'ir.actions.act_window',
|
||||
res_model: 'auth.signup',
|
||||
views: [[false, 'form']],
|
||||
type: 'ir.actions.client',
|
||||
tag: 'auth_signup.signup',
|
||||
target: 'new',
|
||||
name: 'Sign Up'
|
||||
}, function() {
|
||||
// mmh, no way to have access to dialog befor close...
|
||||
// TODO autolog user
|
||||
console.log('onclose', this, arguments);
|
||||
name: 'Sign up'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
instance.auth_signup = instance.auth_signup || {};
|
||||
instance.auth_signup.Signup = instance.web.Widget.extend({
|
||||
template: 'auth_signup.signup',
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.dataset = new instance.web.DataSet(this, 'auth.signup');
|
||||
},
|
||||
start: function() {
|
||||
var self = this;
|
||||
this.$('input[type=password]').change(function() {
|
||||
var v = $(this).val();
|
||||
var e = !_.isEmpty(v);
|
||||
if (e) {
|
||||
e =_.all(self.$('input[type=password]'), function(i) {
|
||||
return $(i).val() === v;
|
||||
});
|
||||
}
|
||||
var $b = self.$('button');
|
||||
if (e) {
|
||||
$b.removeAttr('disabled');
|
||||
} else {
|
||||
$b.attr('disabled', 'disabled');
|
||||
}
|
||||
});
|
||||
|
||||
this.$('form').submit(function(ev) {
|
||||
if(ev) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
var name = self.$('input[name=name]').val();
|
||||
var email = self.$('input[name=email]').val();
|
||||
var password = self.$('input[name=password]').val();
|
||||
|
||||
self.dataset.create({
|
||||
name: name,
|
||||
email: email,
|
||||
password: password
|
||||
}, function() {
|
||||
self.do_action({
|
||||
type: 'ir.actions.client',
|
||||
tag: 'login',
|
||||
params: {
|
||||
db: instance.connection.db,
|
||||
login: email,
|
||||
password: password,
|
||||
login_successful: function() {
|
||||
self.do_action('home');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return false;
|
||||
|
||||
});
|
||||
return $.when(this._super());
|
||||
}
|
||||
|
||||
});
|
||||
instance.web.client_actions.add("auth_signup.signup", "instance.auth_signup.Signup");
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -11,6 +11,18 @@
|
|||
</t>
|
||||
</t>
|
||||
|
||||
<t t-name="auth_signup.signup">
|
||||
<div>
|
||||
<form>
|
||||
Name = <input type="text" name="name"/>
|
||||
Email = <input type="email" name="email"/>
|
||||
Password = <input type="password" name="password"/>
|
||||
Confirmation = <input type="password" name="password_confirmation"/>
|
||||
<button type="submit" disabled="disabled">Signup</button>
|
||||
</form>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
|
||||
|
||||
</templates>
|
||||
|
|
Loading…
Reference in New Issue