[MERGE] trunk
bzr revid: fp@openerp.com-20121103152552-zlf761mkoxbgyxfh
This commit is contained in:
commit
fa90c9e771
|
@ -20,11 +20,10 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import werkzeug
|
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
from openerp.modules.registry import RegistryManager
|
from openerp.modules.registry import RegistryManager
|
||||||
from openerp.addons.web.controllers.main import login_and_redirect
|
|
||||||
|
from ..res_users import SignupError
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -41,22 +40,18 @@ class Controller(openerp.addons.web.http.Controller):
|
||||||
user_info = res_partner.signup_retrieve_info(cr, openerp.SUPERUSER_ID, token)
|
user_info = res_partner.signup_retrieve_info(cr, openerp.SUPERUSER_ID, token)
|
||||||
return user_info
|
return user_info
|
||||||
|
|
||||||
@openerp.addons.web.http.httprequest
|
@openerp.addons.web.http.jsonrequest
|
||||||
def signup(self, req, dbname, token, name, login, password, state=''):
|
def signup(self, req, dbname, token, name, login, password):
|
||||||
""" sign up a user (new or existing), and log it in """
|
""" sign up a user (new or existing)"""
|
||||||
url = '/'
|
|
||||||
registry = RegistryManager.get(dbname)
|
registry = RegistryManager.get(dbname)
|
||||||
with registry.cursor() as cr:
|
with registry.cursor() as cr:
|
||||||
|
res_users = registry.get('res.users')
|
||||||
|
values = {'name': name, 'login': login, 'password': password}
|
||||||
try:
|
try:
|
||||||
res_users = registry.get('res.users')
|
res_users.signup(cr, openerp.SUPERUSER_ID, values, token)
|
||||||
values = {'name': name, 'login': login, 'password': password}
|
except SignupError, e:
|
||||||
credentials = res_users.signup(cr, openerp.SUPERUSER_ID, values, token)
|
return {'error': openerp.tools.exception_to_unicode(e)}
|
||||||
cr.commit()
|
cr.commit()
|
||||||
return login_and_redirect(req, *credentials, redirect_url='/#%s'%state)
|
return {}
|
||||||
except Exception as e:
|
|
||||||
# signup error
|
|
||||||
_logger.exception('error when signup')
|
|
||||||
url = "/#action=login&error_message=%s" % werkzeug.urls.url_quote(e.message)
|
|
||||||
return werkzeug.utils.redirect(url)
|
|
||||||
|
|
||||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -29,6 +29,9 @@ from openerp import SUPERUSER_ID
|
||||||
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
from openerp.tools.safe_eval import safe_eval
|
from openerp.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
|
class SignupError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def random_token():
|
def random_token():
|
||||||
# the token has an entropy of about 120 bits (6 bits/char * 20 chars)
|
# the token has an entropy of about 120 bits (6 bits/char * 20 chars)
|
||||||
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||||
|
@ -101,12 +104,12 @@ class res_partner(osv.Model):
|
||||||
partner_ids = self.search(cr, uid, [('signup_token', '=', token)], context=context)
|
partner_ids = self.search(cr, uid, [('signup_token', '=', token)], context=context)
|
||||||
if not partner_ids:
|
if not partner_ids:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise Exception("Signup token '%s' is not valid" % token)
|
raise SignupError("Signup token '%s' is not valid" % token)
|
||||||
return False
|
return False
|
||||||
partner = self.browse(cr, uid, partner_ids[0], context)
|
partner = self.browse(cr, uid, partner_ids[0], context)
|
||||||
if check_validity and not partner.signup_valid:
|
if check_validity and not partner.signup_valid:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise Exception("Signup token '%s' is no longer valid" % token)
|
raise SignupError("Signup token '%s' is no longer valid" % token)
|
||||||
return False
|
return False
|
||||||
return partner
|
return partner
|
||||||
|
|
||||||
|
@ -194,7 +197,7 @@ class res_users(osv.Model):
|
||||||
# check that uninvited users may sign up
|
# check that uninvited users may sign up
|
||||||
if 'partner_id' not in values:
|
if 'partner_id' not in values:
|
||||||
if not safe_eval(ir_config_parameter.get_param(cr, uid, 'auth_signup.allow_uninvited', 'False')):
|
if not safe_eval(ir_config_parameter.get_param(cr, uid, 'auth_signup.allow_uninvited', 'False')):
|
||||||
raise Exception('Signup is not allowed for uninvited users')
|
raise SignupError('Signup is not allowed for uninvited users')
|
||||||
|
|
||||||
# create a copy of the template user (attached to a specific partner_id if given)
|
# create a copy of the template user (attached to a specific partner_id if given)
|
||||||
values['active'] = True
|
values['active'] = True
|
||||||
|
|
|
@ -8,12 +8,20 @@ openerp.auth_signup = function(instance) {
|
||||||
var d = this._super();
|
var d = this._super();
|
||||||
|
|
||||||
// to switch between the signup and regular login form
|
// to switch between the signup and regular login form
|
||||||
this.$('a.oe_signup_signup').click(function() {
|
this.$('a.oe_signup_signup').click(function(ev) {
|
||||||
|
if (ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
self.$el.addClass("oe_login_signup");
|
self.$el.addClass("oe_login_signup");
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
this.$('a.oe_signup_back').click(function() {
|
this.$('a.oe_signup_back').click(function(ev) {
|
||||||
|
if (ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
self.$el.removeClass("oe_login_signup");
|
self.$el.removeClass("oe_login_signup");
|
||||||
delete self.params.token;
|
delete self.params.token;
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// if there is an error message in params, show it then forget it
|
// if there is an error message in params, show it then forget it
|
||||||
|
@ -90,10 +98,19 @@ openerp.auth_signup = function(instance) {
|
||||||
name: name,
|
name: name,
|
||||||
login: login,
|
login: login,
|
||||||
password: password,
|
password: password,
|
||||||
state: $.param(this.params)
|
//state: $.param(this.params)
|
||||||
};
|
};
|
||||||
var url = "/auth_signup/signup?" + $.param(params);
|
|
||||||
window.location = url;
|
var self = this,
|
||||||
|
super_ = this._super;
|
||||||
|
this.rpc('/auth_signup/signup', params)
|
||||||
|
.done(function(result) {
|
||||||
|
if (result.error) {
|
||||||
|
self.show_error(result.error);
|
||||||
|
} else {
|
||||||
|
super_.apply(self, [ev]);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// regular login
|
// regular login
|
||||||
this._super(ev);
|
this._super(ev);
|
||||||
|
|
Loading…
Reference in New Issue