mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-14 13:08:27 +03:00
multipart form was a bad idea
This commit is contained in:
parent
cc17f2048f
commit
6cd477e227
4 changed files with 4 additions and 86 deletions
|
@ -89,21 +89,6 @@ async fn auth_works() {
|
|||
)
|
||||
.await;
|
||||
|
||||
let resp = test::call_service(
|
||||
&mut app,
|
||||
post_request!(&creds, PAGES.auth.login).to_request(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
|
||||
|
||||
creds.username = NAME.into();
|
||||
let resp = test::call_service(
|
||||
&mut app,
|
||||
post_request!(&creds, PAGES.auth.login).to_request(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
|
||||
// 4. trying to signin with wrong password
|
||||
creds.username = NAME.into();
|
||||
creds.password = NAME.into();
|
||||
|
|
|
@ -15,37 +15,21 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use actix_identity::Identity;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use actix_web::{HttpResponse, Responder};
|
||||
use lazy_static::lazy_static;
|
||||
use my_codegen::get;
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
use crate::api::v1::auth::runners;
|
||||
use crate::pages::errors::Errorable;
|
||||
use crate::AppData;
|
||||
use crate::PAGES;
|
||||
|
||||
#[derive(Clone, TemplateOnce)]
|
||||
#[template(path = "auth/login/index.html")]
|
||||
struct IndexPage {
|
||||
username: Option<String>,
|
||||
password: Option<String>,
|
||||
error: Option<String>,
|
||||
}
|
||||
|
||||
crate::ImplErrorable!(IndexPage);
|
||||
|
||||
struct IndexPage;
|
||||
const PAGE: &str = "Login";
|
||||
|
||||
impl Default for IndexPage {
|
||||
fn default() -> Self {
|
||||
IndexPage {
|
||||
username: None,
|
||||
password: None,
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
IndexPage }
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
|
@ -58,28 +42,3 @@ pub async fn login() -> impl Responder {
|
|||
.content_type("text/html; charset=utf-8")
|
||||
.body(&*INDEX)
|
||||
}
|
||||
#[my_codegen::post(path = "PAGES.auth.login")]
|
||||
async fn login_post(
|
||||
id: Identity,
|
||||
payload: web::Json<runners::Login>,
|
||||
data: AppData,
|
||||
) -> impl Responder {
|
||||
match runners::login_runner(&payload, &data).await {
|
||||
Ok(_) => {
|
||||
id.remember(payload.into_inner().username);
|
||||
HttpResponse::Ok().into()
|
||||
}
|
||||
Err(e) => {
|
||||
let payload = payload.into_inner();
|
||||
let username = Some(payload.username);
|
||||
let password = Some(payload.password);
|
||||
|
||||
let page = IndexPage {
|
||||
username,
|
||||
password,
|
||||
..Default::default()
|
||||
};
|
||||
page.get_error_resp(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ pub mod register;
|
|||
|
||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(login::login);
|
||||
cfg.service(login::login_post);
|
||||
cfg.service(register::join);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,37 +13,12 @@
|
|||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
use actix_web::{error::ResponseError, web, HttpResponse, Responder};
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use lazy_static::lazy_static;
|
||||
use sailfish::TemplateOnce;
|
||||
|
||||
use crate::errors::PageError;
|
||||
|
||||
pub trait Errorable: TemplateOnce {
|
||||
fn get_error_resp<E: ResponseError>(self, e: E) -> HttpResponse;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! ImplErrorable {
|
||||
($struct:ident) => {
|
||||
impl crate::pages::errors::Errorable for $struct {
|
||||
fn get_error_resp<E>(mut self, e: E) -> actix_web::HttpResponse
|
||||
where
|
||||
E: actix_web::error::ResponseError + std::fmt::Display,
|
||||
//R: actix_web::Responder
|
||||
{
|
||||
self.error = Some(e.to_string());
|
||||
let page = self.render_once().unwrap();
|
||||
println!("status code: {}", e.status_code());
|
||||
actix_web::dev::HttpResponseBuilder::new(e.status_code())
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(&page)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, TemplateOnce)]
|
||||
#[template(path = "errors/index.html")]
|
||||
struct ErrorPage<'a> {
|
||||
|
|
Loading…
Add table
Reference in a new issue