mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
If there is a bad password when changing it, we now inform the user
This commit is contained in:
parent
9aa60dfc23
commit
2e22ad946d
2 changed files with 28 additions and 11 deletions
|
@ -151,7 +151,7 @@ namespace PlexRequests.Core
|
|||
var passwordMatch = PasswordHasher.VerifyPassword(oldPassword, userToChange.Salt, userToChange.Hash);
|
||||
if (!passwordMatch)
|
||||
{
|
||||
throw new SecurityException("Password does not match");
|
||||
throw new SecurityException("Incorrect password.");
|
||||
}
|
||||
|
||||
var newSalt = PasswordHasher.GenerateSalt();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#region Copyright
|
||||
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: LoginModule.cs
|
||||
|
@ -23,10 +24,12 @@
|
|||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
|
||||
using System.Security;
|
||||
using Nancy;
|
||||
using Nancy.Authentication.Forms;
|
||||
using Nancy.Extensions;
|
||||
|
@ -43,7 +46,8 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
public class LoginModule : BaseModule
|
||||
{
|
||||
public LoginModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IResourceLinker linker) : base(pr)
|
||||
public LoginModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IResourceLinker linker)
|
||||
: base(pr)
|
||||
{
|
||||
UserMapper = m;
|
||||
Get["/login"] = _ =>
|
||||
|
@ -81,7 +85,10 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
if (userId == null)
|
||||
{
|
||||
return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/login?error=true&username=" + username : "~/login?error=true&username=" + username);
|
||||
return
|
||||
Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl)
|
||||
? $"~/{BaseUrl}/login?error=true&username=" + username
|
||||
: "~/login?error=true&username=" + username);
|
||||
}
|
||||
DateTime? expiry = null;
|
||||
if (Request.Form.RememberMe.HasValue)
|
||||
|
@ -113,7 +120,10 @@ namespace PlexRequests.UI.Modules
|
|||
var exists = UserMapper.DoUsersExist();
|
||||
if (exists)
|
||||
{
|
||||
return Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/register?error=true" : "~/register?error=true");
|
||||
return
|
||||
Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl)
|
||||
? $"~/{BaseUrl}/register?error=true"
|
||||
: "~/register?error=true");
|
||||
}
|
||||
var userId = UserMapper.CreateAdmin(username, Request.Form.Password);
|
||||
Session[SessionKeys.UsernameKey] = username;
|
||||
|
@ -123,6 +133,7 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/changepassword"] = _ => ChangePassword();
|
||||
Post["/changepassword"] = _ => ChangePasswordPost();
|
||||
}
|
||||
|
||||
private ICustomUserMapper UserMapper { get; }
|
||||
|
||||
private Negotiator ChangePassword()
|
||||
|
@ -148,7 +159,8 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
return Response.AsJson(new JsonResponseModel { Message = "The passwords do not match", Result = false });
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var result = UserMapper.UpdatePassword(username, oldPass, newPassword);
|
||||
if (result)
|
||||
{
|
||||
|
@ -157,5 +169,10 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
return Response.AsJson(new JsonResponseModel { Message = "Could not update the password in the database", Result = false });
|
||||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Message = e.ToString(), Result = false });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue