your = utils.clearStringHard(auth._POST['your']) if ('tasks' in auth._POST) and not (auth._POST['tasks'] is None): tasks = utils.clearGlobalIds(auth._POST['tasks']) out_arr = [] your_arr = [] tasks_arr = [] tasks = getTotalIdsString(user_id=auth.user_id, devid=auth.user_some_state, cross=tasks, extendType=0)['info']['ids'] if len(tasks) < 1: headers.errorResponse('Please sync your device') sql = "select group_concat(id,',') as int_tasks from tasks where globalid in ('" + "','".join( tasks.split(',')) + "')" sql_request(sql) tasks_row = mydb.fetchone() if tasks_row is None: headers.errorResponse('Permission denied') tasks = str(tasks_row['int_tasks']).strip(',') if len(out) > 0: out_arr = list(set((int(x)) for x in out.split(','))) if len(your) > 0: your_arr = list(set((int(x)) for x in your.split(','))) if len(tasks) > 0: tasks_arr = list(set(str(x) for x in tasks.split(','))) all_devices = list(set().union(out_arr, your_arr)) # integers def_id = db.getDefaultDevice(auth.user_id) if (len(all_devices) < 1) or len(tasks) < 1:
if len(your_arr) < 1 and len(out_arr) < 1 and len(in_arr) < 1: headers.errorResponse( "Nothing to do") if str(auth.user_id) in your_arr: your_arr.remove(str(auth.user_id)) if str(def_id) in your_arr: your_arr.remove(str(def_id)) if len(your_arr) < 1 and len(out_arr) < 1 and len(in_arr) < 1: headers.errorResponse( "You can not remove current and default devices.\nBut you can erase your account from server") if len(out_arr) > 0: req_filter = ",".join(list(out_arr)) sql_request( "delete from sync_devices where src=" + str(auth.user_some_state) + " and dst in (" + req_filter + ")") sql_request("""delete sync_tasks from sync_tasks inner join tasks as t on t.id=sync_tasks.tid and t.devid=""" + str(auth.user_some_state) + """ where sync_tasks.dst in (""" + req_filter + ")") if len(in_arr) > 0: req_filter = ",".join(list(in_arr)) sql_request( "delete from sync_devices where dst=" + str(auth.user_some_state) + " and src in (" + req_filter + ")") sql_request("""delete sync_tasks from sync_tasks inner join tasks as t on t.id=sync_tasks.tid and t.devid in (""" + req_filter + """) where sync_tasks.dst in (""" + str(auth.user_some_state) + ")") if len(your_arr) > 0: req_filter = ",".join(list(your_arr)) sql_request(
from _common.api import headers from _common.api import utils from mobile_service.apiv1._mobile import sql_request headers.jsonAPI() jsonpost = auth._POST if (jsonpost is None) or ('login' not in jsonpost) or ('device' not in jsonpost): headers.errorResponse('Bad request') login = utils.clearUserLogin(jsonpost['login']) device = utils.clearUserLogin(jsonpost['device']) sql_request('select id from users where login="******" and state>0') uid = 0 rows = mydb.fetchall() for row in rows: uid = int(row['id']) sql_request('select id from devices where uid=' + str(uid) + ' and name="' + device + '"') another_device = 0 rows = mydb.fetchall() for row in rows: another_device = int(row['id']) if (another_device < 1) or (uid < 1): headers.errorResponse('Not found')
currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) sys.path.insert(0, os.path.dirname(os.path.dirname(currentdir))) from _common.api._settings import mydb from _common.api import auth from _common.api import headers from _common.api import utils from _common.api import translation from mobile_service.apiv1._mobile import sql_request headers.jsonAPI() jsonpost = auth._POST if (jsonpost is None) or ('invite' not in jsonpost): headers.errorResponse('Bad request') invite = utils.clearStringHard(str(jsonpost['invite']))[:7].lower() if len(invite) < 3: headers.errorResponse('Too short invite') sql_request('select id from sync_devices where (dst=' + str(auth.user_some_state) + ') and invite="' + invite + '"') row = mydb.fetchone() id = 0 if row is None: headers.errorResponse('Not found') id = int(row['id']) if id < 1: headers.errorResponse('Not found') sql_request('update sync_devices set invite="", state=1 where id=' + str(id)) headers.goodResponse({'state': True}, translation.getValue('confirm_invite'))