Source code for odoo_xmlrpc_twisted.functions.create_resettoken
"""During password reset procedure set the "reset" fields in the "res.users" table."""importosimportconfigparserimportsecretsfromdatetimeimportdatetime,timedelta# call the function "get_settings_odoo" to get the parameters# for the logging of the model on the "odoo Webservice API"try:from.get_settings_odooimportget_settings_odooexceptImportError:fromget_settings_odooimportget_settings_odooresult=get_settings_odoo()db=result[0]uid=result[1]password=result[3]models=result[4]# ------- get the user parameter from the Settings File "user.ini" -------# Name and full path of the "ini" filefilename="parameter_user.ini"path_name=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Go up to repo rootconfig_path=os.path.join(path_name,'config')fullpath=os.path.join(config_path,filename)config=configparser.ConfigParser()config.read(fullpath)# Value for max duration time in days of the reset_tokenreset_token_duration=config.get('create_resettoken','reset_token_duration')
[docs]defcreate_resettoken(email):""" Function to set during password reset procedure the fields "x_reset_token", "x_reset_complete" and 'x_reset_date' in the database table 'res.users'. """result='False'ifemail!='':# find user in the table 'res.users' with the email = emailusers_id=models.execute_kw(db,uid,password,'res.users','search',[[['email','=',email],['x_activate_complete','=',True],# user must be activated]])# generare a random URL-safe text stringx_reset_token=secrets.token_urlsafe(None)x_reset_complete=False# set the max duration of the token duration_date=datetime.now()+timedelta(days=int(reset_token_duration))x_reset_date=duration_date.strftime("%Y-%m-%d %H:%M:%S")# update the user record with the "reset" valuesforu_idinusers_id:models.execute_kw(db,uid,password,'res.users','write',[[u_id],{'x_reset_token':x_reset_token,'x_reset_complete':x_reset_complete,'x_reset_date':x_reset_date}])result=x_reset_tokenelse:passreturn(result)