forked from Ruderverein-Donau-Linz/rowt
		
	no funny business w/ get params
This commit is contained in:
		@@ -30,6 +30,7 @@ use crate::{
 | 
			
		||||
    },
 | 
			
		||||
    SCHECKBUCH,
 | 
			
		||||
};
 | 
			
		||||
use base64::alphabet::STANDARD;
 | 
			
		||||
 | 
			
		||||
pub(crate) mod admin;
 | 
			
		||||
mod auth;
 | 
			
		||||
@@ -136,35 +137,35 @@ impl<'r> FromRequest<'r> for BasicAuth {
 | 
			
		||||
        // Get the Authorization header
 | 
			
		||||
        let auth_header = match request.headers().get_one("Authorization") {
 | 
			
		||||
            Some(h) => h,
 | 
			
		||||
            None => return Outcome::Failure((Status::Unauthorized, ())),
 | 
			
		||||
            None => return Outcome::Error((Status::Unauthorized, ())),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        // Check if it's a Basic auth header
 | 
			
		||||
        if !auth_header.starts_with("Basic ") {
 | 
			
		||||
            return Outcome::Failure((Status::Unauthorized, ()));
 | 
			
		||||
            return Outcome::Error((Status::Unauthorized, ()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Decode the base64 credentials
 | 
			
		||||
        let credentials = match BASE64.decode(auth_header[6..].as_bytes()) {
 | 
			
		||||
        let credentials = match base64::decode(&auth_header[6..]) {
 | 
			
		||||
            Ok(c) => c,
 | 
			
		||||
            Err(_) => return Outcome::Failure((Status::Unauthorized, ())),
 | 
			
		||||
            Err(_) => return Outcome::Error((Status::Unauthorized, ())),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        // Convert to UTF-8 string
 | 
			
		||||
        let credentials_str = match str::from_utf8(&credentials) {
 | 
			
		||||
        let credentials_str = match std::str::from_utf8(&credentials) {
 | 
			
		||||
            Ok(s) => s,
 | 
			
		||||
            Err(_) => return Outcome::Failure((Status::Unauthorized, ())),
 | 
			
		||||
            Err(_) => return Outcome::Error((Status::Unauthorized, ())),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        // Split into username and password
 | 
			
		||||
        let mut parts = credentials_str.splitn(2, ':');
 | 
			
		||||
        let username = match parts.next() {
 | 
			
		||||
            Some(u) => u.to_string(),
 | 
			
		||||
            None => return Outcome::Failure((Status::Unauthorized, ())),
 | 
			
		||||
            None => return Outcome::Error((Status::Unauthorized, ())),
 | 
			
		||||
        };
 | 
			
		||||
        let password = match parts.next() {
 | 
			
		||||
            Some(p) => p.to_string(),
 | 
			
		||||
            None => return Outcome::Failure((Status::Unauthorized, ())),
 | 
			
		||||
            None => return Outcome::Error((Status::Unauthorized, ())),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        Outcome::Success(BasicAuth { username, password })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user