pub trait QPaladins: ToModel + CachingModel {
fn json_for_admin(&self) -> Result<String, Box<dyn Error>> { ... }
fn delete_file(
&self,
coll: &Collection,
model_name: &str,
field_name: &str,
widget_default_value: &str,
is_image: bool
) -> Result<(), Box<dyn Error>> { ... }
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<String, Box<dyn Error>> { ... }
fn calculate_thumbnail_size(
width: u32,
height: u32,
max_size: u32
) -> (u32, u32) { ... }
fn check(&self) -> Result<OutputDataForm, Box<dyn Error>> { ... }
fn save(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputDataForm, Box<dyn Error>> { ... }
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputDataForm, Box<dyn Error>> { ... }
fn create_password_hash(field_value: &str) -> Result<String, Box<dyn Error>> { ... }
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>> { ... }
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<bool, Box<dyn Error>> { ... }
}
Provided Methods
Json-line for admin panel. ( converts a widget map to a list, in the order of the Model fields )
Example:
let user_profile = UserProfile{...};
println!("{}", user_profile.json_for_admin()?);
Deleting a file in the database and in the file system.
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<String, Box<dyn Error>>
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<String, Box<dyn Error>>
Get file info from database.
Calculate the maximum size for a thumbnail.
Checking the Model before queries the database.
Example:
let user_profile = UserProfile {...}
let result = user_profile.check()?;
assert!(result.is_valid());
fn save(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputDataForm, Box<dyn Error>>
fn save(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputDataForm, Box<dyn Error>>
Save to database as a new document or update an existing document.
( Used in conjunction with the check ()
method. )
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputDataForm, Box<dyn Error>>
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputDataForm, Box<dyn Error>>
Remove document from collection.
Example:
let output_data = UserProfile.delete(None)?;
if !routput_data.is_valid() {
println!("{}", routput_data.err_msg());
}
Generate password hash and add to result document.
Example:
let user_profile = UserProfile {...};
let field_value = user_profile.password;
println!("{}", user_profile.create_password_hash(field_value)?);
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>>
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>>
Match the password from the user to the password in the database.
Example:
let user_profile = UserProfile {...};
let password = "12345678";
assert!(user_profile.create_password_hash(password, None)?);
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<bool, Box<dyn Error>>
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<bool, Box<dyn Error>>
For replace or recover password.
Example:
let user_profile = UserProfile {...};
let old_password = "12345678";
let new_password = "qBfJHCW2C9EH3_RW";
assert!(user_profile.create_password_hash(old_password, new_password, None)?);