1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-24 23:01:05 +03:00

WIP: Refactor higher-level data-model to its own crate

This commit is contained in:
Quentin Gliech
2021-10-12 19:03:01 +02:00
parent 29bf149921
commit b3587c677c
17 changed files with 456 additions and 326 deletions

View File

@@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use mas_data_model::BrowserSession;
use serde::Deserialize;
use sqlx::{pool::PoolConnection, PgPool, Postgres};
use sqlx::{PgPool, Postgres, Transaction};
use warp::{hyper::Uri, reply::html, Filter, Rejection, Reply};
use crate::{
@@ -22,11 +23,11 @@ use crate::{
filters::{
cookies::{encrypted_cookie_saver, EncryptedCookieSaver},
csrf::{protected_form, updated_csrf_token},
database::connection,
database::transaction,
session::session,
with_templates, CsrfToken,
},
storage::SessionInfo,
storage::{user::authenticate_session, PostgresqlBackend},
templates::{EmptyContext, TemplateContext, Templates},
};
@@ -50,7 +51,7 @@ pub(super) fn filter(
let post = warp::post()
.and(session(pool, cookies_config))
.and(connection(pool))
.and(transaction(pool))
.and(protected_form(cookies_config))
.and_then(post);
@@ -61,7 +62,7 @@ async fn get(
templates: Templates,
cookie_saver: EncryptedCookieSaver,
csrf_token: CsrfToken,
session: SessionInfo,
session: BrowserSession<PostgresqlBackend>,
) -> Result<impl Reply, Rejection> {
let ctx = EmptyContext.with_session(session).with_csrf(&csrf_token);
@@ -72,14 +73,14 @@ async fn get(
}
async fn post(
session: SessionInfo,
mut conn: PoolConnection<Postgres>,
session: BrowserSession<PostgresqlBackend>,
mut txn: Transaction<'_, Postgres>,
form: ReauthForm,
) -> Result<impl Reply, Rejection> {
let _session = session
.reauth(&mut conn, form.password)
authenticate_session(&mut txn, &session, form.password)
.await
.wrap_error()?;
txn.commit().await.wrap_error()?;
Ok(warp::redirect(Uri::from_static("/")))
}