shield/actions/
sign_out.rs1use async_trait::async_trait;
2
3use crate::{
4 action::Action,
5 error::ShieldError,
6 form::{Form, Input, InputType, InputTypeSubmit, InputValue},
7 request::{Request, RequestMethod},
8 response::{Response, ResponseType},
9 session::{BaseSession, SessionAction},
10};
11
12const ACTION_ID: &str = "sign-out";
13const ACTION_NAME: &str = "Sign out";
14
15pub struct SignOutAction;
16
17#[async_trait]
18impl Action for SignOutAction {
19 fn id(&self) -> &'static str {
20 ACTION_ID
21 }
22
23 fn name(&self) -> &'static str {
24 ACTION_NAME
25 }
26
27 fn openapi_summary(&self) -> &'static str {
28 "Sign out"
29 }
30
31 fn openapi_description(&self) -> &'static str {
32 "Sign out."
33 }
34
35 fn method(&self) -> RequestMethod {
36 RequestMethod::Post
37 }
38
39 async fn forms(&self) -> Result<Vec<Form>, ShieldError> {
40 Ok(vec![Form {
41 inputs: vec![Input {
42 name: "submit".to_owned(),
43 label: None,
44 r#type: InputType::Submit(InputTypeSubmit {}),
45 value: Some(InputValue::String {
46 value: self.name().to_owned(),
47 }),
48 addon_start: None,
49 addon_end: None,
50 }],
51 }])
52 }
53
54 async fn call(
55 &self,
56 _session: &BaseSession,
57 _request: Request,
58 ) -> Result<Response, ShieldError> {
59 Ok(Response::new(ResponseType::Default).session_action(SessionAction::Unauthenticate))
60 }
61}