def post(self): helper = Helper(current_app.logger) data = self.params() msisdn = clean_msisdn(data.get('mobile')) code = data.get('code') ok = helper.verify_code(msisdn, code) if ok: profile_data = helper.get_profile_data(msisdn) token = helper.create_hash_token(msisdn, profile_data[0], remember=0) if ok and token: message = { 'success': { 'status': 201, "message": "Verification code has been sent to your phone" }, 'token': token } else: message = { 'error': { 'status': 401, "message": "Verification failed. Kindly check code and try again or click resend code to receive new code" } } return make_response(json.dumps(message), 200)
def process_response(self): data = self.params() current_app.logger.info("Login requesrt eceived: %r" % data) msisdn = clean_msisdn(data.get('msisdn')) if not msisdn: return { "status": 401, "message": "Invalid username and or password", 'token': '' } password = data.get("password") if not password: return { "status": 401, "message": "Invalid username and or password", 'token': '' } helper = Helper(current_app.logger) profile_data = helper.get_profile_data(msisdn) if not profile_data: return { 'status': 401, "message": "Invalid username and or password", 'token': '' } real_pass = profile_data[1] if not checkpw(password, real_pass): return { "status": 401, "message": "Invalid username and or password", 'token': '' } token = helper.create_hash_token(msisdn, profile_data[0], remember=data.get('remember')) if not token: return { "status": 401, "message": "Could not create token", 'token': '' } return { "status": 200, "user": { 'token': token, 'profile_id': str(profile_data[0]), 'balance': float(profile_data[3]), 'msisdn': msisdn, 'bonus': float(profile_data[4]) } }
def post(self): helper = Helper(current_app.logger) data = self.params() current_app.logger.info("Android code request with data => %r" % data) msisdn = clean_msisdn(data.get('mobile')) network = get_network_from_msisdn_prefix(msisdn) helper = Helper(current_app.logger) code, profile_id = helper.get_existing_code(msisdn) if code: profile_data = helper.get_profile_data(msisdn) token = helper.create_hash_token(msisdn, profile_data[0], remember=0) message = "Namba yako ya uthibitisho wa akaunti yako ya Scorepesa"\ " ni %s. Ingiza namba kwenye tovuti kukamilisha mchakato huu" % (code, ) outbox_id = helper.create_outbox(profile_id, msisdn, network, message) send_notification(msisdn, outbox_id, network, message) message = { 'success': { 'status': 200, 'id': profile_id, "message": "Verification code has been sent to your phone", 'code': code }, 'token': token } else: message = { 'error': { 'status': 401, "message": "Verification code could not be resent. Kindly check your mobile number and try again" } } return make_response(json.dumps(message), 200)