FedericoCeratto/bottle-cork

Best way to add more user fields to user profile?

Opened this issue · 1 comments

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

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.