dont create old userid

This commit is contained in:
j 2016-01-16 18:01:04 +05:30
parent 2c9109a7a5
commit f1ba3fbd34
3 changed files with 15 additions and 15 deletions

View File

@ -509,7 +509,8 @@ def update_online():
'id': settings.USER_ID,
'online': state.online
})
if not settings.server.get('migrated_id', False):
if settings.OLD_USER_ID and not settings.server.get('migrated_id', False):
r = directory.put(settings.sk, {
'id': settings.USER_ID,
})

View File

@ -58,15 +58,13 @@ if os.path.exists(key_path):
with open(key_path, 'rb') as fd:
sk = ed25519.SigningKey(fd.read())
vk = sk.get_verifying_key()
OLD_USER_ID = vk.to_ascii(encoding='base64').decode()
else:
sk, vk = ed25519.create_keypair()
with open(key_path, 'wb') as fd:
os.chmod(key_path, 0o600)
fd.write(sk.to_bytes())
os.chmod(key_path, 0o400)
sk = None
vk = None
OLD_USER_ID = None
USER_ID = get_user_id(ssl_key_path, ssl_cert_path)
OLD_USER_ID = vk.to_ascii(encoding='base64').decode()
OML_UPDATE_KEY='K55EZpPYbP3X+3mA66cztlw1sSaUMqGwfTDKQyP2qOU'

View File

@ -378,14 +378,15 @@ def upgrade_db(old, new=None):
old_key = os.path.join(settings.config_path, 'node.ssl.key')
if os.path.exists(old_key):
os.unlink(old_key)
statements = [
"UPDATE user SET id = '{nid}' WHERE id = '{oid}'",
"UPDATE list SET user_id = '{nid}' WHERE user_id = '{oid}'",
"UPDATE useritem SET user_id = '{nid}' WHERE user_id = '{oid}'",
"UPDATE changelog SET user_id = '{nid}' WHERE user_id = '{oid}'",
]
for sql in statements:
run_sql(sql.format(oid=settings.OLD_USER_ID, nid=settings.USER_ID))
if settings.OLD_USER_ID:
statements = [
"UPDATE user SET id = '{nid}' WHERE id = '{oid}'",
"UPDATE list SET user_id = '{nid}' WHERE user_id = '{oid}'",
"UPDATE useritem SET user_id = '{nid}' WHERE user_id = '{oid}'",
"UPDATE changelog SET user_id = '{nid}' WHERE user_id = '{oid}'",
]
for sql in statements:
run_sql(sql.format(oid=settings.OLD_USER_ID, nid=settings.USER_ID))
if old <= '20151201-384-03c2439':
with db.session():
import item.models