Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 44dcffd

Browse files
authored
chore(project): remove the validator dependency
#60 r=vladikoff
1 parent 145df00 commit 44dcffd

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/send/mod.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use std::{borrow::Cow, collections::HashMap};
6-
75
use rocket::{
86
data::{self, FromData}, http::Status, response::Failure, Data, Outcome, Request,
97
};
108
use rocket_contrib::{Json, Value};
11-
use validator::{self, Validate, ValidationError};
129

1310
use auth_db::DbClient;
1411
use bounces::Bounces;
12+
use deserialize;
1513
use providers::Providers;
1614
use settings::Settings;
1715
use validate;
@@ -32,9 +30,9 @@ struct Body {
3230
html: Option<String>,
3331
}
3432

35-
#[derive(Debug, Deserialize, Validate)]
33+
#[derive(Debug, Deserialize)]
3634
struct Email {
37-
#[validate(email)]
35+
#[serde(deserialize_with = "deserialize::email_address")]
3836
to: String,
3937
cc: Option<Vec<String>>,
4038
subject: String,
@@ -43,7 +41,7 @@ struct Email {
4341
}
4442

4543
impl FromData for Email {
46-
type Error = ValidationError;
44+
type Error = ();
4745

4846
fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> {
4947
let result = Json::<Email>::from_data(request, data);
@@ -65,7 +63,7 @@ impl FromData for Email {
6563
fn validate(email: &Email) -> bool {
6664
if let Some(ref cc) = email.cc {
6765
for address in cc {
68-
if !validator::validate_email(&address) {
66+
if !validate::email_address(&address) {
6967
return false;
7068
}
7169
}
@@ -80,15 +78,8 @@ fn validate(email: &Email) -> bool {
8078
true
8179
}
8280

83-
fn fail() -> data::Outcome<Email, ValidationError> {
84-
Outcome::Failure((
85-
Status::BadRequest,
86-
ValidationError {
87-
code: Cow::from("400"),
88-
message: None,
89-
params: HashMap::new(),
90-
},
91-
))
81+
fn fail() -> data::Outcome<Email, ()> {
82+
Outcome::Failure((Status::BadRequest, ()))
9283
}
9384

9485
#[post("/send", format = "application/json", data = "<email>")]

src/service_main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ extern crate serde;
2525
#[macro_use]
2626
extern crate serde_derive;
2727
extern crate serde_json;
28-
extern crate validator;
29-
#[macro_use]
30-
extern crate validator_derive;
3128

3229
mod app_errors;
3330
mod auth_db;

0 commit comments

Comments
 (0)