Beispiel #1
0
    def work(self, request, req, res):
        attendee_info = AttendeeStatus.objects.filter(id=req['attendee_status_id'])

        if not attendee_info.exists():
            raise ValidationError('Invalid id', params=['attendee_status_id'])

        user = attendee_info[0].user

        if WifiCred.objects.filter(assigned_user=user).exists():
            raise ValidationError('Attendee already has wifi credentials', params=['attendee_status_id'])

        # Get new free wifi cred to assign
        credentials = WifiCred.objects.filter(hackathon=Hackathon.objects.current(), assigned_user__isnull=True)
        if not credentials.exists():
            raise ValidationError('No more wifi codes to assign!')

        credentials = credentials.all()
        cred = credentials[random.randint(0, len(credentials)-1)]

        # Assign
        cred.assigned_user = user
        cred.save()

        # Email
        email.send_template_to_user(user, 'wifi_credentials', 'Wifi Credentials', {
            'username': cred.username,
            'password': cred.password
        })
Beispiel #2
0
    def work(self, request, req: dict, res: dict):
        # Check captcha
        if not captcha.is_valid_response(req['g_recaptcha_response']):
            raise ValidationError('Captcha check failed',
                                  params=['g_recaptcha_response'])

        user = User.objects.filter(email=req['email'].lower())

        if user.exists():
            user = user[0]
        else:
            # Invalid, just ignore request
            return

        if LinkKey.objects.valid_key_exists_for_user(
                key_type=LinkKey.TYPE_PASSWORD_RESET, user=user):
            # Already has a pending reset
            return

        # Create key for password reset
        key = LinkKey.objects.create(user=user,
                                     type=LinkKey.TYPE_PASSWORD_RESET,
                                     key=LinkKey.generate_unique_key(),
                                     expires_at=(timezone.now() +
                                                 timedelta(days=1)))

        # Send email with link to reset
        email.send_template_to_user(
            user=user,
            template_name='password_reset',
            subject='HackFSU Password Reset Link',
            merge_vars={'password_reset_link': key.get_link()})
Beispiel #3
0
 def approve_application(self, request, queryset):
     total = 0
     for obj in queryset:
         if obj.approved is False:
             acl.add_user_to_group(obj.user, acl.group_hacker)
             acl.remove_user_from_group(obj.user, acl.group_pending_hacker)
             obj.approved = True
             obj.save()
             total += 1
             email.send_template_to_user(
                 obj.user, 'hacker_register_accepted', 'HackFSU Hacker Registration Approved'
             )
     self.message_user(request, 'Approved & emailed {} pending hackers'.format(total))
Beispiel #4
0
    def work(self, request, req: dict, res: dict):
        link_key = LinkKey.objects.get(key=request.session.get(SESSION_KEY))
        user = link_key.user
        user.set_password(req['new_password'])
        user.save()

        email.send_template_to_user(
            user=user,
            template_name='password_changed',
            subject='HackFSU Password Change Successful')

        logout(request)

        link_key.used_at = timezone.now()
        link_key.save()