Exemplo n.º 1
0
 def after_login(self):
     if c.account is not None:
         h.flash_success(_("Welcome back, %s!") % c.account.name)
         redirect("/")
     else:
         h.flash_error(_("Incorrect user name or password!"))
         redirect("/login")
Exemplo n.º 2
0
 def after_login(self):
     if c.account is not None:
         h.flash_success(_("Welcome back, %s!") % c.account.name)
         redirect("/")
     else:
         h.flash_error(_("Incorrect user name or password!"))
         redirect("/login")
Exemplo n.º 3
0
    def give(self, dataset):
        """
        Award a given badge to a given dataset.
        """
        # Get the dataset
        self._get_dataset(dataset)

        # Get the badge
        badge_id = request.params.get('badge', None)
        badge = Badge.by_id(id=badge_id)

        if badge:
            # See if user can award this badge to a this dataset
            require.badge.give(badge, c.dataset)
            # Add the dataset to the badge datasets and commit to database
            badge.datasets.append(c.dataset)
            db.session.commit()
        else:
            # If we don't find the badge id we flash an error message
            h.flash_error(_('Badge not found.'))

        # Go to the dataset's main page
        redirect(
            h.url_for(controller='dataset',
                      action='view',
                      dataset=c.dataset.name))
Exemplo n.º 4
0
    def load(self, dataset, id):
        """
        Load the dataset into the database. If a url parameter 'sample'
        is provided then its value is converted into a boolean. If the value
        equals true we only perform a sample run, else we do a full load.
        """

        # Get our source (and dataset)
        self._get_source(dataset, id)

        # We require that the user can update the dataset
        require.dataset.update(c.dataset)

        # If the source is already running we flash an error declaring that
        # we're already running this source
        if c.source.is_running:
            h.flash_error(_("Already running!"))
        # If the source isn't already running we try to load it (or sample it)
        else:
            try:
                sample = asbool(request.params.get('sample', 'false'))
                load_source.delay(c.source.id, sample)
                # Let the user know we're loading the source
                h.flash_success(_("Now loading..."))
            except Exception as e:
                abort(400, e)

        # Send the user to the editor index page for this dataset
        redirect(
            h.url_for(controller='editor',
                      action='index',
                      dataset=c.dataset.name))
Exemplo n.º 5
0
    def load(self, dataset, id):
        """
        Load the dataset into the database. If a url parameter 'sample' 
        is provided then its value is converted into a boolean. If the value
        equals true we only perform a sample run, else we do a full load.
        """

        # Get our source (and dataset)
        self._get_source(dataset, id)

        # We require that the user can update the dataset
        require.dataset.update(c.dataset)

        # If the source is already running we flash an error declaring that
        # we're already running this source
        if c.source.is_running:
            h.flash_error(_("Already running!"))
        # If the source isn't already running we try to load it (or sample it)
        else:
            try:
                sample = asbool(request.params.get('sample', 'false'))
                load_source.delay(c.source.id, sample)
                # Let the user know we're loading the source
                h.flash_success(_("Now loading..."))
            except Exception, e:
                abort(400, e)
Exemplo n.º 6
0
 def after_login(self):
     self._disable_cache()
     if c.account is not None:
         h.flash_success(_("Welcome back, %s!") % c.account.name)
         redirect(h.url_for(controller='account', action='dashboard'))
     else:
         h.flash_error(_("Incorrect user name or password!"))
         redirect(h.url_for(controller='account', action='login'))
Exemplo n.º 7
0
 def after_login(self):
     self._disable_cache()
     if c.account is not None:
         h.flash_success(_("Welcome back, %s!") % c.account.name)
         redirect(h.url_for(controller='account', action='dashboard'))
     else:
         h.flash_error(_("Incorrect user name or password!"))
         redirect(h.url_for(controller='account', action='login'))
Exemplo n.º 8
0
 def locale(self):
     return_to = request.params.get('return_to', '/')
     locale = request.params.get('locale')
     if locale is not None:
         flash_success(_("Language has been set to: English"))
         set_session_locale(locale)
     else:
         flash_error(_("No language given!"))
     return_to += '&' if '?' in return_to else '?'
     # hack to prevent next page being cached
     return_to += '__cache=%s' % int(random.random() * 100000000)
     redirect(return_to.encode('utf-8'))
Exemplo n.º 9
0
 def locale(self):
     return_to = request.params.get("return_to", "/")
     locale = request.params.get("locale")
     if locale is not None:
         flash_success(_("Language has been set to: English"))
         set_session_locale(locale)
     else:
         flash_error(_("No language given!"))
     return_to += "&" if "?" in return_to else "?"
     # hack to prevent next page being cached
     return_to += "__cache=%s" % int(random.random() * 100000000)
     redirect(return_to.encode("utf-8"))
Exemplo n.º 10
0
 def locale(self):
     return_to = request.params.get('return_to', '/')
     locale = request.params.get('locale')
     if locale is not None:
         flash_success(_("Language has been set to: English"))
         set_session_locale(locale)
     else:
         flash_error(_("No language given!"))
     return_to += '&' if '?' in return_to else '?'
     # hack to prevent next page being cached
     return_to += '__cache=%s' % int(random.random() * 100000000)
     redirect(return_to.encode('utf-8'))
Exemplo n.º 11
0
    def trigger_reset(self):
        self._disable_cache()
        if request.method == 'GET':
            return render('account/trigger_reset.html')
        email = request.params.get('email')
        if email is None or not len(email):
            h.flash_error(_("Please enter an email address!"))
            return render('account/trigger_reset.html')
        account = Account.by_email(email)
        if account is None:
            h.flash_error(_("No user is registered under this address!"))
            return render('account/trigger_reset.html')
        send_reset_link(account)

        h.flash_success(_("You've received an email with a link to reset your "
            + "password. Please check your inbox."))
        redirect(h.url_for(controller='account', action='login'))
Exemplo n.º 12
0
    def trigger_reset(self):
        self._disable_cache()
        if request.method == 'GET':
            return render('account/trigger_reset.html')
        email = request.params.get('email')
        if email is None or not len(email):
            h.flash_error(_("Please enter an email address!"))
            return render('account/trigger_reset.html')
        account = Account.by_email(email)
        if account is None:
            h.flash_error(_("No user is registered under this address!"))
            return render('account/trigger_reset.html')
        send_reset_link(account)

        h.flash_success(
            _("You've received an email with a link to reset your " +
              "password. Please check your inbox."))
        redirect(h.url_for(controller='account', action='login'))
Exemplo n.º 13
0
    def trigger_reset(self):
        """
        Allow user to trigger a reset of the password in case they forget it
        """

        # Disable the cache
        self._disable_cache()

        # If it's a simple GET method we return the form
        if request.method == 'GET':
            return templating.render('account/trigger_reset.html')

        # Get the email
        email = request.params.get('email')

        # Simple check to see if the email was provided. Flash error if not
        if email is None or not len(email):
            h.flash_error(_("Please enter an email address!"))
            return templating.render('account/trigger_reset.html')

        # Get the account for this email
        account = Account.by_email(email)

        # If no account is found we let the user know that it's not registered
        if account is None:
            h.flash_error(_("No user is registered under this address!"))
            return templating.render('account/trigger_reset.html')

        # Send the reset link to the email of this account
        send_reset_link(account)

        # Let the user know that email with link has been sent
        h.flash_success(
            _("You've received an email with a link to reset your " +
              "password. Please check your inbox."))

        # Redirect to the login page
        redirect(h.url_for(controller='account', action='login'))
Exemplo n.º 14
0
    def create(self):
        """
        Create a new badge in the system
        """
        # Check if user is allowed to create a badge
        require.badge.create()

        import shutil

        label = request.params['badge-label']
        description = request.params['badge-description']
        image = request.POST['badge-image']

        try:
            # Get upload directory for Badge and generate a random filename
            upload_dir = h.get_object_upload_dir(Badge)
            random_filename = h.get_uuid_filename(image.filename)
            
            # Open the filename and copy the uploaded image
            permanent_filename = os.path.join(upload_dir, random_filename)
            permanent_image = open(permanent_filename, 'w')
            shutil.copyfileobj(image.file, permanent_image)

            upload_image_path = h.upload(random_filename, Badge)
            # Close image files
            image.file.close()
            permanent_image.close()
        except OSError:
            upload_image_path = ''
            h.flash_error(_('Uploading files not supported at the moment.'))

        badge = Badge(label, upload_image_path, description, c.account)
        db.session.add(badge)
        db.session.commit()

        redirect(h.url_for(controller='badge', action='information', 
                           id=badge.id))
