Пример #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 edit_profile_post(account_id):
    """ Perform registration of a new user """
    errors, values = {}, dict(request.form.items())

    account = Account.by_id(account_id)
    if not account:
        flash_error("This is not a valid account")
        abort(404)
    if account.id != current_user.id and not current_user.admin:
        flash_error("You cannot access this content")
        abort(403)

    try:
        # Grab the actual data and validate it
        data = AccountSettings().deserialize(values)

        if (data['website'].find('http://') == -1) and data['website'] != "":
            data['website'] = 'http://%s' % data['website']

        account.fullname = data['fullname']
        account.website = data['website']
        db.session.commit()

        # TO DO redirect to email sent page
        return redirect(url_for('account.profile', account_id=account.id))
    except colander.Invalid as i:
        errors = i.asdict()
        print errors
    if request.form.get("csrf_token", None):
        values['csrf_token'] = request.form.get('csrf_token')
    else:
        values["csrf_token"] = generate_csrf_token()
    return render_template('account/edit_profile.jade',
                           form_fill=values,
                           form_errors=errors,
                           account_id=account_id)
Пример #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, i:
                # Load errors if we get here
                errors = i.asdict()
Пример #5
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)