Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to add more user fields to user profile? #104

Open
oshihirii opened this issue Jul 31, 2016 · 1 comment
Open

Best way to add more user fields to user profile? #104

oshihirii opened this issue Jul 31, 2016 · 1 comment

Comments

@oshihirii
Copy link

I can see user profile fields are created in:

register() - https://github.com/FedericoCeratto/bottle-cork/blob/master/cork/cork.py#L387

and then passed through to pending_registrations collection and then users collection on validate_registration().

What is the best way to add more user fields without hacking bottle-cork files?

Possibly (with pymongo):

  1. Add fields to pending_registrations collection after register(), by assigning post_get('email_address') to variable email_addr and matching it in the pending_registrations collection and adding new fields with db.pending_registrations.update({"email_addr": email_addr},{"$set": {"new_key1":[],"new_key_2":"hello"}}). (I tried this, it works).

  2. But then I need to ensure that the fields are added to users collection at validate_registration(), but these fields are "hard-coded" here:

        # the user data is moved from pending_registrations to _users
        self._store.users[username] = {
            'role': data['role'],
            'hash': data['hash'],
            'email_addr': data['email_addr'],
            'desc': data['desc'],
            'creation_date': data['creation_date'],
            'last_login': str(datetime.utcnow())
}

https://github.com/FedericoCeratto/bottle-cork/blob/master/cork/cork.py#L467

@oshihirii
Copy link
Author

I ended up just having to hardcode changes in cork.py at validate_registration().

Just thinking out loud, I wonder if it is possible to iterate over data, get its key names and dynamically create the required key values to be added to users collection (so the custom fields are added as well). And perhaps pop off the unnecessary fields - pending registration number etc. Might have a look at doing that when I have a moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant