mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Check client tokens
This commit is contained in:
@ -20,7 +20,7 @@ pub fn get_client(name: &str, token: &str) -> ResultBoxError<APIClient> {
|
||||
id: res.get_int64("id")? as u32,
|
||||
name: res.get_str("service_name")?,
|
||||
token: res.get_str("token")?,
|
||||
domain: res.get_optional_str("domain")?,
|
||||
domain: res.get_optional_str("client_domain")?,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
@ -3,11 +3,11 @@ use std::error::Error;
|
||||
use std::ops::Add;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use mysql::{Binary, Pool, ResultSet};
|
||||
use mysql::{Binary, Pool, ResultSet, Value};
|
||||
use mysql::prelude::Queryable;
|
||||
|
||||
use crate::data::config::DatabaseConfig;
|
||||
use crate::data::error::ExecError;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
|
||||
/// Database access helper
|
||||
///
|
||||
@ -107,30 +107,43 @@ impl<'a> RowResult<'a> {
|
||||
}
|
||||
|
||||
/// Find an integer included in the request
|
||||
pub fn get_int64(&self, name: &str) -> Result<i64, ExecError> {
|
||||
let value: Option<i64> = self.row.get(self.find_col(name)?);
|
||||
pub fn get_int64(&self, name: &str) -> Result<i64, Box<dyn Error>> {
|
||||
let value = self.row.get_opt(self.find_col(name)?);
|
||||
|
||||
match value {
|
||||
None => Err(ExecError(format!("Could not extract integer field {} !", name))),
|
||||
Some(s) => Ok(s)
|
||||
None => Err(ExecError::boxed_string(
|
||||
format!("Could not extract integer field {} !", name))),
|
||||
Some(s) => Ok(s?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Find a string included in the request
|
||||
pub fn get_str(&self, name: &str) -> Result<String, ExecError> {
|
||||
let value: Option<String> = self.row.get(self.find_col(name)?);
|
||||
pub fn get_str(&self, name: &str) -> Result<String, Box<dyn Error>> {
|
||||
let value = self.row.get_opt(self.find_col(name)?);
|
||||
|
||||
match value {
|
||||
None => Err(ExecError(format!("Could not extract string field {} !", name))),
|
||||
Some(s) => Ok(s)
|
||||
None => Err(ExecError::boxed_string(
|
||||
format!("Could not extract string field {} !", name))),
|
||||
Some(s) => Ok(s?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an optional string
|
||||
pub fn get_optional_str(&self, name: &str) -> Result<Option<String>, ExecError> {
|
||||
match self.find_col(name) {
|
||||
Ok(col) => Ok(self.row.get(col)),
|
||||
Err(_) => Ok(None),
|
||||
/// Check out whether a given value is null or not
|
||||
pub fn is_null(&self, name: &str) -> ResultBoxError<bool> {
|
||||
let value = self.row.get_opt(self.find_col(name)?);
|
||||
|
||||
match value {
|
||||
None => Ok(true),
|
||||
Some(Ok(Value::NULL)) => Ok(true),
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an optional string => Set to None if string is null
|
||||
pub fn get_optional_str(&self, name: &str) -> ResultBoxError<Option<String>> {
|
||||
match self.is_null(name)? {
|
||||
true => Ok(None),
|
||||
false => Ok(Some(self.get_str(name)?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user