fix: username regex
This commit is contained in:
parent
bcf857d6b2
commit
1d4462fe11
1 changed files with 13 additions and 11 deletions
|
@ -19,8 +19,7 @@ static EMAIL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
Regex::new(r"[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]+)*@(?:[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?").unwrap()
|
Regex::new(r"[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]+)*@(?:[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[-A-Za-z0-9]*[A-Za-z0-9])?").unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: This regex doesnt seem to be working
|
static USERNAME_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[\w.-]+$").unwrap());
|
||||||
static USERNAME_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[a-zA-Z0-9.-_]").unwrap());
|
|
||||||
|
|
||||||
// Password is expected to be hashed using SHA3-384
|
// Password is expected to be hashed using SHA3-384
|
||||||
static PASSWORD_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[0-9a-f]{96}").unwrap());
|
static PASSWORD_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"[0-9a-f]{96}").unwrap());
|
||||||
|
@ -37,20 +36,23 @@ pub async fn check_access_token(
|
||||||
access_token: String,
|
access_token: String,
|
||||||
pool: &sqlx::Pool<Postgres>,
|
pool: &sqlx::Pool<Postgres>,
|
||||||
) -> Result<Uuid, HttpResponse> {
|
) -> Result<Uuid, HttpResponse> {
|
||||||
let row = sqlx::query_as(
|
let row =
|
||||||
"SELECT CAST(uuid as VARCHAR), created FROM access_tokens WHERE token = $1",
|
sqlx::query_as("SELECT CAST(uuid as VARCHAR), created FROM access_tokens WHERE token = $1")
|
||||||
)
|
.bind(&access_token)
|
||||||
.bind(&access_token)
|
.fetch_one(pool)
|
||||||
.fetch_one(pool)
|
.await;
|
||||||
.await;
|
|
||||||
|
|
||||||
if let Err(error) = row {
|
if let Err(error) = row {
|
||||||
if error.to_string() == "no rows returned by a query that expected to return at least one row" {
|
if error.to_string()
|
||||||
return Err(HttpResponse::Unauthorized().finish())
|
== "no rows returned by a query that expected to return at least one row"
|
||||||
|
{
|
||||||
|
return Err(HttpResponse::Unauthorized().finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
error!("{}", error);
|
error!("{}", error);
|
||||||
return Err(HttpResponse::InternalServerError().json(r#"{ "error": "Unhandled exception occured, contact the server administrator" }"#))
|
return Err(HttpResponse::InternalServerError().json(
|
||||||
|
r#"{ "error": "Unhandled exception occured, contact the server administrator" }"#,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (uuid, created): (String, i64) = row.unwrap();
|
let (uuid, created): (String, i64) = row.unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue