Prerequisites
This is a follow-up to #1806514: Unify anonymous and registered users.
Problem/Motivation
Currently the user 'account' is a hard-wired part of what we call a 'user' in Drupal. This is an annoying and unnecessary interdependency because the account itself is something that should be optional.
Benefits
With the account being optional and replacable by other, alternative authentication mechanisms we would ease the adoption of Drupal for niche use-cases where accounts are not actually required and cumbersome or only partly required (@see this comment for an example of such a case).
Also, the implementation of an anonymous user API according to #1806514: Unify anonymous and registered users would be much cleaner in general because there would be no stale account data on user entities of non-registered users.
Proposed resolution
Create a new, separate account entity with a primary key 'uid' for a unique relation between user and account. The account entity consists of the password and the initial e-mail address only.
Every visitor of a site can potentially be a user. By registering on the website a user would get an 'account' attached to his user entity through which he can identify himself as that user. Until then, this happens exclusively through the session.
We would end up with two distinct objects in core:
User - Any visitor, registered or not, can become a 'user'. That means that, whenever something that should be available to anonymous users but somehow requires a user entity (or would be better of if it had one) happens on the website we generate a user entity. Thus, a 'user' is any type of person that we want to be able to store information for. This could be anything from anonymous commenters (core) or voters (contrib) through to contacts in a complex, contributed CRM system as well as registered users with an account or other means to identify themselves on the site.
Account - Accounts would be the default way for Drupal to identify users. Users can create accounts and once an account is attached to a user entity that user is a 'registered user'. Accounts are somewhat optional and could be replaced with other authentication mechanisms that would also lead to 'registered users'.
Remaining tasks
Postponed on #1806514: Unify anonymous and registered users
Comments
Comment #1
michelleI think this might help my use case as well. I run the website for the camera club I am in and we maintain the "roster" via user accounts. This works great except for those who don't have email addresses (mostly the older ones). I currently put in a fake email for them but having them be users without accounts would be much cleaner, I think.
Michelle
Comment #2
yautja_cetanu commentedSummary
In this thread #1806514: Unify anonymous and registered users Sun proposed a potentially simpler method of only achieving an anonymous user API that helps with the comment module situation described in this issue #355513: Create an anonymous user API. We have invested how both ideas could be achieved. Sun’s is in theory and our idea can be found both in the Party module and fubhy’s sandbox: http://drupal.org/sandbox/sumsi/1806794
After further analysis we think that Sun’s proposal could work but is a little more complicated than it appears at first. Our idea appears complicated but think it is actually simpler then initially appears and has more scope at assisting many contrib cases. Both proposals would be helpful and so we have gone into detail here.
Sun/ Damien Tournoud’s Idea
We keep users as they are but put a flag on the user of whether it is anonymous or authenticated. We then move all systems that deal with anonymous users to deal with users + anonymous flag. For example when a comment is input with some information such as name, website and e-mail it is saved on a user that is flagged as anonymous. This user will be treated in almost the same way bar some exceptions.
Dealing with Names and Passwords requires some extra code.
Change the Database scheme or not?
We think that changing the database schema seems to be the reasonable conclusion as making it completely impossible even in contrib to allow anonymous users to have non-unique names does not make sense. However due to #845774: Regression: Anonymous users can post comments in the name of registered users this is arguably a good thing.
However if we want to allow anonymous users to be non-unique (And we definitely want them to not have a password) we need something like below
Example of how we would make an anonymous user API that deals with saving and updating usernames and passwords.
Wordy Code
Code Snippet
Our Proposal
Our idea completely separates the user information from the information required to authenticate that user. Our idea puts the username as a unique property on the account entity and deals with the name of a user with our “nice name concept”.
Potential Performance Worries and our solution
Loading a user and an account from the from the database will be slower and more memory intensive than loading one record from one table.
So instead we have found a way of not needing to load both tables in the vast majority of cases. For example, using the concept of a name on the user entity (nice_name), our patch in the issue only loads the account on 2 occasions.
We add a ‘name’ field onto the user table that is essentially free text and non-unique so that it can take any value. When comments are saved they can create a user and write directly to the name field. When accounts are created they will write to both the account name (which is unique) and the user name which is not unique.
This allows us to maintain unique account names, but allow for non-unique comment-poster names. We think this is no worse than sun’s proposal, especially regarding performance but allows for contrib to much more easily take control of the display name of a user entity.
This has a bunch of further benefits
It also opens up the potential for contrib to some really interesting things in the future
Comment #2.0
yautja_cetanu commentedUpdated issue summary.
Comment #15
smustgrave commentedPostponing #1806514: Unify anonymous and registered users
From the linked issue
While taking a look at #1816218: Separate the account information from the user entity. @catch found this issue and mentioned they both could be moved to the ideas queue.
Comment #16
aaronmchaleAlready commented on #1806514: Unify anonymous and registered users expressing my support. Definitely +1 to this.l
A few thoughts (some of which I've thought for a long time but never got around to expressing them):
So we may want to take the opportunity to consider this as part of what we think of as the base fields and data structures for the account entity type.
Comment #17
quietone commentedThe Ideas project is being deprecated. This issue is moved to the Drupal project. Check that the selected component is correct. Also, add the relevant tags, especially any 'needs manager review' tags.