Skip to content

Commit

Permalink
refactor GitHub access token body
Browse files Browse the repository at this point in the history
  • Loading branch information
subhojit777 committed Jan 30, 2019
1 parent 0b34481 commit 8495f9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/github.rs
@@ -1,4 +1,5 @@
use crate::AppState;
use crate::models;
use actix_web::actix;
use actix_web::client;
use actix_web::client::ClientResponse;
Expand Down Expand Up @@ -42,7 +43,7 @@ pub fn login_redirect(
let github_client_secret =
env::var("GITHUB_CLIENT_SECRET").expect("GITHUB_CLIENT_SECRET must be set.");

let json_body = Body::new(
let json_body = models::GHAccessTokenBody::new(
github_client_id,
github_client_secret,
session_code,
Expand All @@ -59,22 +60,3 @@ pub fn login_redirect(
})
.responder()
}

#[derive(Serialize, Deserialize)]
struct Body {
client_id: String,
client_secret: String,
code: String,
accept: String,
}

impl Body {
fn new(client_id: String, client_secret: String, code: String, accept: String) -> Self {
Body {
client_id,
client_secret,
code,
accept,
}
}
}
19 changes: 19 additions & 0 deletions src/models.rs
Expand Up @@ -27,3 +27,22 @@ pub struct AnswerForm {
pub title: String,
pub user_id: i32,
}

#[derive(Serialize, Deserialize)]
pub struct GHAccessTokenBody {
client_id: String,
client_secret: String,
code: String,
accept: String,
}

impl GHAccessTokenBody {
pub fn new(client_id: String, client_secret: String, code: String, accept: String) -> Self {
GHAccessTokenBody {
client_id,
client_secret,
code,
accept,
}
}
}

0 comments on commit 8495f9f

Please sign in to comment.