Exemplo n.º 15
0
    def trigger_reset(self):
        """
        Allow user to trigger a reset of the password in case they forget it
        """

        # Disable the cache
        self._disable_cache()

        # If it's a simple GET method we return the form
        if request.method == 'GET':
            return templating.render('account/trigger_reset.html')

        # Get the email
        email = request.params.get('email')

        # Simple check to see if the email was provided. Flash error if not
        if email is None or not len(email):
            h.flash_error(_("Please enter an email address!"))
            return templating.render('account/trigger_reset.html')

        # Get the account for this email
        account = Account.by_email(email)

        # If no account is found we let the user know that it's not registered
        if account is None:
            h.flash_error(_("No user is registered under this address!"))
            return templating.render('account/trigger_reset.html')

        # Send the reset link to the email of this account
        send_reset_link(account)

        # Let the user know that email with link has been sent
        h.flash_success(_("You've received an email with a link to reset your "
            + "password. Please check your inbox."))

        # Redirect to the login page
        redirect(h.url_for(controller='account', action='login'))
Exemplo n.º 16
0
    def create(self):
        """
        Create a new badge in the system
        """
        # Check if user is allowed to create a badge
        require.badge.create()

        import shutil

        label = request.params['badge-label']
        description = request.params['badge-description']
        image = request.POST['badge-image']

        try:
            # Get upload directory for Badge and generate a random filename
            upload_dir = h.get_object_upload_dir(Badge)
            random_filename = h.get_uuid_filename(image.filename)

            # Open the filename and copy the uploaded image
            permanent_filename = os.path.join(upload_dir, random_filename)
            permanent_image = open(permanent_filename, 'w')
            shutil.copyfileobj(image.file, permanent_image)

            upload_image_path = h.upload(random_filename, Badge)
            # Close image files
            image.file.close()
            permanent_image.close()
        except OSError:
            upload_image_path = ''
            h.flash_error(_('Uploading files not supported at the moment.'))

        badge = Badge(label, upload_image_path, description, c.account)
        db.session.add(badge)
        db.session.commit()

        redirect(
            h.url_for(controller='badge', action='information', id=badge.id))
Exemplo n.º 17
0
    def give(self, dataset):
        """
        Award a given badge to a given dataset.
        """
        # Get the dataset
        self._get_dataset(dataset)

        # Get the badge
        badge_id = request.params.get('badge', None)
        badge = Badge.by_id(id=badge_id)

        if badge:
            # See if user can award this badge to a this dataset
            require.badge.give(badge, c.dataset)
            # Add the dataset to the badge datasets and commit to database
            badge.datasets.append(c.dataset)
            db.session.commit()
        else:
            # If we don't find the badge id we flash an error message
            h.flash_error(_('Badge not found.'))

        # Go to the dataset's main page
        redirect(h.url_for(controller='dataset', action='view',
                           dataset=c.dataset.name))
Exemplo n.º 18
0
 def do_reset(self):
     email = request.params.get('email')
     if email is None or not len(email):
         h.flash_error(_("The reset link is invalid!"))
         redirect(h.url_for(controller='account', action='login'))
     account = Account.by_email(email)
     if account is None:
         h.flash_error(_("No user is registered under this address!"))
         redirect(h.url_for(controller='account', action='login'))
     if request.params.get('token') != account.token:
         h.flash_error(_("The reset link is invalid!"))
         redirect(h.url_for(controller='account', action='login'))
     who_api = request.environ['repoze.who.plugins']['auth_tkt']
     headers = who_api.remember(request.environ,
             {'repoze.who.userid': account.name})
     response.headers.extend(headers)
     h.flash_success(_("Thanks! You have now been signed in - please change "
         + "your password!"))
     redirect(h.url_for(controller='account', action='settings'))
Exemplo n.º 19
0
 def do_reset(self):
     email = request.params.get('email')
     if email is None or not len(email):
         h.flash_error(_("The reset link is invalid!"))
         redirect(h.url_for(controller='account', action='login'))
     account = Account.by_email(email)
     if account is None:
         h.flash_error(_("No user is registered under this address!"))
         redirect(h.url_for(controller='account', action='login'))
     if request.params.get('token') != account.token:
         h.flash_error(_("The reset link is invalid!"))
         redirect(h.url_for(controller='account', action='login'))
     who_api = request.environ['repoze.who.plugins']['auth_tkt']
     headers = who_api.remember(request.environ,
                                {'repoze.who.userid': account.name})
     response.headers.extend(headers)
     h.flash_success(
         _("Thanks! You have now been signed in - please change " +
           "your password!"))
     redirect(h.url_for(controller='account', action='settings'))