Skip to content

Commit 6b17b13

Browse files
committed
logout curl
1 parent e3a5bea commit 6b17b13

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ curl -X POST -H 'Content-Type: application/json' -i 'http://127.0.0.1:8000/api/a
103103
}
104104
```
105105
106+
### `POST /api/auth/login`: Logout
107+
```bash
108+
curl -X POST -H 'Content-Type: application/json' -H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzcyNTc4NzksImV4cCI6MTU3Nzg2MjY3OSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiYzUxNWE3NTg3NGYzNGVjNGFmNDJmNWE2M2QxMDVjMGYifQ.B9w6FxFdypb5GCRMKXZ9CZWFxQLFjvmPSusMCtcE-Ac' -i 'http://127.0.0.1:8000/api/auth/logout'
109+
```
110+
106111
### `GET /api/address-book`: Get all people information
107112
```
108113
curl -X GET -H 'Content-Type: application/json' -H 'Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzU4NzM4MjksImV4cCI6MTU3NjQ3ODYyOSwidXNlciI6ImMiLCJsb2dpbl9zZXNzaW9uIjoiZjU5N2M3MTIxZTExNDBhMGE0ZjE0YmQ4N2NjM2Q4MWUifQ.6qppDfRgOw45eExJ7MUEwpcu3AUXXe9_ifj_mp7k22k' -i 'http://127.0.0.1:8000/api/address-book'

log4rs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ appenders:
88
encoder:
99
pattern: "{d} - {m}{n}"
1010
root:
11-
level: info
11+
level: debug
1212
appenders:
1313
- requests
1414
- stdout

migrations/2019-02-20-054109_create_login_history_table/up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
CREATE TABLE login_history
33
(
44
id SERIAL PRIMARY KEY NOT NULL,
5-
user_id BIGINT NOT NULL REFERENCES users(id),
5+
user_id INTEGER NOT NULL REFERENCES users(id),
66
login_timestamp TIMESTAMP WITH TIME ZONE NOT NULL
7-
);
7+
);

src/api/account_controller.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub fn login(login_dto: web::Json<LoginDTO>, pool: web::Data<Pool>) -> impl Futu
2828

2929
// POST api/auth/logout
3030
pub fn logout(req: HttpRequest, pool: web::Data<Pool>) -> impl Future<Item = HttpResponse, Error = Error> {
31+
debug!("{:?}",req);
3132
if let Some(authen_header) = req.headers().get(constants::AUTHORIZATION) {
3233
account_service::logout(authen_header, &pool);
3334
ok(HttpResponse::Ok().json(ResponseBody::new(constants::MESSAGE_LOGOUT_SUCCESS, constants::EMPTY)))

src/middleware/authen_middleware.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use futures::{
1313
Poll,
1414
future::{ok, Either, FutureResult},
1515
};
16+
use actix_web::http::header::{HeaderName, HeaderValue};
1617

1718
pub struct Authentication;
1819

@@ -52,7 +53,16 @@ where
5253

5354
fn call(&mut self, mut req: ServiceRequest) -> Self::Future {
5455
// Bypass some account routes
56+
debug!("{:?}",req.head_mut().headers());
57+
let headers = req.headers_mut();
58+
headers.append(HeaderName::from_static("content-length"),HeaderValue::from_static("true"));
59+
// let (r, pl) = req.into_parts();
60+
// debug!("{:?}",&r);
61+
// debug!("{:?}",pl);
62+
// let req2 = ServiceRequest::from_parts(r, pl);
63+
// assert!(ServiceRequest::from_parts(r, pl).is_ok());
5564
for ignore_route in constants::IGNORE_ROUTES.iter() {
65+
debug!("route:{}",ignore_route);
5666
if req.path().starts_with(ignore_route) {
5767
return Either::A(self.service.call(req));
5868
}

src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ allow_tables_to_appear_in_same_query!(
3434
login_history,
3535
people,
3636
users,
37-
);
37+
);

0 commit comments

Comments
 (0)