On 04/06/2013 17:58, Sean McArthur wrote:
> [+ some folks in webdev that use Persona]
>
> This sounds like the right goal. Some people will enjoy not having to
> manage state, but existing websites really have trouble with the current
> watch().
>
> I had some similar conversations with mkelly, and I experimented in this
> gist based on his feedback:
https://gist.github.com/seanmonstar/5561248
TLDR; I am laying out the use cases, as well as the problems I am
running in to, while using the .watch API with the Wordpress Persona
plugin. If you don't care about the gory details, skip this email.
=========================================
Sean, this is the first I have seen these ideas, I like where they are
going.Can the same functionality (minus the promises) be retrofitted
into the current .watch/.request API via additional parameters?
I am going to lay out in detail the use cases I have recently run up
against in the Wordpress plugin. The Wordpress plugin is probably a
unique in that sometimes Persona is used to sign a user up/in to the
site as a member, at other times it is used as a quick way to verify an
email addresses when a visitor want to leave a comment. We want both of
these sets of functionality to exist together, at the same time.
Sometimes we want full on session handling. At other times we want a one
time assertion.
Use case - user sign in
1) Users: Existing Persona users *or* new users signing in with an IdP
backed address.
Desired Behavior: User never leaves dialog, completes sign in in
same tab they start in. No problem here.
Existing Behavior: Same as existing behavior.
2) Users: User who must verify their email address with Persona.
Desired Behavior: User verifies their email address with Persona, is
redirected back to Wordpress,
is signed in, and are redirected to their profile page.
Existing Behavior: The same as existing behavior.
Use case - user signup
Because of my own lack of understanding of how Wordpress fits together,
I am trying to use already existing facilities and retrofit Persona on
top of it. This means I ask for a username first, verify the user using
Persona, and then submit the new user form. If I knew how to stage the
info on the back end until verification, this would be *much* easier,
but, I do not. We do not have the ability to hotpatch Core Wordpress
files to add needed functionality, and we do not want to change too much
existing behavior and risk collisions with other plugins or long term
diversion from core Wordpress functionality.
1) Users: Existing Persona users *or* new users signing in with an IdP
backed address.
Desired Behavior: User fills out new username, clicks "sign in with
Persona."
The user verifies with Persona, the registration form is
submitted, and a new account is created.
Existing Behavior: Same as desired behavior.
2) Users: User who must verify their email address with Persona.
a) Verification Method: User verifies in same tab by replacing
currently existing window.
Desired Behavior: redirect user to sign up page, re-load
previously saved new user state, submit form.
Existing Behavior: same as desired, using localStorage to
re-load previously filled out state.
b) Verification Method: User verifies in a different tab while
keeping original tab open.
User's original page is Tab A. User verifies in Tab B.
Desired Behavior: User opens new tab to verify with Persona, is
then redirected to the
signup page where the new user form is submitted, IFF there
is an error (like the
user name is already taken), show the error. Otherwise, the
user is redirected to
their profile page where they can fill out additional
profile information. Tab A
does nothing. It finds out that Tab B was opened and stands
down. If it takes any
action, it should redirect to the profile page when Tab B
completes registration.
Existing Behavior: This is a nightmare. We don't know which tab
will receive its assertion
first. Sometimes it is Tab A, sometimes it is Tab B. We
always want Tab B to show any
registration errors because the user is at Tab B. To try to
do this, before the user
opens the Persona dialog, we save all sign up state to
localStorage. Since we have no
way of definitively knowing by time Tab A receives its
assertion whether Tab B has
been opened (like case 2A), the first tab to receive the
assertion adds the assertion
to the signup form and submits. The second tab to receive
its assertion busy waits
for a "I'm done" or "Houston, there was a problem!" signal
from the tab that
submitted the form. If there was a problem, for example, if
the username is already
registered, both tabs show the error.
For both Sign Up and Sign In, we want Persona to have a hand in managing
sessions after the user signs in.
For commenting though, this is not the case. We only want an assertion
so the user can submit a comment. We cannot mix .get and .watch on the
same page. We have to jump through additional hoops.
Use case - visitors who leave a comment
Unlike new user sign up, it does not make sense to consider having the
user verify their email address first and then ask them to leave a comment.
1) Users: Existing Persona users *or* new users signing in with an IdP
backed address.
Desired Behavior: User fills out comment, clicks "sign in with
Persona."
The user verifies with Persona, the comment form is submitted,
no session is created.
The user is not marked as "signed in to this site" with Persona.
Existing Behavior: Same as desired behavior, but doing this with
.watch is a pain. Remember .watch
is registered on every page to handle normal member sign ins. If
the user leaves a comment and
is not signed in to the site as a member, when .onlogin is
called, we have to immediately
call navigator.id.logout() to prevent the .onlogin callback from
being fired on every subsequent
page the user visits.
2) Users: User who must verify their email address with Persona.
a) Verification Method: User verifies in same tab by replacing
currently existing window.
Desired Behavior: User fills out comment, clicks "sign in
with Persona."
The user verifies with Persona, the previous state of
the comment form is re-loaded,
submitted, no session is created. The user is not marked
as "signed in to this site"
with Persona.
Existing Behavior: Matches desired behavior by saving form
state to localStorage.
b) Verification Method: User verifies in a different tab while
keeping original tab open.
Desired Outcome: User opens new tab to verify with Persona,
is then redirected to the
comment page where the comment form is submitted, IFF there
is an error (like the
comment already exists), show the error. Otherwise, the
user is redirected to
their new comment. Tab A does nothing. It finds out that
Tab B was opened and
stands down. If Tab A takes any action, it should redirect
to the new comment once
Tab B completes submission.
Existing Behavior: All of the same nightmares as "User Sign
Up:2b" with the additional
caveat that user is not marked as "signed in to this
site" with Persona.
===================================================
Remedies to what is ailing me.
I want to be able to use .watch and .get like functionality at the same
time. .watch for session management of members. .get for visitors who
leave comments.
Potential Solutions:
* add a "no_session" flag to .request.
* Allow .get and .watch to co-exist.
I also want a way for users who verify in Tab B to notify Tab A that
their onlogin should be ignored. Maybe this
is of the form of a new parameter when calling .watch or .request, or
perhaps an additional field when returning the assertion that says "user
verified in another window and is going to be redirected". I want this
to work whether Tab A or Tab B receives its assertion first.
We keep saying that BigTent is going to remedy loads of these problems
for the majority of users, and it will. But, for the 30% of the users
not covered under BigTent who do not yet have a Persona account, I still
want the plugin's UX to be awesome. I don't want them to have to create
a Persona account and then re-submit their comment. I don't want them to
have to create a Persona account and then have to re-submit the
authentication form. And I don't want to rewrite large portions of the
Wordpress core logic to stage data and then fully submit it once the
user verifies.
Goodness.
Shane