Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple-auth-server added to examples #65

Merged
merged 5 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix PR to make requested changes
  • Loading branch information
mygnu committed Dec 9, 2018
commit 7b16120004484024343a55209c51b1c105adaafc
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# intellij files
.idea/**
68 changes: 34 additions & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@ before_script:

script:
- |
cd async_db && cargo check && cd ..
cd async_ex1 && cargo check && cd ..
cd actix_redis && cargo check && cd ..
cd actix_todo && cargo check && cd ..
cd basics && cargo check && cd ..
cd cookie-auth && cargo check && cd ..
cd cookie-auth-full && cargo check && cd ..
cd cookie-session && cargo check && cd ..
cd diesel && cargo check && cd ..
cd error_handling && cargo check && cd ..
cd form && cargo check && cd ..
cd hello-world && cargo check && cd ..
cd http-proxy && cargo check && cd ..
cd http-full-proxy && cargo check && cd ..
cd json && cargo check && cd ..
cd juniper && cargo check && cd ..
cd middleware && cargo check && cd ..
cd multipart && cargo check && cd ..
cd protobuf && cargo check && cd ..
cd r2d2 && cargo check && cd ..
cd redis-session && cargo check && cd ..
cd simple-auth-sarver && cargo check && cd ..
cd state && cargo check && cd ..
cd static_index && cargo check && cd ..
cd template_askama && cargo check && cd ..
cd template_tera && cargo check && cd ..
cd tls && cargo check && cd ..
cd rustls && cargo check && cd ..
cd unix-socket && cargo check && cd ..
cd web-cors/backend && cargo check && cd ../..
cd websocket && cargo check && cd ..
cd websocket-chat && cargo check && cd ..
cd websocket-chat-broker && cargo check && cd ..
cd websocket-tcp-chat && cargo check && cd ..
cd async_db && cargo check && cd ..
cd async_ex1 && cargo check && cd ..
cd actix_redis && cargo check && cd ..
cd actix_todo && cargo check && cd ..
cd basics && cargo check && cd ..
cd cookie-auth && cargo check && cd ..
cd cookie-auth-full && cargo check && cd ..
cd cookie-session && cargo check && cd ..
cd diesel && cargo check && cd ..
cd error_handling && cargo check && cd ..
cd form && cargo check && cd ..
cd hello-world && cargo check && cd ..
cd http-proxy && cargo check && cd ..
cd http-full-proxy && cargo check && cd ..
cd json && cargo check && cd ..
cd juniper && cargo check && cd ..
cd middleware && cargo check && cd ..
cd multipart && cargo check && cd ..
cd protobuf && cargo check && cd ..
cd r2d2 && cargo check && cd ..
cd redis-session && cargo check && cd ..
cd simple-auth-sarver && cargo check && cd ..
cd state && cargo check && cd ..
cd static_index && cargo check && cd ..
cd template_askama && cargo check && cd ..
cd template_tera && cargo check && cd ..
cd tls && cargo check && cd ..
cd rustls && cargo check && cd ..
cd unix-socket && cargo check && cd ..
cd web-cors/backend && cargo check && cd ../..
cd websocket && cargo check && cd ..
cd websocket-chat && cargo check && cd ..
cd websocket-chat-broker && cargo check && cd ..
cd websocket-tcp-chat && cargo check && cd ..
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"protobuf",
"r2d2",
"redis-session",
"simple-auth-server",
"state",
"static_index",
"template_askama",
Expand Down
165 changes: 0 additions & 165 deletions simple-auth-server/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions simple-auth-server/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
##### What?

We are going to create a web-server in `rust` that only deals with user registration and authentication. I will be explaining the steps in each file as we go. The complete project code is here [repo](https://gitlab.com/mygnu/rust-auth-server/tree). Please take all this with a pinch of salt as I'm a still a noob to rust 😉.

##### Flow of the event would look like this:

- Registers with email address ➡ Receive an 📨 with a link to verify
Expand All @@ -27,13 +23,10 @@ We are going to create a web-server in `rust` that only deals with user registra
- [sparkpost](https://crates.io/crates/sparkpost) // Rust bindings for sparkpost email api v1.
- [uuid](https://crates.io/crates/uuid) // A library to generate and parse UUIDs.

I have provided a brief info about the crates in use from their official description. If you want to know more about any of these crates please click on the name to go to `crates.io`.
**Shameless plug:** `sparkpost` is my crate please leave feedback if you like/dislike it.

Read the full tutorial series on [hgill.io](https://hgill.io)

- [Auth Web Microservice with rust using Actix-Web - Complete Tutorial Part 1](https://hgill.io/posts/auth-microservice-rust-actix-web-diesel-complete-tutorial-part-1/)
- [Auth Web Microservice with rust using Actix-Web - Complete Tutorial Part 2](https://hgill.io/posts/auth-microservice-rust-actix-web-diesel-complete-tutorial-part-2/)
- [Auth Web Microservice with rust using Actix-Web - Complete Tutorial Part 3](https://hgill.io/posts/auth-microservice-rust-actix-web-diesel-complete-tutorial-part-3/)

TODO: User Login frontend page
7 changes: 5 additions & 2 deletions simple-auth-server/src/auth_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ impl Message for AuthData {
type Result = Result<SlimUser, ServiceError>;
}

mygnu marked this conversation as resolved.
Show resolved Hide resolved

impl Handler<AuthData> for DbExecutor {
type Result = Result<SlimUser, ServiceError>;
fn handle(&mut self, msg: AuthData, _: &mut Self::Context) -> Self::Result {
Expand All @@ -31,7 +30,11 @@ impl Handler<AuthData> for DbExecutor {
if let Some(user) = items.pop() {
match verify(&msg.password, &user.password) {
Ok(matching) => {
if matching { return Ok(user.into()); } else { return mismatch_error; }
if matching {
return Ok(user.into());
} else {
return mismatch_error;
}
}
Err(_) => { return mismatch_error; }
}
Expand Down
5 changes: 1 addition & 4 deletions simple-auth-server/src/email_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fn get_api_key() -> String {
std::env::var("SPARKPOST_API_KEY").expect("SPARKPOST_API_KEY must be set")
}

#[allow(unused)]
pub fn send_invitation(invitation: &Invitation) {
let tm = Transmission::new_eu(get_api_key());
let sending_email =
Expand Down Expand Up @@ -50,14 +49,12 @@ pub fn send_invitation(invitation: &Invitation) {

let result = tm.send(&email);

// Note that we only print out the error response from email api
match result {
Ok(res) => {
// println!("{:?}", &res);
match res {
TransmissionResponse::ApiResponse(api_res) => {
println!("API Response: \n {:#?}", api_res);
// assert_eq!(1, api_res.total_accepted_recipients);
// assert_eq!(0, api_res.total_rejected_recipients);
}
TransmissionResponse::ApiError(errors) => {
println!("Response Errors: \n {:#?}", &errors);
Expand Down
1 change: 0 additions & 1 deletion simple-auth-server/src/register_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct RegisterUser {
pub password: String,
}

mygnu marked this conversation as resolved.
Show resolved Hide resolved

impl Message for RegisterUser {
type Result = Result<SlimUser, ServiceError>;
}
Expand Down