Fix examples

This commit is contained in:
Thomas Gideon 2017-02-14 10:51:39 -05:00
parent 29ad0d721d
commit 5e81d2fccb
3 changed files with 16 additions and 17 deletions

View file

@ -1,14 +1,15 @@
extern crate crypto;
extern crate jwt;
extern crate rustc_serialize;
// need this for custom derivation
#[macro_use]
extern crate serde_derive;
extern crate medallion;
use std::default::Default;
use jwt::{
use medallion::{
DefaultHeader,
Token,
};
#[derive(Default, RustcDecodable, RustcEncodable)]
#[derive(Default, Serialize, Deserialize)]
struct Custom {
sub: String,
rhino: bool,

View file

@ -1,8 +1,7 @@
extern crate crypto;
extern crate jwt;
extern crate medallion;
use std::default::Default;
use jwt::{
use medallion::{
DefaultHeader,
Registered,
Token,
@ -16,7 +15,7 @@ fn new_token(user_id: &str, password: &str) -> Option<String> {
let header: DefaultHeader = Default::default();
let claims = Registered {
iss: Some("mikkyang.com".into()),
iss: Some("example.com".into()),
sub: Some(user_id.into()),
..Default::default()
};
@ -36,9 +35,9 @@ fn login(token: &str) -> Option<String> {
}
fn main() {
let token = new_token("Michael Yang", "password").unwrap();
let token = new_token("Random User", "password").unwrap();
let logged_in_user = login(&*token).unwrap();
assert_eq!(logged_in_user, "Michael Yang");
assert_eq!(logged_in_user, "Random User");
}

View file

@ -1,10 +1,9 @@
extern crate crypto;
extern crate jwt;
extern crate medallion;
use std::default::Default;
use std::fs::File;
use std::io::{Error, Read};
use jwt::{
use medallion::{
Algorithm,
DefaultHeader,
Registered,
@ -29,7 +28,7 @@ fn new_token(user_id: &str, password: &str) -> Option<String> {
..Default::default()
};
let claims = Registered {
iss: Some("mikkyang.com".into()),
iss: Some("example.com".into()),
sub: Some(user_id.into()),
..Default::default()
};
@ -49,9 +48,9 @@ fn login(token: &str) -> Option<String> {
}
fn main() {
let token = new_token("Michael Yang", "password").unwrap();
let token = new_token("Random User", "password").unwrap();
let logged_in_user = login(&*token).unwrap();
assert_eq!(logged_in_user, "Michael Yang");
assert_eq!(logged_in_user, "Random User");
}