def _signup_create_user(self, values): """ create a new user from the template user """ IrConfigParam = self.env['ir.config_parameter'] template_user_id = literal_eval( IrConfigParam.get_param('auth_signup.template_user_id', 'False')) template_user = self.browse(template_user_id) assert template_user.exists(), 'Signup: invalid template user' # check that uninvited users may sign up if 'partner_id' not in values: if not literal_eval( IrConfigParam.get_param('auth_signup.allow_uninvited', 'False')): raise SignupError('Signup is not allowed for uninvited users') assert values.get('login'), "Signup: no login given for new user" assert values.get('partner_id') or values.get( 'name'), "Signup: no name or partner given for new user" # create a copy of the template user (attached to a specific partner_id if given) values['active'] = True try: with self.env.cr.savepoint(): return template_user.with_context( no_reset_password=True).copy(values) except Exception, e: # copy may failed if asked login is not available. raise SignupError(ustr(e))
def _signup_create_user(self, values): """ signup a new user using the template user """ # check that uninvited users may sign up if 'partner_id' not in values: if self._get_signup_invitation_scope() != 'b2c': raise SignupError(_('Signup is not allowed for uninvited users')) return self._create_user_from_template(values)
def _signup_create_user(self, values): """ signup a new user using the template user """ # check that uninvited users may sign up if 'partner_id' not in values: if self.env['ir.config_parameter'].sudo().get_param( 'auth_signup.invitation_scope', 'b2b') != 'b2c': raise SignupError( _('Signup is not allowed for uninvited users')) return self._create_user_from_template(values)
def process_company_signup_form(self, form, context=None): """Process the signup with creation of the new user and partner""" try: company = request.env["res.partner"].sudo().create( self.company_vals(form, context=context) ) except Exception as err: _logger.error(err) raise SignupError(_("Can not create company.")) context["company"] = company try: self._signup_with_values( context.get("token"), self.representative_vals(form, context=context) ) except Exception as err: _logger.error(err) company.unlink() raise SignupError(_("Can not create user."))
def _signup_create_user(self, values): """ Overwrite method to allow registering through OAuth2 without opening signup form. :param values: dict :return: method call """ if 'oauth_provider_id' not in values and 'partner_id' not in values: if self._get_signup_invitation_scope() != 'b2c': raise SignupError( _('Signup is not allowed for uninvited users')) return self._create_user_from_template(values)
def _create_user_from_template(self, values): template_user_id = literal_eval(self.env['ir.config_parameter'].sudo().get_param('base.template_portal_user_id', 'False')) template_user = self.browse(template_user_id) if not template_user.exists(): raise ValueError(_('Signup: invalid template user')) if not values.get('login'): raise ValueError(_('Signup: no login given for new user')) if not values.get('partner_id') and not values.get('name'): raise ValueError(_('Signup: no name or partner given for new user')) # create a copy of the template user (attached to a specific partner_id if given) values['active'] = True try: with self.env.cr.savepoint(): return template_user.with_context(no_reset_password=True).copy(values) except Exception as e: # copy may failed if asked login is not available. raise SignupError(ustr(e))