aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/identitymanager/watch/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/identitymanager/watch/index.html')
-rw-r--r--files/zh-cn/web/api/identitymanager/watch/index.html59
1 files changed, 59 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/identitymanager/watch/index.html b/files/zh-cn/web/api/identitymanager/watch/index.html
new file mode 100644
index 0000000000..1660ccdacf
--- /dev/null
+++ b/files/zh-cn/web/api/identitymanager/watch/index.html
@@ -0,0 +1,59 @@
+---
+title: IdentityManager.watch()
+slug: Web/API/IdentityManager/watch
+translation_of: Archive/IdentityManager/watch
+---
+<p>{{ ApiRef("Persona") }}</p>
+
+<div class="note"><strong>注意:</strong> 不是所有的浏览器都支持这项功能. 使用 Persona 的网站必须在他们的页面中包含 <a href="https://login.persona.org/include.js" title="https://login.persona.org/include.js">polyfill library</a> .</div>
+
+<h3 id="Summary" name="Summary">概要</h3>
+
+<p>This function registers callbacks that respond to a <a href="/en-US/docs/BrowserID" title="BrowserID">Persona</a> user logging in or out.</p>
+
+<h3 id="Syntax" name="Syntax">语法</h3>
+
+<pre class="brush:js;">navigator.id.watch({
+ loggedInUser: 'bob@example.org',
+ onlogin: function(assertion) {
+ // A user has logged in! Here you need to:
+ // 1. Send the assertion to your backend for verification and to create a session.
+ // 2. Update your UI.
+ },
+ onlogout: function() {
+ // A user has logged out! Here you need to:
+ // Tear down the user's session by redirecting the user or making a call to your backend.
+ }
+});
+</pre>
+
+<h4 id="参数">参数</h4>
+
+<dl>
+ <dt><code>loggedInUser </code>{{ optional_inline() }}</dt>
+ <dd><strong>NOTE: </strong>This parameter was renamed from <code>loggedInEmail</code> in early September. Both names will continue to work for the time being, but code <strong>should</strong> be changed to use <code>loggedInUser</code> instead.</dd>
+ <dd>The email address of the currently logged in user. This should be a string containing the user's email address if the website believes that a user is currently logged in, or <code>null</code> otherwise. If the website is unsure, this should be set to <code>undefined</code> or omitted.</dd>
+ <dd>Persona compares its knowledge of the local user to the value of <code>loggedInUser</code> to determine which callback—<code>onlogin</code>, <code>onlogout</code>, or none at all—to automatically invoke when your page loads. If <code>loggedInUser</code> is <code>undefined</code> or omitted, Persona <em>will</em> invoke either <code>onlogin</code> or <code>onlogout</code>, depending on whether or not a local user should be logged in to your site. These callbacks are not invoked automatically if both BrowserID and <code>loggedInUser</code> agree on the local user's state.</dd>
+ <dd>Note that Persona may automatically call <em>either</em> <code>onlogin</code> or <code>onlogout</code> when your page loads, but not <em>both</em>. If <code>loggedInUser</code> is set to <code><span class="link-mailto">foo@example.com</span></code>, but Persona believes <code><span class="link-mailto">bar@example.com</span></code> should be logged in, only <code>onlogin</code> will be called. It will have an assertion for <code><span class="link-mailto">bar@example.com</span></code> as its first parameter.</dd>
+ <dt><code>onlogin</code></dt>
+ <dd>A function which will be invoked and passed a single argument, an assertion, when the user logs in. This function should send the assertion to the site's backend for verification. If verification succeeds, the backend should establish a session for the user and the function should update the UI as appropriate.</dd>
+ <dt><code>onlogout</code></dt>
+ <dd>A function that will be invoked, without any arguments, when the user logs out. This should tear down the user's session by making a call to the site's backend, or by redirecting the user.</dd>
+</dl>
+
+<h3 id="Example" name="Example">示例</h3>
+
+<p>需要示例.</p>
+
+<h3 id="Specification" name="Specification">技术规范</h3>
+
+<p>没有包含在任何技术规范中.</p>
+
+<h3 id="查看其它内容">查看其它内容</h3>
+
+<ul>
+ <li><a href="/en/BrowserID" title="BrowserID">BrowserID</a></li>
+ <li>{{domxref("navigator.id")}}</li>
+ <li>{{domxref("navigator.id.logout()")}}</li>
+ <li>{{domxref("navigator.id.request()")}}</li>
+</ul>