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)
def post(self): data = self.params() msisdn = data.get('msisdn', 0) if not msisdn or msisdn == 0: msisdn = data.get('mobile') if not msisdn or msisdn == 0: message = { "success": { "status": 400, "message": "Invalid phone number" } } return make_response(json.dumps(message), 200) scorepesa = Scorepesa(current_app.logger) profile_id, new = scorepesa.create_profile({"msisdn": msisdn}, 0) helper = Helper(current_app.logger) password_set = False if new: code = get_code() password = None #self.generate_pass_str(data.get('password')) message = "Namba yako ya uthibitisho wa akaunti yako ya Scorepesa"\ " ni %s. Ingiza namba kwenye tovuti kukamilisha mchakato huu" % (code, ) network = get_network_from_msisdn_prefix(msisdn) helper.create_profile_settings(profile_id, code, password) outbox_id = helper.create_outbox(profile_id, msisdn, network, message) send_notification(msisdn, outbox_id, network, message) elif data.get('password'): password = self.generate_pass_str(data.get('password')) password_set = helper.set_password(profile_id, password) if profile_id > 0 and new: message = { "success": { "status": 201, "message": "Account created success" } } elif password_set: message = { "message": "Account password set successfully", "status": 201 } elif profile_id == -1: message = { "success": { "status": 500, "message": "Encountered problem trying to create profile, Please try again later" } } else: message = { "success": { "status": 200, "message": "Account alreay exists, proceed to login and play with scorepesa.com" } } return make_response(json.dumps(message), 200)