@@ -32,7 +32,6 @@ use crate::services::session::{
3232 CreateSession , GetOtherSessions , GetOtherSessionsOutput , InvalidateOtherSessions ,
3333 RenewSession ,
3434} ;
35- use crate :: services:: user:: GetUser ;
3635
3736pub async fn auth_login (
3837 ctx : & ServiceContext < ' _ > ,
@@ -208,9 +207,16 @@ pub async fn auth_mfa_setup(
208207 ctx : & ServiceContext < ' _ > ,
209208 params : Params < ' static > ,
210209) -> Result < MultiFactorSetupOutput > {
211- let GetUser { user : reference } = params. parse ( ) ?;
212- let user = UserService :: get ( ctx, reference) . await ?;
213- MfaService :: setup ( ctx, & user) . await
210+ let MultiFactorConfigure {
211+ user_id,
212+ session_token,
213+ ip_address,
214+ } = params. parse ( ) ?;
215+
216+ let user =
217+ SessionService :: get_user_with_id ( ctx, & session_token, false , user_id) . await ?;
218+
219+ MfaService :: setup ( ctx, & user, ip_address) . await
214220}
215221
216222pub async fn auth_mfa_disable (
@@ -220,22 +226,13 @@ pub async fn auth_mfa_disable(
220226 let MultiFactorConfigure {
221227 user_id,
222228 session_token,
229+ ip_address,
223230 } = params. parse ( ) ?;
224231
225- let user = SessionService :: get_user ( ctx, & session_token, false ) . await ?;
226- if user. user_id != user_id {
227- error ! (
228- "Passed user ID ({}) does not match session token ({})" ,
229- user_id, user. user_id,
230- ) ;
231-
232- return Err ( Error :: SessionUserId {
233- active_user_id : user_id,
234- session_user_id : user. user_id ,
235- } ) ;
236- }
232+ let user =
233+ SessionService :: get_user_with_id ( ctx, & session_token, false , user_id) . await ?;
237234
238- MfaService :: disable ( ctx, user. user_id ) . await
235+ MfaService :: disable ( ctx, user. user_id , ip_address ) . await
239236}
240237
241238pub async fn auth_mfa_reset_recovery (
@@ -245,20 +242,11 @@ pub async fn auth_mfa_reset_recovery(
245242 let MultiFactorConfigure {
246243 user_id,
247244 session_token,
245+ ip_address,
248246 } = params. parse ( ) ?;
249247
250- let user = SessionService :: get_user ( ctx, & session_token, false ) . await ?;
251- if user. user_id != user_id {
252- error ! (
253- "Passed user ID ({}) does not match session token ({})" ,
254- user_id, user. user_id,
255- ) ;
256-
257- return Err ( Error :: SessionUserId {
258- active_user_id : user_id,
259- session_user_id : user. user_id ,
260- } ) ;
261- }
248+ let user =
249+ SessionService :: get_user_with_id ( ctx, & session_token, false , user_id) . await ?;
262250
263- MfaService :: reset_recovery_codes ( ctx, & user) . await
251+ MfaService :: reset_recovery_codes ( ctx, & user, ip_address ) . await
264252}
0 commit comments