add code to require authentication for 2 controllers functions (2 different syntax)
This commit is contained in:
parent
ee1a27bb8d
commit
d1102dcf8b
2 changed files with 8 additions and 0 deletions
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
models::_entities::servers::{ActiveModel, Column, Entity, Model},
|
models::_entities::servers::{ActiveModel, Column, Entity, Model},
|
||||||
views,
|
views,
|
||||||
};
|
};
|
||||||
|
use crate::models::users;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
|
@ -31,9 +32,14 @@ async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn list(
|
pub async fn list(
|
||||||
|
auth: auth::JWT,
|
||||||
ViewEngine(v): ViewEngine<TeraView>,
|
ViewEngine(v): ViewEngine<TeraView>,
|
||||||
State(ctx): State<AppContext>,
|
State(ctx): State<AppContext>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
|
// we only want to make sure user exists, so we name the variable
|
||||||
|
// with a `_` in front to remove the warning about unused variable
|
||||||
|
let _current_user = users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;
|
||||||
|
|
||||||
let item = Entity::find()
|
let item = Entity::find()
|
||||||
.order_by(Column::Id, Order::Desc)
|
.order_by(Column::Id, Order::Desc)
|
||||||
.all(&ctx.db)
|
.all(&ctx.db)
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
models::_entities::services::{ActiveModel, Column, Entity, Model},
|
models::_entities::services::{ActiveModel, Column, Entity, Model},
|
||||||
views,
|
views,
|
||||||
};
|
};
|
||||||
|
use crate::models::users;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
|
@ -33,6 +34,7 @@ async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn list(
|
pub async fn list(
|
||||||
|
_user: auth::ApiToken<users::Model>,
|
||||||
ViewEngine(v): ViewEngine<TeraView>,
|
ViewEngine(v): ViewEngine<TeraView>,
|
||||||
State(ctx): State<AppContext>,
|
State(ctx): State<AppContext>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
|
|
Loading…
Reference in a new issue