Created
March 16, 2017 13:20
-
-
Save goyox86/cdd16fa761030cf08d8862cae1d80399 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Serialize, Deserialize, Insertable)] | |
#[table_name="users"] | |
pub struct NewUser { | |
pub name: String, | |
pub username: String, | |
pub email: String, | |
#[serde(rename(deserialize = "password"))] | |
#[serde(deserialize_with = "hash_user_password")] | |
pub hashed_password: String | |
} | |
fn hash_user_password<D>(deserializer: D) -> Result<String, D::Error> | |
where D: Deserializer | |
{ | |
let password: String = Deserialize::deserialize(deserializer)?; | |
hash(&password, DEFAULT_COST) | |
.map_err(de::Error::custom) | |
.map(|hashed_password|hashed_password) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment