def WithdrawVault(): status_code = authenticate_request(request.headers, request.remote_addr) if status_code != INT_OK: return respond_json(status_code) user_id = request.headers['userId'] fields = json_decode(request.data) if fields.has_key('coins'): coins_result = WithdrawCoins(user_id, fields['coins']) return respond_json(INT_OK, **coins_result) else: return respond_json(INT_ERROR_FORMAT)
def renew_token_proc(userid, client_ip): """ Method to renew token """ status_code, userid, mytoken, mytoken_valid_time = renew_token( userid, client_ip) if status_code == INT_OK: return respond_json(INT_OK, userId=userid, secret_token=mytoken, secret_token_exp=mytoken_valid_time) return respond_json(INT_ERROR_FORMAT)
def get_transactions(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) fields = json_decode(request.data) #TODO: save access token in social table. Use userid to get token and retrieve details if fields.has_key('access_token'): try: resp = GetTransactions(fields['access_token']) except Exception, e: return respond_json(INT_ERROR_GENERAL, msg=str(e)) else: return respond_json(INT_OK, **resp.json())
def delete_user(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) fields = json_decode(request.data) #TODO: save access token in social table. Use userid to get token and delete user if fields.has_key('access_token'): try: resp = DeleteUser(fields['access_token']) except Exception, e: return respond_json(INT_ERROR_GENERAL, message=str(e)) else: return respond_json(INT_OK)
def add_user(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) #check if available fields are present fields = json_decode(request.data) if fields.has_key('account') and fields.has_key( 'username') and fields.has_key('password'): #try to add user resp = AddUser(fields['account'], fields['username'], fields['password']) return respond_json(INT_OK, **resp) else: return respond_json(INT_ERROR_FORMAT)
def add_user_patch(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) #check if available fields are present fields = json_decode(request.data) #TODO: save access token in social table. Use userid to get token and update user if fields.has_key('access_token') and fields.has_key( 'username') and fields.has_key('password'): #try to add user resp = AddUserPatch(fields['access_token'], fields['username'], fields['password']) return respond_json(INT_OK, **resp) else: return respond_json(INT_ERROR_FORMAT)
def send_answer(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) fields = json_decode(request.data) #TODO: save access token in social table. Use userid to get token and retrieve details if fields.has_key('access_token') and fields.has_key( 'account') and fields.has_key('answer'): try: resp = answer_question(fields['account'], fields['access_token'], fields['answer']) except Exception, e: return respond_json(INT_ERROR_GENERAL, message=str(e)) else: return respond_json(INT_OK)
def login_proc(fields=None, client_ip=STR_UNDEFINED): """ This is the function that log in :param fields: :param client_ip: :return: on success, expect a secret token and a valid time (in min) returned """ _login_parsing_fields(fields) status_code, userid, secret_token, secret_token_exp = verify_user( (fields['username']), (fields['password']), True, client_ip) if status_code == INT_OK: return respond_json(INT_OK, userId=userid, secret_token=secret_token, secret_token_exp=secret_token_exp) else: return respond_json(status_code)
def GetVault(): """ Gets all Vault fields. Returns: State of users vault in the following format: {coins: [{coin1 fields}, {coin2 fields}, ...]} """ status_code = authenticate_request(request.headers, request.remote_addr) if status_code != INT_OK: return respond_json(status_code) user_id = request.headers['userId'] vault = GetCoins(user_id) if vault is None: return respond_json(INT_ERROR_NOTEXIST) return respond_json(INT_OK, **vault)
def UpdateVault(): """ Deposits specified coin amounts into vault Request body contains a 'coins' key with a list of dictionaries as it's value: {coins: [ {brandId: 2, coinAmt: 10}, {brandId: 3, coinAmt: -5} ... ] } Negative coinAmt = withdrawal Positive coinAmt = deposit Returns: Same format as input, except with success status for each coin update. For example: {coins: [ {brandId: 2, coinAmt: 10, status: 0}, {brandId: 3, coinAmt: -5, status: -1} ... ] } A status of 0 indicates success, and a status of -1 indicates failure. """ status_code = authenticate_request(request.headers, request.remote_addr) if status_code != INT_OK: return respond_json(status_code) user_id = request.headers['userId'] fields = json_decode(request.data) if fields.has_key('coins'): coins_result = UpdateCoins(user_id, fields['coins']) return respond_json(INT_OK, **coins_result) else: return respond_json(INT_ERROR_FORMAT)
def signup_proc(fields=None, client_ip=STR_UNDEFINED): """ This is the main proc for signup Protocol: signup fields: username password email signuptype: regular facebook twitter googleplus :param fields: :param client_ip: :return: """ _signup_parsing_fields(fields) status_code = create_new(fields['username'], fields['password'], fields['email'], fields['signuptype']) return respond_json(status_code)
def get_categories(): cats = GetCategories() return respond_json(INT_OK, categories=cats)
def get_banks(): banks = GetInstitutions() return respond_json(INT_OK, banks=banks)
@banking_api.route('/deleteuser', methods=['POST']) def delete_user(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) fields = json_decode(request.data) #TODO: save access token in social table. Use userid to get token and delete user if fields.has_key('access_token'): try: resp = DeleteUser(fields['access_token']) except Exception, e: return respond_json(INT_ERROR_GENERAL, message=str(e)) else: return respond_json(INT_OK) else: return respond_json(INT_ERROR_FORMAT) @banking_api.route('/transactions', methods=['POST']) def get_transactions(): status_code = authenticate_request(request.headers, request.remote_addr) if (status_code != INT_OK): return respond_json(status_code) fields = json_decode(request.data) #TODO: save access token in social table. Use userid to get token and retrieve details if fields.has_key('access_token'): try: resp = GetTransactions(fields['access_token']) except Exception, e: return respond_json(INT_ERROR_GENERAL, msg=str(e)) else:
def save_user_details_proc(userid='', fields={}): save_user_details(userid, fields) return respond_json(INT_OK)
def logout_proc(userid, token, client_ip): """ Method to log out and set the token as expired """ return respond_json(security_check(userid, token, client_ip, True))