Пример #1
0
    def login(self):
        """
        A view that logs in the user. Displays a login form and in case of a
        ``POST`` request, handles the login by checking whether it is valid.
        If it is, the user is logged in and redirected to the frontpage.
        """
        form = LoginForm(self.request.POST, csrf_context=self.request)
        retparams = {'form': form,
                     }
        if self.request.method == 'POST':
            if not form.validate():
                return retparams
            login_success, msg, team = login(form.email.data,
                                             form.password.data)
            if not login_success:
                self.request.session.flash("Login failed.", 'error')
                log.warn("Failed login attempt for team '%(team_email)s' "
                         "with IP Address '%(ip_address)s' and reason "
                         "'%(message)s'" %
                         {'team_email': form.email.data,
                          'ip_address': self.request.client_addr,
                          'message': msg,
                          }
                         )
                return retparams
            # Start a new session due to new permissions
            self.request.session.invalidate()

            # Check if CTF has started already
            ctf_started = self.request.settings.ctf_started
            if not ctf_started:
                ctf_start = self.request.settings.ctf_start_date
                self.request.session.flash(
                    "You are now logged in. However, the CTF has not started "
                    "yet and thus you cannot see any challenges or the "
                    "scoreboard. The CTF will start at %s (%s), i.e. %s UTC."
                    % (tz_str(ctf_start, team.timezone), team.timezone,
                       tz_str(ctf_start, utc)))
            else:
                self.request.session.flash("You have been logged in.",
                                           'success')
            headers = remember(self.request, team.id)
            return HTTPFound(location=self.request.route_url('home'),
                             headers=headers)
        return retparams
Пример #2
0
def test_tz_str():
    dt = datetime(2012, 1, 1, tzinfo=utc)
    tz = timezone("Europe/Berlin")
    assert tz_str(dt, tz) == "2012-01-01 01:00:00"