1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-09-02 04:56:38 +02:00

Deploying to gh-pages from @ 12f6db3755 🚀

This commit is contained in:
robjtede
2022-03-01 04:28:45 +00:00
parent ae535d0a8a
commit 378b4c17ba
4 changed files with 38 additions and 48 deletions

View File

@@ -165,9 +165,6 @@
<span id="160">160</span>
<span id="161">161</span>
<span id="162">162</span>
<span id="163">163</span>
<span id="164">164</span>
<span id="165">165</span>
</pre><pre class="rust"><code><span class="doccomment">//! Opinionated request identity service for Actix Web apps.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! [`IdentityService`] middleware can be used with different policies types to store</span>
@@ -177,7 +174,7 @@
<span class="doccomment">//!</span>
<span class="doccomment">//! To access current request identity, use the [`Identity`] extractor.</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! ```no_run</span>
<span class="doccomment">//! ```</span>
<span class="doccomment">//! use actix_web::*;</span>
<span class="doccomment">//! use actix_identity::{Identity, CookieIdentityPolicy, IdentityService};</span>
<span class="doccomment">//!</span>
@@ -193,33 +190,30 @@
<span class="doccomment">//!</span>
<span class="doccomment">//! #[post(&quot;/login&quot;)]</span>
<span class="doccomment">//! async fn login(id: Identity) -&gt; HttpResponse {</span>
<span class="doccomment">//! id.remember(&quot;User1&quot;.to_owned()); // &lt;- remember identity</span>
<span class="doccomment">//! // remember identity</span>
<span class="doccomment">//! id.remember(&quot;User1&quot;.to_owned());</span>
<span class="doccomment">//! HttpResponse::Ok().finish()</span>
<span class="doccomment">//! }</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! #[post(&quot;/logout&quot;)]</span>
<span class="doccomment">//! async fn logout(id: Identity) -&gt; HttpResponse {</span>
<span class="doccomment">//! id.forget(); // &lt;- remove identity</span>
<span class="doccomment">//! // remove identity</span>
<span class="doccomment">//! id.forget();</span>
<span class="doccomment">//! HttpResponse::Ok().finish()</span>
<span class="doccomment">//! }</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! #[actix_web::main]</span>
<span class="doccomment">//! async fn main() -&gt; std::io::Result&lt;()&gt; {</span>
<span class="doccomment">//! HttpServer::new(move || {</span>
<span class="doccomment">//! // create cookie identity backend</span>
<span class="doccomment">//! let policy = CookieIdentityPolicy::new(&amp;[0; 32])</span>
<span class="doccomment">//! .name(&quot;auth-cookie&quot;)</span>
<span class="doccomment">//! .secure(false);</span>
<span class="doccomment">//! HttpServer::new(move || {</span>
<span class="doccomment">//! // create cookie identity backend (inside closure, since policy is not Clone)</span>
<span class="doccomment">//! let policy = CookieIdentityPolicy::new(&amp;[0; 32])</span>
<span class="doccomment">//! .name(&quot;auth-cookie&quot;)</span>
<span class="doccomment">//! .secure(false);</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! App::new()</span>
<span class="doccomment">//! // wrap policy into middleware identity middleware</span>
<span class="doccomment">//! .wrap(IdentityService::new(policy))</span>
<span class="doccomment">//! .service(services![index, login, logout])</span>
<span class="doccomment">//! })</span>
<span class="doccomment">//! .bind((&quot;0.0.0.0&quot;, 8080u16))?</span>
<span class="doccomment">//! .run()</span>
<span class="doccomment">//! .await</span>
<span class="doccomment">//! }</span>
<span class="doccomment">//! App::new()</span>
<span class="doccomment">//! // wrap policy into middleware identity middleware</span>
<span class="doccomment">//! .wrap(IdentityService::new(policy))</span>
<span class="doccomment">//! .service(services![index, login, logout])</span>
<span class="doccomment">//! })</span>
<span class="doccomment">//! # ;</span>
<span class="doccomment">//! ```</span>
<span class="attribute">#![<span class="ident">deny</span>(<span class="ident">rust_2018_idioms</span>, <span class="ident">nonstandard_style</span>)]</span>