Commit c75f6dfd authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Remove use of unstable library feature 'try_trait' in order to compile on stable rust again

parent 30b13029
......@@ -42,16 +42,9 @@ pub enum MedalError {
CsrfCheckFailed,
SessionTimeout,
DatabaseError,
NoneError,
PasswordHashingError,
UnmatchedPasswords,
}
// TODO: Add CsrfCheckFailed, DatabaseError
impl std::convert::From<std::option::NoneError> for MedalError {
fn from(_: std::option::NoneError) -> Self {
MedalError::NoneError
}
}
type MedalValue = (String, json_val::Map<String, json_val::Value>);
type MedalResult<T> = Result<T, MedalError>;
......@@ -509,11 +502,11 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
Ok(("profile".to_string(), data))
}
fn hash_password(password: &str, salt: &str) -> Result<String, BcryptError> {
fn hash_password(password: &str, salt: &str) -> Result<String, MedalError> {
let password_and_salt = [password, salt].concat().to_string();
match hash(password_and_salt, 5) {
Ok(result) => Ok(result),
Err(e) => Err(e)
Err(e) => Err(MedalError::PasswordHashingError)
}
}
......@@ -552,7 +545,7 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
if password != "" || password_repeat != "" {
if password == password_repeat {
let salt: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
let hash = hash_password(&password, &salt).ok()?;
let hash = hash_password(&password, &salt)?;
password_salt = Some((hash, salt));
result = ProfileStatus::password_changed;
......
#![feature(try_trait)]
#[macro_use]
extern crate iron;
#[macro_use]
......
......@@ -209,8 +209,8 @@ impl<'c, 'a, 'b> From<AugMedalError<'c, 'a, 'b>> for IronError {
functions::MedalError::DatabaseError => IronError {
error: Box::new(SessionError { message: "Database Error".to_string() }),
response: Response::with(status::Forbidden) },
functions::MedalError::NoneError => IronError {
error: Box::new(SessionError { message: "None Error".to_string() }),
functions::MedalError::PasswordHashingError => IronError {
error: Box::new(SessionError { message: "Error hashing the passwords".to_string() }),
response: Response::with(status::Forbidden) },
functions::MedalError::UnmatchedPasswords => IronError {
error: Box::new(SessionError { message: "The two passwords did not match.".to_string() }),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment