wip
This commit is contained in:
parent
7eb34b4350
commit
51d3c76460
@ -12,11 +12,9 @@ const addState = connect(
|
|||||||
} = state;
|
} = state;
|
||||||
function submitLogin(name, password) {
|
function submitLogin(name, password) {
|
||||||
postData('/login', { name, password })
|
postData('/login', { name, password })
|
||||||
.then(res => {
|
.then(res => res.json())
|
||||||
if (!res.ok) return errorToast(res);
|
.then(data => {
|
||||||
res.text()
|
if (!data.success) return errorToast(data.error_message);
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
ws.connect();
|
ws.connect();
|
||||||
})
|
})
|
||||||
.catch(error => errorToast(error));
|
.catch(error => errorToast(error));
|
||||||
|
|||||||
@ -5,9 +5,11 @@ use iron::headers::{Cookie as CookieHdr, SetCookie};
|
|||||||
use iron::prelude::*;
|
use iron::prelude::*;
|
||||||
use iron::status;
|
use iron::status;
|
||||||
use iron::typemap::Key;
|
use iron::typemap::Key;
|
||||||
|
use iron::mime::Mime;
|
||||||
use iron::{typemap, BeforeMiddleware,AfterMiddleware};
|
use iron::{typemap, BeforeMiddleware,AfterMiddleware};
|
||||||
use persistent::Read;
|
use persistent::Read;
|
||||||
use router::Router;
|
use router::Router;
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
// use warden::{warden};
|
// use warden::{warden};
|
||||||
// use pubsub::{pg_listen};
|
// use pubsub::{pg_listen};
|
||||||
@ -37,6 +39,23 @@ pub enum MnmlHttpError {
|
|||||||
InvalidCode,
|
InvalidCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct JsonResponse {
|
||||||
|
response: String,
|
||||||
|
success: bool,
|
||||||
|
error_message: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JsonResponse {
|
||||||
|
fn success(response: String) -> Self {
|
||||||
|
JsonResponse { response: response, success: true, error_message: "".to_string() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn error(msg: String) -> Self {
|
||||||
|
JsonResponse { response: "".to_string(), success: false, error_message: msg }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<MnmlHttpError> for IronError {
|
impl From<MnmlHttpError> for IronError {
|
||||||
fn from(m_err: MnmlHttpError) -> Self {
|
fn from(m_err: MnmlHttpError) -> Self {
|
||||||
let (err, res) = match m_err {
|
let (err, res) = match m_err {
|
||||||
@ -48,8 +67,11 @@ impl From<MnmlHttpError> for IronError {
|
|||||||
MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest),
|
MnmlHttpError::PasswordUnacceptable => (m_err.compat(), status::BadRequest),
|
||||||
MnmlHttpError::InvalidCode => (m_err.compat(), status::Unauthorized),
|
MnmlHttpError::InvalidCode => (m_err.compat(), status::Unauthorized),
|
||||||
};
|
};
|
||||||
|
let err_msg = JsonResponse::error("grep".to_string());
|
||||||
|
let err_out = serde_json::to_string(&err_msg).expect("Failed to encode response");
|
||||||
|
let content_type = "application/json".parse::<Mime>().expect("Failed to parse content type");
|
||||||
|
|
||||||
IronError::new(err, res)
|
IronError::new(err, (content_type, res, err_out))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user