Skip to content

Commit

Permalink
Merge branch 'release/0.0.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
kickthedragon committed Aug 31, 2016
2 parents d5d6471 + b9d3517 commit 169dc1f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "fractal-api"
version = "0.0.9"
version = "0.0.10"
authors = [
"Iban Eguia <iban@fractal.global>",
"Eric Remigino <eric@fractal.global>",
Expand Down
38 changes: 36 additions & 2 deletions src/lib.rs
Expand Up @@ -19,13 +19,15 @@ use std::time::Duration;
use std::io::Read;

use hyper::Client as HyperClient;
use hyper::header::{Headers, Authorization, Basic, Accept, qitem, Connection, ConnectionOption};
use hyper::header::{Headers, Authorization, Basic, Accept, qitem};
use hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
use hyper::status::StatusCode;
use rustc_serialize::base64::FromBase64;
use rustc_serialize::json;
use dto::{FromDTO, UserDTO, ScopeDTO as Scope, GenerateTransactionDTO as GenerateTransaction,
LoginDTO as Login, RegisterDTO as Register, UpdateUserDTO as UpdateUser, FractalConnectionDTO as ConnectionInvitation, ConfirmPendingConnectionDTO as ConfirmConnection};
LoginDTO as Login, RegisterDTO as Register, UpdateUserDTO as UpdateUser,
FractalConnectionDTO as ConnectionInvitation, ConfirmPendingConnectionDTO as ConfirmConnection,
ResetPasswordDTO as ResetPassword};

use chrono::NaiveDate;

Expand Down Expand Up @@ -256,6 +258,38 @@ impl ClientV1 {
}
}

/// Begins a the reset password procecss
pub fn start_reset_password<S: AsRef<str>>(&self,
access_token: &AccessToken,
username: S,
email: S)
-> Result<()> {
if access_token.scopes().any(|s| s == &Scope::Public) && !access_token.has_expired() {
let mut headers = Headers::new();
headers.set(Authorization(access_token.get_token()));
let dto: ResetPassword = ResetPassword {
username: String::from(username.as_ref()),
email: String::from(email.as_ref()),
};
let response = try!(self.client
.post(&format!("{}start_reset_password", self.url))
.body(&json::encode(&dto).unwrap())
.headers(headers)
.send());
match response.status {
StatusCode::Ok => {
Ok(())
}
StatusCode::Unauthorized => Err(Error::Unauthorized),
_ => Err(Error::ServerError),
}
} else {
Err(Error::Unauthorized)
}
}



/// Registers the user
pub fn register<S: AsRef<str>>(&self,
access_token: &AccessToken,
Expand Down

0 comments on commit 169dc1f

Please sign in to comment.