Esempio n. 1
0
    def post(self, invitedGuest=False):
        args = self.req_parser.parse_args()
        email = args['email']
        firstname = args['firstname']
        lastname = args['lastname']
        user_title = args['user_title']
        policy_agreed = args['policy_agreed']
        user_primaryLanguage = args['language']

        if (invitedGuest):
            password = self.randomPassword()
        else:
            password = args['password']

        if (password is None):
            return MISSING_PASSWORD

        if not policy_agreed:
            return POLICY_NOT_AGREED

        LOGGER.info("Registering email: {}".format(email))

        user = AppUser(email=email,
                       firstname=firstname,
                       lastname=lastname,
                       user_title=user_title,
                       password=password,
                       organisation_id=g.organisation.id)
        user.user_primaryLanguage = user_primaryLanguage

        db.session.add(user)

        try:
            db.session.commit()
        except IntegrityError:
            LOGGER.error("email: {} already in use".format(email))
            return EMAIL_IN_USE

        if (not invitedGuest):
            email_user(
                'verify-email',
                template_parameters=dict(system=g.organisation.system_name,
                                         organisation=g.organisation.name,
                                         host=misc.get_baobab_host(),
                                         token=user.verify_token),
                user=user,
                subject_parameters=dict(system=g.organisation.system_name))

            LOGGER.debug("Sent verification email to {}".format(user.email))
        else:
            user.verified_email = True
            try:
                db.session.commit()
            except IntegrityError:
                LOGGER.error("Unable to verify email: {}".format(email))
                return VERIFY_EMAIL_INVITED_GUEST

        return user_info(user, []), 201
Esempio n. 2
0
    def seed_static_data(self, add_offer=True):
        db.session.add(UserCategory('Offer Category'))
        db.session.add(Country('Suid Afrika'))
        db.session.commit()
        db.session.commit()

        test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                            'Male', 'University', 'Computer Science', 'None',
                            1, datetime(1984, 12, 12), 'Zulu', '654321')
        test_user.verified_email = True
        db.session.add(test_user)
        db.session.commit()

        offer_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms',
                              1, 1, 'F', 'NWU', 'Math', 'NA', 1,
                              datetime(1984, 12, 12), 'Eng', '654321', True)
        offer_admin.verified_email = True
        db.session.add(offer_admin)

        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12),
            end_date=datetime(2020, 12, 12),
        )
        db.session.add(event)
        db.session.commit()

        if add_offer:
            offer = Offer(user_id=test_user.id,
                          event_id=event.id,
                          offer_date=datetime.now(),
                          expiry_date=datetime.now() + timedelta(days=15),
                          payment_required=False,
                          travel_award=True,
                          accommodation_award=False)
            db.session.add(offer)
            db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Esempio n. 3
0
    def seed_static_data(self):
        test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                            'Male', 'University', 'Computer Science', 'None', 1,
                            datetime(1984, 12, 12),
                            'Zulu',
                            '123456')
        test_user.verified_email = True
        db.session.add(test_user)

        test_user2 = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                             'Male', 'University', 'Computer Science', 'None', 1,
                             datetime(1984, 12, 12),
                             'Zulu',
                             '123456')
        test_user2.verified_email = True
        db.session.add(test_user2)

        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))

        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms', 1,
                              1, 'F', 'NWU', 'Math', 'NA', 1, datetime(1984, 12, 12), 'Eng', '123456')
        event_admin.verified_email = True
        db.session.add(event_admin)

        self.event1 = Event('Indaba', 'Indaba Event',
                            datetime.now(), datetime.now())
        self.event2 = Event('IndabaX', 'IndabaX Sudan',
                            datetime.now(), datetime.now())
        db.session.add(self.event1)
        db.session.add(self.event2)

        adminRole = EventRole('admin', 3, 1)
        db.session.add(adminRole)
        db.session.commit()

        self.event1_id = self.event1.id
        self.event2_id = self.event2.id
        self.headers = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Esempio n. 4
0
    def seed_static_data(self):

        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                            'Male', 'University', 'Computer Science', 'None',
                            1, datetime(1984, 12, 12), 'Zulu', '123456')
        test_user.verified_email = True
        db.session.add(test_user)
        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),
        )
        db.session.add(event)
        db.session.commit()
        self.event = event
Esempio n. 5
0
    def seed_static_data(self, create_registration=False):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                            'Male', 'University', 'Computer Science', 'None', 1,
                            datetime(1984, 12, 12),
                            'Zulu',
                            '123456')
        test_user.verified_email = True
        db.session.add(test_user)
        db.session.commit()

        test_user2 = AppUser('*****@*****.**', 'Something2', 'Thing2', 'Mrs', 1, 1,
                            'Female', 'University of Indaba', 'Machine Learning', 'None', 1,
                            datetime(1985, 2, 3),
                            'Zulu',
                            '123456')
        test_user2.verified_email = True
        db.session.add(test_user2)
        db.session.commit()

        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms', 1,
                              1, 'F', 'NWU', 'Math', 'NA', 1, datetime(1984, 12, 12), 'Eng', '123456', True)
        event_admin.verified_email = True
        db.session.add(event_admin)

        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),

        )
        db.session.add(event)
        db.session.commit()

        self.offer = Offer(
            user_id=test_user.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=False,
            travel_award=True,
            accommodation_award=False,
            responded_at=datetime.now())
        self.offer.candidate_response = True
        self.offer.accepted_travel_award = True
        db.session.add(self.offer)
        db.session.commit()

        self.offer2 = Offer(
            user_id=test_user2.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=True,
            travel_award=True,
            accommodation_award=False,
            responded_at=datetime.now())
        db.session.add(self.offer2)
        db.session.commit()

        self.offer3 = Offer(
            user_id=event_admin.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=True,
            travel_award=False,
            accommodation_award=True,
            responded_at=datetime.now())
        db.session.add(self.offer3)
        db.session.commit()

        self.form = RegistrationForm(
            event_id=event.id
        )
        db.session.add(self.form)
        db.session.commit()

        section = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section)
        db.session.commit()

        section2 = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 2",
            description="the section 2 description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section2)
        db.session.commit()

        self.question = RegistrationQuestion(
            section_id=section.id,
            registration_form_id=self.form.id,
            description="Question 1",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text"
        )
        db.session.add(self.question)
        db.session.commit()

        self.question2 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 2",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text"
        )
        db.session.add(self.question2)
        db.session.commit()

        self.question3 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 3",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text"
        )
        db.session.add(self.question3)
        db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.headers2 = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        if create_registration:
            self.registration1 = Registration(self.offer.id, self.form.id, confirmed=False)
            db.session.add(self.registration1)
            db.session.commit()
            self.registration2 = Registration(self.offer2.id, self.form.id, confirmed=True)
            db.session.add(self.registration2)
            db.session.commit()
            self.registration3 = Registration(self.offer3.id, self.form.id, confirmed=False)
            db.session.add(self.registration3)
            db.session.commit()

        db.session.flush()
Esempio n. 6
0
    def seed_static_data(self):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                            'Male', 'University', 'Computer Science', 'None',
                            1, datetime(1984, 12, 12), 'Zulu', '123456')
        test_user.verified_email = True
        db.session.add(test_user)
        db.session.commit()

        test_user_2 = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr',
                              1, 1, 'Female', 'University',
                              'Computer Science', 'None', 1,
                              datetime(1984, 12, 12), 'Zulu', '123456')
        test_user_2.verified_email = True
        db.session.add(test_user_2)
        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),
        )
        db.session.add(event)
        db.session.commit()

        offer = Offer(user_id=test_user.id,
                      event_id=event.id,
                      offer_date=datetime.now(),
                      expiry_date=datetime.now() + timedelta(days=15),
                      payment_required=False,
                      accommodation_award=True,
                      travel_award=True,
                      accepted_accommodation_award=True,
                      accepted_travel_award=True)
        db.session.add(offer)
        db.session.commit()

        offer_2 = Offer(
            user_id=test_user_2.id,
            event_id=event.id,
            offer_date=datetime.now(),
            expiry_date=datetime.now() + timedelta(days=15),
            payment_required=True,
            accommodation_award=False,
            travel_award=False,
            accepted_accommodation_award=False,
            accepted_travel_award=False,
        )
        db.session.add(offer_2)
        db.session.commit()

        form = RegistrationForm(event_id=event.id)
        db.session.add(form)
        db.session.commit()

        section = RegistrationSection(
            registration_form_id=form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=True,
            show_for_accommodation_award=False,
            show_for_payment_required=False,
        )
        db.session.add(section)
        db.session.commit()

        rq = RegistrationQuestion(section_id=section.id,
                                  registration_form_id=form.id,
                                  description="Will you be bringing a poster?",
                                  type="short-text",
                                  is_required=True,
                                  order=1,
                                  placeholder="the placeholder",
                                  headline="Will you be bringing a poster?",
                                  validation_regex="[]/",
                                  validation_text=" text")
        db.session.add(rq)
        db.session.commit()

        registration = Registration(offer_id=offer.id,
                                    registration_form_id=form.id,
                                    confirmed=True)
        db.session.add(registration)
        db.session.commit()

        registration_2 = Registration(offer_id=offer_2.id,
                                      registration_form_id=form.id,
                                      confirmed=True)
        db.session.add(registration_2)
        db.session.commit()

        ra = RegistrationAnswer(registration_id=registration_2.id,
                                registration_question_id=rq.id,
                                value="yes")
        db.session.add(ra)
        db.session.commit()

        template = InvitationTemplate(
            event_id=event.id,
            template_path="Indaba 2019  - Invitation Letter - General.docx",
            send_for_travel_award_only=False,
            send_for_accommodation_award_only=False,
            send_for_both_travel_accommodation=True)
        db.session.add(template)

        template_2 = InvitationTemplate(
            event_id=event.id,
            template_path=
            "Indaba 2019 - Invitation Letter - Travel & Accomodation.docx",
            send_for_travel_award_only=False,
            send_for_accommodation_award_only=False,
            send_for_both_travel_accommodation=False)
        db.session.add(template_2)
        db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.headers_2 = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Esempio n. 7
