Explorar el Código

Remove serial key feature

Eren Yilmaz hace 5 años
padre
commit
72896645bb
Se han modificado 6 ficheros con 5 adiciones y 113 borrados
  1. 2 24
      client_controller.py
  2. 0 5
      create_new_key.py
  3. 0 8
      db_setup/tables.py
  4. 1 4
      doc/documentation.py
  5. 1 56
      model.py
  6. 1 16
      server_controller.py

+ 2 - 24
client_controller.py

@@ -5,7 +5,6 @@ from inspect import signature
 
 import connection
 from connection import client_request
-from debug import debug
 from game import DEFAULT_ORDER_EXPIRY, CURRENCY_NAME, MIN_INTEREST_INTERVAL, CURRENCY_SYMBOL, OWNABLE_NAME_PATTERN
 from routes import client_commands
 from run_client import fake_loading_bar
@@ -41,7 +40,7 @@ def login(username=None, password=None):
             print('Login failed.')
 
 
-def register(username=None, game_key='', password=None, retype_pw=None):
+def register(username=None, password=None, retype_pw=None):
     if connection.session_id is not None:
         connection.session_id = None
         fake_loading_bar('Signing out', duration=0.7)
@@ -68,15 +67,8 @@ def register(username=None, game_key='', password=None, retype_pw=None):
             print('Passwords do not match.')
             return
 
-    if not debug:
-        if game_key == '':
-            print('Entering a game key will provide you with some starting money and other useful stuff.')
-            game_key = input('Game key (leave empty if you don\'t have one): ')
-
     fake_loading_bar('Validating Registration', duration=5.2)
-    if game_key != '':
-        fake_loading_bar('Validating Game Key', duration=0.4)
-    response = client_request('register', {"username": username, "password": password, "game_key": game_key})
+    response = client_request('register', {"username": username, "password": password})
 
     if 'error' in response:
         print('Registration failed with message:', response['error'])
@@ -205,20 +197,6 @@ def leaderboard():
             print('Leaderboard access failed.')
 
 
-def activate_key(key=''):
-    if key == '':
-        print('Entering a game key may get you some money or other useful stuff.')
-        key = input('Key: ')
-
-    if key == '':
-        print('Invalid key.')
-
-    fake_loading_bar('Validating Key', duration=0.4)
-    response = client_request('activate_key', {"session_id": connection.session_id, 'key': key})
-    if 'error' in response:
-        print('Key activation failed with message:', response['error'])
-
-
 def _order(is_buy_order, obj_name=None, amount=None, limit=None, stop_loss=None, expiry=None, ioc=None):
     if obj_name is None:  # TODO list some available objects
         obj_name = input('Name of object to sell: ')

+ 0 - 5
create_new_key.py

@@ -1,5 +0,0 @@
-from model import generate_keys, cleanup
-
-if __name__ == '__main__':
-    generate_keys(count=1)
-    cleanup()

+ 0 - 8
db_setup/tables.py

