@@ -1180,7 +1180,21 @@ private UserOperationStatus ValidateUserUpdateModel(IUser existingUser, UserUpda
1180
1180
return keys ;
1181
1181
}
1182
1182
1183
+ /// <inheritdoc/>
1183
1184
public async Task < Attempt < PasswordChangedModel , UserOperationStatus > > ChangePasswordAsync ( Guid performingUserKey , ChangeUserPasswordModel model )
1185
+ {
1186
+ IServiceScope serviceScope = _serviceScopeFactory . CreateScope ( ) ;
1187
+ IBackOfficeUserStore userStore = serviceScope . ServiceProvider . GetRequiredService < IBackOfficeUserStore > ( ) ;
1188
+ IUser ? performingUser = await userStore . GetAsync ( performingUserKey ) ;
1189
+ if ( performingUser is null )
1190
+ {
1191
+ return Attempt . FailWithStatus ( UserOperationStatus . MissingUser , new PasswordChangedModel ( ) ) ;
1192
+ }
1193
+
1194
+ return await ChangePasswordAsync ( performingUser , model ) ;
1195
+ }
1196
+
1197
+ private async Task < Attempt < PasswordChangedModel , UserOperationStatus > > ChangePasswordAsync ( IUser performingUser , ChangeUserPasswordModel model )
1184
1198
{
1185
1199
IServiceScope serviceScope = _serviceScopeFactory . CreateScope ( ) ;
1186
1200
using ICoreScope scope = ScopeProvider . CreateCoreScope ( ) ;
@@ -1197,12 +1211,6 @@ public async Task<Attempt<PasswordChangedModel, UserOperationStatus>> ChangePass
1197
1211
return Attempt . FailWithStatus ( UserOperationStatus . InvalidUserType , new PasswordChangedModel ( ) ) ;
1198
1212
}
1199
1213
1200
- IUser ? performingUser = await userStore . GetAsync ( performingUserKey ) ;
1201
- if ( performingUser is null )
1202
- {
1203
- return Attempt . FailWithStatus ( UserOperationStatus . MissingUser , new PasswordChangedModel ( ) ) ;
1204
- }
1205
-
1206
1214
// require old password for self change when outside of invite or resetByToken flows
1207
1215
if ( performingUser . UserState != UserState . Invited && performingUser . Username == user . Username && string . IsNullOrEmpty ( model . OldPassword ) && string . IsNullOrEmpty ( model . ResetPasswordToken ) )
1208
1216
{
@@ -1226,12 +1234,13 @@ public async Task<Attempt<PasswordChangedModel, UserOperationStatus>> ChangePass
1226
1234
IBackOfficePasswordChanger passwordChanger = serviceScope . ServiceProvider . GetRequiredService < IBackOfficePasswordChanger > ( ) ;
1227
1235
Attempt < PasswordChangedModel ? > result = await passwordChanger . ChangeBackOfficePassword (
1228
1236
new ChangeBackOfficeUserPasswordModel
1229
- {
1230
- NewPassword = model . NewPassword ,
1231
- OldPassword = model . OldPassword ,
1232
- User = user ,
1233
- ResetPasswordToken = model . ResetPasswordToken ,
1234
- } , performingUser ) ;
1237
+ {
1238
+ NewPassword = model . NewPassword ,
1239
+ OldPassword = model . OldPassword ,
1240
+ User = user ,
1241
+ ResetPasswordToken = model . ResetPasswordToken ,
1242
+ } ,
1243
+ performingUser ) ;
1235
1244
1236
1245
if ( result . Success is false )
1237
1246
{
@@ -2184,9 +2193,26 @@ public async Task<Attempt<PasswordChangedModel, UserOperationStatus>> CreateInit
2184
2193
public async Task < Attempt < PasswordChangedModel , UserOperationStatus > > ResetPasswordAsync ( Guid userKey , string token , string password )
2185
2194
{
2186
2195
using ICoreScope scope = ScopeProvider . CreateCoreScope ( ) ;
2196
+ IServiceScope serviceScope = _serviceScopeFactory . CreateScope ( ) ;
2197
+
2198
+ EventMessages evtMsgs = EventMessagesFactory . Get ( ) ;
2199
+ IBackOfficeUserStore userStore = serviceScope . ServiceProvider . GetRequiredService < IBackOfficeUserStore > ( ) ;
2200
+
2201
+ IUser ? user = await userStore . GetAsync ( userKey ) ;
2202
+ if ( user is null )
2203
+ {
2204
+ return Attempt . FailWithStatus ( UserOperationStatus . UserNotFound , new PasswordChangedModel ( ) ) ;
2205
+ }
2206
+
2207
+ var savingNotification = new UserPasswordResettingNotification ( user , evtMsgs ) ;
2208
+ if ( await scope . Notifications . PublishCancelableAsync ( savingNotification ) )
2209
+ {
2210
+ scope . Complete ( ) ;
2211
+ return Attempt . FailWithStatus ( UserOperationStatus . CancelledByNotification , new PasswordChangedModel ( ) ) ;
2212
+ }
2187
2213
2188
2214
Attempt < PasswordChangedModel , UserOperationStatus > changePasswordAttempt =
2189
- await ChangePasswordAsync ( userKey , new ChangeUserPasswordModel
2215
+ await ChangePasswordAsync ( user , new ChangeUserPasswordModel
2190
2216
{
2191
2217
NewPassword = password ,
2192
2218
UserKey = userKey ,
0 commit comments