upgrade validator: it now uses types! in macros!!

This commit is contained in:
Mina Galić 2020-05-24 22:03:26 +02:00
parent 0726375859
commit 07036b5fad
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
7 changed files with 24 additions and 23 deletions

22
Cargo.lock generated
View File

@ -1536,9 +1536,9 @@ dependencies = [
[[package]]
name = "if_chain"
version = "0.1.3"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bac95d9aa0624e7b78187d6fb8ab012b41d9f6f54b1bcb61e61c4845f8357ec"
checksum = "c3360c7b59e5ffa2653671fb74b4741a5d343c03f331c0a4aeda42b5c2b0ec7d"
[[package]]
name = "indexmap"
@ -3981,31 +3981,31 @@ dependencies = [
[[package]]
name = "validator"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "236a5eda3df2c877872e98dbc55d497d943792e6405d8fc65bd4f8a5e3b53c99"
checksum = "7ab5990ba09102e1ddc954d294f09b9ea00fc7831a5813bbe84bfdbcae44051e"
dependencies = [
"idna 0.1.5",
"idna 0.2.0",
"lazy_static",
"regex",
"serde",
"serde_derive",
"serde_json",
"url 1.7.2",
"url 2.1.1",
]
[[package]]
name = "validator_derive"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d360d6f5754972c0c1da14fb3d5580daa31aee566e1e45e2f8d3bf5950ecd3e9"
checksum = "e668e9cd05c5009b833833aa1147e5727b5396ea401f22dd1167618eed4a10c9"
dependencies = [
"if_chain",
"lazy_static",
"proc-macro2 0.4.30",
"quote 0.6.13",
"proc-macro2 1.0.17",
"quote 1.0.6",
"regex",
"syn 0.15.44",
"syn 1.0.23",
"validator",
]

View File

@ -31,8 +31,8 @@ serde_qs = "0.5"
shrinkwraprs = "0.2.1"
syntect = "3.3"
tokio = "0.2"
validator = "0.8"
validator_derive = "0.8"
validator = "0.10"
validator_derive = "0.10"
webfinger = { git = "https://github.com/Plume-org/webfinger", rev = "4e8f12810c4a7ba7a07bbcb722cd265fdff512b6", features = ["async"] }
[[bin]]

View File

@ -9,6 +9,7 @@ extern crate rocket;
extern crate serde_json;
#[macro_use]
extern crate validator_derive;
extern crate validator;
use clap::App;
use diesel::r2d2::ConnectionManager;

View File

@ -22,7 +22,7 @@ use plume_models::{
#[derive(Default, FromForm, Debug, Validate)]
pub struct NewCommentForm {
pub responding_to: Option<i32>,
#[validate(length(min = "1", message = "Your comment can't be empty"))]
#[validate(length(min = 1, message = "Your comment can't be empty"))]
pub content: String,
pub warning: String,
}

View File

@ -77,12 +77,12 @@ pub fn admin_mod(_mod: Moderator, rockets: PlumeRocket) -> Ructe {
#[derive(Clone, FromForm, Validate)]
pub struct InstanceSettingsForm {
#[validate(length(min = "1"))]
#[validate(length(min = 1))]
pub name: String,
pub open_registrations: bool,
pub short_description: SafeString,
pub long_description: SafeString,
#[validate(length(min = "1"))]
#[validate(length(min = 1))]
pub default_license: String,
}

View File

@ -35,9 +35,9 @@ pub fn new(m: Option<String>, rockets: PlumeRocket) -> Ructe {
#[derive(Default, FromForm, Validate)]
pub struct LoginForm {
#[validate(length(min = "1", message = "We need an email, or a username to identify you"))]
#[validate(length(min = 1, message = "We need an email, or a username to identify you"))]
pub email_or_name: String,
#[validate(length(min = "1", message = "Your password can't be empty"))]
#[validate(length(min = 1, message = "Your password can't be empty"))]
pub password: String,
}
@ -199,7 +199,7 @@ pub fn password_reset_form(token: String, rockets: PlumeRocket) -> Result<Ructe,
#[derive(FromForm, Default, Validate)]
#[validate(schema(
function = "passwords_match",
skip_on_field_errors = "false",
skip_on_field_errors = false,
message = "Passwords are not matching"
))]
pub struct NewPasswordForm {

View File

@ -455,12 +455,12 @@ pub async fn delete(
#[derive(Default, FromForm, Validate)]
#[validate(schema(
function = "passwords_match",
skip_on_field_errors = "false",
skip_on_field_errors = false,
message = "Passwords are not matching"
))]
pub struct NewUserForm {
#[validate(
length(min = "1", message = "Username can't be empty"),
length(min = 1, message = "Username can't be empty"),
custom(
function = "validate_username",
message = "User name is not allowed to contain any of < > & @ ' or \""
@ -469,9 +469,9 @@ pub struct NewUserForm {
pub username: String,
#[validate(email(message = "Invalid email"))]
pub email: String,
#[validate(length(min = "8", message = "Password should be at least 8 characters long"))]
#[validate(length(min = 8, message = "Password should be at least 8 characters long"))]
pub password: String,
#[validate(length(min = "8", message = "Password should be at least 8 characters long"))]
#[validate(length(min = 8, message = "Password should be at least 8 characters long"))]
pub password_confirmation: String,
}