def post(self, request): if 'email' in request.data: email = request.data['email'] else: raise CustomError(ERROR__API__EMAIL__NO_EMAIL_PROVIDED) try: user = UserProfile.objects.get(email=email) except: raise CustomError(ERROR__API__EMAIL__NO_EMAIL_PROVIDED) link_already = ForgotPasswordLinks.objects.filter(user=user).__len__() if link_already >= 1: raise CustomError(ERROR__API__USER__ALREADY_FORGOT_PASSWORD) user.is_active = False user.save() ip = get_client_ip(request) forgot_password_link = ForgotPasswordLinks(user=user, ip_address=ip) forgot_password_link.save() url = get_website_base_url( ) + "api/reset-password/" + forgot_password_link.link EmailSender.send_email_notification( [user.email], "Password reset", "Your password was resetted click here: " + url) return Response()
def post(self, request): if 'email' in request.data: email = request.data['email'] else: raise CustomError(ERROR__API__EMAIL__NO_EMAIL_PROVIDED) # EmailSender.send_email_notification([email], 'SYSTEM NOTIFICATION', 'There was a change') EmailSender.test_send(email) return Response()
def post(self, request): if not request.user.has_permission( permissions.PERMISSION_CAN_ADD_RECORD_RLC, for_rlc=request.user.rlc): raise CustomError(error_codes.ERROR__API__PERMISSION__INSUFFICIENT) data = request.data rlc = request.user.rlc if 'client_id' in data: try: client = models.Client.objects.get(pk=data['client_id']) except: raise CustomError( error_codes.ERROR__RECORD__CLIENT__NOT_EXISTING) client.note = data['client_note'] client.phone_number = data['client_phone_number'] client.save() else: client = models.Client(name=data['client_name'], phone_number=data['client_phone_number'], birthday=data['client_birthday'], note=data['client_note'], from_rlc=rlc) client.save() try: origin = models.OriginCountry.objects.get( pk=data['origin_country']) except: raise CustomError( error_codes.ERROR__RECORD__ORIGIN_COUNTRY__NOT_FOUND) client.origin_country = origin client.save() record = models.Record(client_id=client.id, first_contact_date=data['first_contact_date'], last_contact_date=data['first_contact_date'], record_token=data['record_token'], note=data['record_note'], creator_id=request.user.id, from_rlc_id=rlc.id, state="op", official_note=data['official_note']) record.save() for tag_id in data['tags']: record.tagged.add(models.RecordTag.objects.get(pk=tag_id)) for user_id in data['consultants']: record.working_on_record.add(UserProfile.objects.get(pk=user_id)) record.save() for user_id in data['consultants']: actual_consultant = UserProfile.objects.get(pk=user_id) url = FrontendLinks.get_record_link(record) EmailSender.send_email_notification( [actual_consultant.email], "New Record", "RLC Intranet Notification - Your were assigned as a consultant for a new record. Look here:" + url) return Response(serializers.RecordFullDetailSerializer(record).data)
def create(self, request): if type(request.data) is QueryDict: data = request.data.dict() else: data = dict(request.data) if 'rlc' in data: del data['rlc'] # Check if email already in use if UserProfile.objects.filter(email=request.data['email']).count() > 0: raise CustomError(ERROR__API__EMAIL__ALREADY_IN_USE) data['email'] = data['email'].lower() serializer = self.get_serializer(data=data) serializer.is_valid(raise_exception=True) self.perform_create(serializer) user = UserProfile.objects.get(email=request.data['email'].lower()) if 'rlc' not in request.data: raise CustomError(ERROR__API__REGISTER__NO_RLC_PROVIDED) user.rlc = Rlc.objects.get(pk=request.data['rlc']) if 'birthday' in request.data: user.birthday = request.data['birthday'] user.is_active = False user.save() # new user request from backend.api.models import NewUserRequest new_user_request = NewUserRequest(request_from=user) new_user_request.save() # new user activation link from backend.api.models import UserActivationLink user_activation_link = UserActivationLink(user=user) user_activation_link.save() EmailSender.send_user_activation_email( user, FrontendLinks.get_user_activation_link(user_activation_link)) headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def post(self, request, id): # request = self.request if 'message' not in request.data or request.data['message'] == '': raise CustomError( error_codes.ERROR__RECORD__MESSAGE__NO_MESSAGE_PROVIDED) message = request.data['message'] try: record = models.Record.objects.get(pk=id) except Exception as e: raise CustomError(error_codes.ERROR__RECORD__RECORD__NOT_EXISTING) if not record.user_has_permission(request.user): raise CustomError(error_codes.ERROR__API__PERMISSION__INSUFFICIENT) record_message = models.RecordMessage(sender=request.user, message=message, record=record) record_message.save() EmailSender.send_record_new_message_notification_email(record) return Response( serializers.RecordMessageSerializer(record_message).data)
def patch(self, request, id): record = models.Record.objects.get(pk=id) user = request.user if user.rlc != record.from_rlc and not user.is_superuser: raise CustomError( error_codes.ERROR__RECORD__RETRIEVE_RECORD__WRONG_RLC) if not record.user_has_permission(user): raise CustomError(error_codes.ERROR__API__PERMISSION__INSUFFICIENT) record_data = request.data['record'] client_data = request.data['client'] client = record.client try: record.note = record_data['note'] record.contact = record_data['contact'] record.last_contact_date = parse_date( record_data['last_contact_date']) record.state = record_data['state'] record.official_note = record_data['official_note'] record.additional_facts = record_data['additional_facts'] record.bamf_token = record_data['bamf_token'] record.foreign_token = record_data['foreign_token'] record.first_correspondence = record_data['first_correspondence'] record.circumstances = record_data['circumstances'] record.lawyer = record_data['lawyer'] record.related_persons = record_data['related_persons'] record.consultant_team = record_data['consultant_team'] record.next_steps = record_data['next_steps'] record.status_described = record_data['status_described'] record.tagged.clear() for tag in record_data['tags']: record.tagged.add(models.RecordTag.objects.get(pk=tag['id'])) client.note = client_data['note'] client.name = client_data['name'] client.birthday = parse_date(client_data['birthday']) client.origin_country = models.OriginCountry.objects.get( pk=client_data['origin_country']) client.phone_number = client_data['phone_number'] except: raise CustomError( error_codes.ERROR__RECORD__RECORD__COULD_NOT_SAVE) record.last_edited = datetime.utcnow().replace(tzinfo=pytz.utc) record.save() client.last_edited = datetime.utcnow().replace(tzinfo=pytz.utc) client.save() record_url = FrontendLinks.get_record_link(record) for user in record.working_on_record.all(): EmailSender.send_email_notification( [user.email], "Patched Record", "RLC Intranet Notification - A record of yours was changed. Look here:" + record_url) return Response({ 'record': serializers.RecordFullDetailSerializer( models.Record.objects.get(pk=record.pk)).data, 'client': serializers.ClientSerializer( models.Client.objects.get(pk=client.pk)).data })