0
    def seed_static_data(self):
        db.session.add(UserCategory('Postdoc'))
        db.session.add(Country('South Africa'))
        db.session.commit()

        test_user = AppUser('*****@*****.**', 'Some', 'Thing', 'Mr', 1, 1,
                            'Male', 'University', 'Computer Science', 'None',
                            1, datetime(1984, 12, 12), 'Zulu', '123456')
        test_user.verified_email = True
        db.session.add(test_user)
        db.session.commit()

        event_admin = AppUser('*****@*****.**', 'event_admin', '1', 'Ms',
                              1, 1, 'F', 'NWU', 'Math', 'NA', 1,
                              datetime(1984, 12, 12), 'Eng', '123456', True)
        event_admin.verified_email = True
        db.session.add(event_admin)

        db.session.commit()

        event = Event(
            name="Tech Talk",
            description="tech talking",
            start_date=datetime(2019, 12, 12, 10, 10, 10),
            end_date=datetime(2020, 12, 12, 10, 10, 10),
        )
        db.session.add(event)
        db.session.commit()

        self.form = RegistrationForm(event_id=event.id)
        db.session.add(self.form)
        db.session.commit()

        self.event_id = event.id

        section = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 1",
            description="the section description",
            order=1,
            show_for_travel_award=None,
            show_for_accommodation_award=None,
            show_for_payment_required=None,
        )
        db.session.add(section)
        db.session.commit()

        section2 = RegistrationSection(
            registration_form_id=self.form.id,
            name="Section 2",
            description="the section 2 description",
            order=1,
            show_for_travel_award=None,
            show_for_accommodation_award=None,
            show_for_payment_required=None,
        )
        db.session.add(section2)
        db.session.commit()

        self.question = RegistrationQuestion(section_id=section.id,
                                             registration_form_id=self.form.id,
                                             description="Question 1",
                                             type="short-text",
                                             is_required=True,
                                             order=1,
                                             placeholder="the placeholder",
                                             headline="the headline",
                                             validation_regex="[]/",
                                             validation_text=" text")
        db.session.add(self.question)
        db.session.commit()

        self.question2 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 2",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text")
        db.session.add(self.question2)
        db.session.commit()

        self.question3 = RegistrationQuestion(
            section_id=section2.id,
            registration_form_id=self.form.id,
            description="Question 3",
            type="short-text",
            is_required=True,
            order=1,
            placeholder="the placeholder",
            headline="the headline",
            validation_regex="[]/",
            validation_text=" text")
        db.session.add(self.question3)
        db.session.commit()

        self.headers = self.get_auth_header_for("*****@*****.**")
        self.adminHeaders = self.get_auth_header_for("*****@*****.**")

        db.session.flush()
Esempio n. 8
0
    def post(self, invitedGuest=False):
        args = self.req_parser.parse_args()
        email = args['email']
        firstname = args['firstname']
        lastname = args['lastname']
        user_title = args['user_title']
        nationality_country_id = args['nationality_country_id']
        residence_country_id = args['residence_country_id']
        user_gender = args['user_gender']
        affiliation = args['affiliation']
        department = args['department']
        user_disability = args['user_disability']
        user_category_id = args['user_category_id']

        if (invitedGuest):
            password = self.randomPassword()
        else:
            password = args['password']

        if (password is None):
            return MISSING_PASSWORD

        user_dateOfBirth = datetime.strptime((args['user_dateOfBirth']),
                                             '%Y-%m-%dT%H:%M:%S.%fZ')
        user_primaryLanguage = args['user_primaryLanguage']

        LOGGER.info("Registering email: {}".format(email))

        user = AppUser(email=email,
                       firstname=firstname,
                       lastname=lastname,
                       user_title=user_title,
                       nationality_country_id=nationality_country_id,
                       residence_country_id=residence_country_id,
                       user_gender=user_gender,
                       affiliation=affiliation,
                       department=department,
                       user_disability=user_disability,
                       user_category_id=user_category_id,
                       user_dateOfBirth=user_dateOfBirth,
                       user_primaryLanguage=user_primaryLanguage,
                       password=password)

        db.session.add(user)

        try:
            db.session.commit()
        except IntegrityError:
            LOGGER.error("email: {} already in use".format(email))
            return EMAIL_IN_USE

        if (not invitedGuest):
            send_mail(recipient=user.email,
                      subject='Baobab Email Verification',
                      body_text=VERIFY_EMAIL_BODY.format(
                          user_title, firstname, lastname, get_baobab_host(),
                          user.verify_token))

            LOGGER.debug("Sent verification email to {}".format(user.email))
        else:
            user.verified_email = True
            try:
                db.session.commit()
            except IntegrityError:
                LOGGER.error("Unable to verify email: {}".format(email))
                return VERIFY_EMAIL_INVITED_GUEST

        return user_info(user, []), 201