Skip to content

Commit

Permalink
Issue-5308 - Change Password page invalid password status code update
Browse files Browse the repository at this point in the history
  • Loading branch information
berkarslan-xo authored and bdukes committed Sep 21, 2022
1 parent 0e9fb67 commit ac6e9df
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<Compile Include="Entities\Portals\PortalAliasExtensions.cs" />
<Compile Include="Entities\Portals\PortalSettingUpdatedEventArgs.cs" />
<Compile Include="Entities\Portals\PortalTemplateEventArgs.cs" />
<Compile Include="Entities\Users\Exceptions\InvalidPasswordException.cs" />
<Compile Include="Entities\Users\Exceptions\InvalidUserRegisterException.cs" />
<Compile Include="Entities\Users\UpdateUserEventArgs.cs" />
<Compile Include="Entities\Content\ContentTypeMemberNameFixer.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Entities.Users
{
using System;

/// <summary>
/// An exception class which should be used to throw exceptions when password validations fail.
/// </summary>
[Serializable]
public class InvalidPasswordException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="InvalidPasswordException"/> class.
/// </summary>
public InvalidPasswordException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="InvalidPasswordException"/> class with a message.
/// </summary>
/// <param name="message">Exception message.</param>
public InvalidPasswordException(string message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="InvalidPasswordException"/> class with a message and an inner exception.
/// </summary>
/// <param name="message">Exception message.</param>
/// <param name="innerException">Inner exception to wrap.</param>
public InvalidPasswordException(
string message,
Exception innerException)
: base(message, innerException)
{
}
}
}
2 changes: 1 addition & 1 deletion DNN Platform/Library/Entities/Users/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static bool ChangePassword(UserInfo user, string oldPassword, string newP
}
else
{
throw new Exception("Invalid Password");
throw new InvalidPasswordException("Invalid Password");
}

return passwordChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ public bool ChangePassword(int portalId, int userId, string newPassword)
catch (ThreadAbortException)
{
return true;
}
catch (InvalidPasswordException exc)
{
// Password validation has failed
Logger.Error(exc);
throw new InvalidPasswordException(
Localization.GetString("PasswordResetFailed", Constants.LocalResourcesFile),
exc);
}
catch (Exception exc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ public HttpResponseMessage ChangePassword(ChangePasswordDto changePasswordDto)

return this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true });
}
catch (InvalidPasswordException exc)
{
Logger.Error(exc);
return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, exc.Message);
}
catch (Exception ex)
{
Logger.Error(ex);
Expand Down

0 comments on commit ac6e9df

Please sign in to comment.