Пример #1
0
    def settings(self):
        require.account.update(c.account)
        errors, values = {}, c.account
        if request.method == 'POST':
            try:
                schema = AccountSettings()
                values = request.params
                data = schema.deserialize(values)
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                c.account.fullname = data['fullname']
                c.account.email = data['email']
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(data['password1'])
                db.session.add(c.account)
                db.session.commit()
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                errors = i.asdict()
Пример #2
0
    def settings(self):
        require.account.update(c.account)
        errors, values = {}, c.account
        if request.method == 'POST':
            try:
                schema = AccountSettings()
                values = request.params
                data = schema.deserialize(values)
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                c.account.fullname = data['fullname']
                c.account.email = data['email']
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(
                        data['password1'])
                db.session.add(c.account)
                db.session.commit()
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                errors = i.asdict()
Пример #3
0
    def settings(self):
        """
        Change settings for the logged in user
        """

        # The logged in user must be able to update the account
        require.account.update(c.account)

        # Disable the cache
        self._disable_cache()

        # Initial values and errors
        errors, values = {}, c.account

        # If POST the user is trying to update the settings
        if request.method == 'POST':
            try:
                # Get the account settings schema (for validation)
                schema = AccountSettings()

                # Set values from the request parameters
                # (for validation and so we can autofill forms)
                values = request.params

                # Grab the actual data and validate it
                data = schema.deserialize(values)

                # If the passwords don't match we notify the user
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                # Update full name
                c.account.fullname = data['fullname']
                
                # Update the script root
                c.account.script_root = data['script_root']
                
                # Update email and whether email should be public
                c.account.email = data['email']
                c.account.public_email = data['public_email']

                # If twitter handle is provided we update it
                # (and if it should be public)
                if data['twitter'] is not None:
                    c.account.twitter_handle = data['twitter'].lstrip('@')
                    c.account.public_twitter = data['public_twitter']

                # If a new password was provided we update it as well
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(data['password1'])

                # Do the actual update in the database
                db.session.add(c.account)
                db.session.commit()
                
                # Let the user know we've updated successfully
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid, i:
                # Load errors if we get here
                errors = i.asdict()
Пример #4
0
    def settings(self):
        """
        Change settings for the logged in user
        """

        # The logged in user must be able to update the account
        require.account.update(c.account)

        # Disable the cache
        self._disable_cache()

        # Initial values and errors
        errors, values = {}, c.account

        # If POST the user is trying to update the settings
        if request.method == 'POST':
            try:
                # Get the account settings schema (for validation)
                schema = AccountSettings()

                # Set values from the request parameters
                # (for validation and so we can autofill forms)
                values = request.params

                # Grab the actual data and validate it
                data = schema.deserialize(values)

                # If the passwords don't match we notify the user
                if not data['password1'] == data['password2']:
                    raise colander.Invalid(AccountSettings.password1,
                                           _("Passwords don't match!"))

                # Update full name
                c.account.fullname = data['fullname']

                # Update the script root
                c.account.script_root = data['script_root']

                # Update email and whether email should be public
                c.account.email = data['email']
                c.account.public_email = data['public_email']

                # If twitter handle is provided we update it
                # (and if it should be public)
                if data['twitter'] is not None:
                    c.account.twitter_handle = data['twitter'].lstrip('@')
                    c.account.public_twitter = data['public_twitter']

                # If a new password was provided we update it as well
                if data['password1'] is not None and len(data['password1']):
                    c.account.password = generate_password_hash(
                        data['password1'])

                # Do the actual update in the database
                db.session.add(c.account)
                db.session.commit()

                # Let the user know we've updated successfully
                h.flash_success(_("Your settings have been updated."))
            except colander.Invalid as i:
                # Load errors if we get here
                errors = i.asdict()
        else:
            # Get the account values to autofill the form
            values = c.account.as_dict()

            # We need to put public checks separately because they're not
            # a part of the dictionary representation of the account
            if c.account.public_email:
                values['public_email'] = c.account.public_email
            if c.account.public_twitter:
                values['public_twitter'] = c.account.public_twitter

        # Return the rendered template
        return templating.render('account/settings.html',
                                 form_fill=values,
                                 form_errors=errors)