def _handle_activate_device(self, client, cid: str, params: dict) -> bool: login = params[Subscriber.EMAIL_FIELD] password_hash = params[Subscriber.PASSWORD_FIELD] check_user = Subscriber.objects(email=login, class_check=False).first() if not check_user: client.activate_device_fail(cid, 'User not found') return False if check_user.status == Subscriber.Status.NOT_ACTIVE: client.activate_device_fail(cid, 'User not active') return False if check_user.status == Subscriber.Status.BANNED: client.activate_device_fail(cid, 'Banned user') return False if check_user[Subscriber.PASSWORD_FIELD] != password_hash: client.activate_device_fail(cid, 'User invalid password') return False result = client.activate_device_success(cid, check_user.get_devices()) if not result: return False client.info = check_user self.__activate_subscriber(client) return True
def remove_subscriber(self): data = request.get_json() sid = data['sid'] subscriber = Subscriber.objects(id=sid).first() if subscriber: subscriber.delete() return jsonify(status='ok'), 200 return jsonify(status='failed'), 404
def subscriber_edit(self, sid): subscriber = Subscriber.objects(id=sid).first() form = SignupForm(obj=subscriber) if request.method == 'POST' and form.validate_on_submit(): subscriber = form.update_entry(subscriber) subscriber.save() return jsonify(status='ok'), 200 return render_template('service/subscriber/edit.html', form=form)
def subscriber_send_message(self, sid): subscriber = Subscriber.objects(id=sid).first() form = MessageForm() if request.method == 'POST' and form.validate_on_submit(): servers_manager.send_message(subscriber.email, form.get_data()) return jsonify(status='ok'), 200 return render_template('service/subscriber/send_message.html', form=form)
def subscriber_send_message(self, sid): native_balancer = app.config.get('INTERNAL_LOAD_BALANCER') if not native_balancer: return "Send message for internal LB not implemented!" subscriber = Subscriber.objects(id=sid).first() form = MessageForm() if request.method == 'POST' and form.validate_on_submit(): servers_manager.send_message(subscriber.email, form.get_data()) return jsonify(status='ok'), 200 return render_template('service/subscriber/send_message.html', form=form)
def _handle_login(self, client, cid: str, params: dict) -> bool: login = params[Subscriber.EMAIL_FIELD] password_hash = params[Subscriber.PASSWORD_FIELD] device_id = params['device_id'] check_user = Subscriber.objects(email=login, class_check=False).first() if not check_user: client.login_fail(cid, 'User not found') return False if check_user.status == Subscriber.Status.NOT_ACTIVE: client.login_fail(cid, 'User not active') return False if check_user.status == Subscriber.Status.BANNED: client.login_fail(cid, 'Banned user') return False if check_user[Subscriber.PASSWORD_FIELD] != password_hash: client.login_fail(cid, 'User invalid password') return False found_device = check_user.find_device(device_id) if not found_device: client.login_fail(cid, 'Device not found') return False if found_device.status == Device.Status.BANNED: client.login_fail(cid, 'Device banned') return False if found_device.status == Device.Status.NOT_ACTIVE: found_device.status = Device.Status.ACTIVE check_user.save() user_connections = self.get_user_connections_by_email(login) for conn in user_connections: if conn.device == found_device: client.login_fail(cid, 'Device in use') return False result = client.login_success(cid) if not result: return False client.info = check_user client.device = found_device self.__login_subscriber(client) return True
def make_subscriber(cls, email: str, password: str, country: str, language: str): return cls(email=email, password=Subscriber.make_md5_hash_from_password(password), country=country, language=language)