@@ -80,14 +80,6 @@ def tables(cursor):
                 -- there is a not null constraint for new values that is watched by triggers
                 ALTER TABLE transactions ADD COLUMN seller_id INTEGER REFERENCES users(rowid)
                 ''')
-    cursor.execute('''
-                CREATE TABLE IF NOT EXISTS keys(
-                    rowid INTEGER PRIMARY KEY,
-                    key STRING UNIQUE NOT NULL,
-                    used_by_user_id INTEGER,
-                    FOREIGN KEY (used_by_user_id) REFERENCES users(rowid)
-                )
-                ''')
     cursor.execute('''
                 CREATE TABLE IF NOT EXISTS news(
                     rowid INTEGER PRIMARY KEY,

+ 1 - 4
doc/documentation.py

@@ -5,9 +5,6 @@
 # {"email": "user123@example.org", "username": "user123", "password": "FILTERED", "preferred_language": "german"}
 # while a valid request to /events would be the empty object {}
 
-activate_key_required_attributes = ['key', 'session_id']
-activate_key_possible_attributes = ['key', 'session_id']
-
 before_request_required_attributes = []
 before_request_possible_attributes = []
 
@@ -63,7 +60,7 @@ orders_on_required_attributes = ['ownable', 'session_id']
 orders_on_possible_attributes = ['ownable', 'session_id']
 
 register_required_attributes = ['password', 'username']
-register_possible_attributes = ['game_key', 'password', 'username']
+register_possible_attributes = ['password', 'username']
 
 repay_loan_required_attributes = ['amount', 'loan_id', 'session_id']
 repay_loan_possible_attributes = ['amount', 'loan_id', 'session_id']

+ 1 - 56
model.py

@@ -119,16 +119,6 @@ def setup():
     db_setup.setup(current_cursor)
 
 
-def used_key_count():
-    execute('''
-        SELECT COUNT(*) -- rarely executed, no index needed, O(n) query
-        FROM keys
-        WHERE used_by_user_id IS NOT NULL
-        ''')
-
-    return current_cursor.fetchone()[0]
-
-
 def login(username, password):
     execute('''
                 SELECT rowid, password, salt
@@ -146,7 +136,7 @@ def login(username, password):
         return None
 
 
-def register(username, password, game_key):
+def register(username, password):
     salt = str(uuid.uuid4())
     hashed_password = sha256_crypt.using(rounds=100000).encrypt(str(password) + salt)
     connect()
@@ -159,9 +149,6 @@ def register(username, password, game_key):
                 (username, password, salt)
                 VALUES (? , ?, ?)
                 ''', (username, hashed_password, salt))
-    if game_key != '':
-        if valid_key(game_key):
-            activate_key(game_key, get_user_id_by_name(username))
     own(get_user_id_by_name(username), CURRENCY_NAME)
     return True
 
@@ -201,20 +188,6 @@ def send_ownable(from_user_id, to_user_id, ownable_id, amount):
     return True
 
 
-def valid_key(key):
-    execute('''
-                SELECT key
-                FROM keys
-                WHERE used_by_user_id IS NULL
-                AND key = ?
-                ''', (key,))
-
-    if current_cursor.fetchone():
-        return True
-    else:
-        return False
-
-
 def new_session(user_id):
     session_id = str(uuid.uuid4())
 
@@ -227,14 +200,6 @@ def new_session(user_id):
     return session_id
 
 
-def save_key(key):
-    execute('''
-                INSERT INTO keys 
-                (key)
-                VALUES (?)
-                ''', (key,))
-
-
 def drop_old_sessions():
     execute(''' -- no need to optimize this very well
                 DELETE FROM sessions
@@ -319,17 +284,6 @@ def get_user_ownership(user_id):
     return current_cursor.fetchall()
 
 
-def activate_key(key, user_id):
-    execute('''
-                UPDATE keys
-                SET used_by_user_id = ?
-                WHERE used_by_user_id IS NULL
-                AND key = ?
-                ''', (user_id, key,))
-
-    send_ownable(bank_id(), user_id, currency_id(), 1000)
-
-
 def bank_id():
     execute('''
         SELECT users.rowid
@@ -925,15 +879,6 @@ def drop_expired_orders():
     return data
 
 
-def generate_keys(count=1):
-    # source https://stackoverflow.com/questions/17049308/python-3-3-serial-key-generator-list-problems
-
-    for i in range(count):
-        key = '-'.join(random_chars(5) for _ in range(5))
-        save_key(key)
-        print(key)
-
-
 def user_has_order_with_id(session_id, order_id):
     execute('''
                 SELECT orders.rowid

+ 1 - 16
server_controller.py

@@ -40,27 +40,12 @@ def register(json_request):
         return BadRequest('Username can not be empty.')
     if model.user_exists(username):
         return BadRequest('User already exists.')
-    game_key = ''
-    if 'game_key' in json_request:
-        game_key = json_request['game_key'].strip().upper()
-        if game_key != '' and not model.valid_key(game_key):
-            return BadRequest('Game key is not valid.')
-    if model.register(username, json_request['password'], game_key):
+    if model.register(username, json_request['password']):
         return {'message': "successfully registered user"}
     else:
         return BadRequest('Registration not successful')
 
 
-def activate_key(json_request):
-    check_missing_attributes(json_request, ['key', 'session_id'])
-    if model.valid_key(json_request['key']):
-        user_id = model.get_user_id_by_session_id(json_request['session_id'])
-        model.activate_key(json_request['key'], user_id)
-        return {'message': "successfully activated key"}
-    else:
-        return BadRequest('Invalid key.')
-
-
 def order(json_request):
     check_missing_attributes(json_request, ['buy', 'session_id', 'amount', 'ownable', 'time_until_expiration'])
     if not model.ownable_name_exists(json_request['ownable']):