diff --git a/Oqtane.Client/Modules/Admin/Users/Add.razor b/Oqtane.Client/Modules/Admin/Users/Add.razor index 805155cb..537a3bac 100644 --- a/Oqtane.Client/Modules/Admin/Users/Add.razor +++ b/Oqtane.Client/Modules/Admin/Users/Add.razor @@ -14,7 +14,6 @@ @if (profiles != null) { -
@@ -22,24 +21,6 @@
-
- -
-
- - -
-
-
-
- -
-
- - -
-
-
@@ -123,12 +104,7 @@ @code { private bool _initialized = false; - private string _passwordrequirements; private string _username = string.Empty; - private string _password = string.Empty; - private string _passwordtype = "password"; - private string _togglepassword = string.Empty; - private string _confirm = string.Empty; private string _email = string.Empty; private string _displayname = string.Empty; private string _notify = "True"; @@ -142,8 +118,6 @@ { try { - _passwordrequirements = await UserService.GetPasswordRequirementsAsync(PageState.Site.SiteId); - _togglepassword = SharedLocalizer["ShowPassword"]; profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); settings = new Dictionary(); _initialized = true; @@ -169,39 +143,32 @@ { try { - if (_username != string.Empty && _password != string.Empty && _confirm != string.Empty && _email != string.Empty) + if (_username != string.Empty && _email != string.Empty) { - if (_password == _confirm) + if (ValidateProfiles()) { - if (ValidateProfiles()) + var user = new User(); + user.SiteId = PageState.Site.SiteId; + user.Username = _username; + user.Password = ""; // will be auto generated + user.Email = _email; + user.DisplayName = string.IsNullOrWhiteSpace(_displayname) ? _username : _displayname; + user.PhotoFileId = null; + user.SuppressNotification = !bool.Parse(_notify); + + user = await UserService.AddUserAsync(user); + + if (user != null) { - var user = new User(); - user.SiteId = PageState.Site.SiteId; - user.Username = _username; - user.Password = _password; - user.Email = _email; - user.DisplayName = string.IsNullOrWhiteSpace(_displayname) ? _username : _displayname; - user.PhotoFileId = null; - user.SuppressNotification = !bool.Parse(_notify); - - user = await UserService.AddUserAsync(user); - - if (user != null) - { - await SettingService.UpdateUserSettingsAsync(settings, user.UserId); - await logger.LogInformation("User Created {User}", user); - NavigationManager.NavigateTo(NavigateUrl()); - } - else - { - await logger.LogError("Error Adding User {Username} {Email}", _username, _email); - AddModuleMessage(Localizer["Error.User.AddCheckPass"], MessageType.Error); - } + await SettingService.UpdateUserSettingsAsync(settings, user.UserId); + await logger.LogInformation("User Created {User}", user); + NavigationManager.NavigateTo(NavigateUrl()); + } + else + { + await logger.LogError("Error Adding User {Username} {Email}", _username, _email); + AddModuleMessage(Localizer["Error.User.AddCheckPass"], MessageType.Error); } - } - else - { - AddModuleMessage(Localizer["Message.Password.NoMatch"], MessageType.Warning); } } else @@ -252,18 +219,4 @@ var value = (string)e.Value; settings = SettingService.SetSetting(settings, SettingName, value); } - - private void TogglePassword() - { - if (_passwordtype == "password") - { - _passwordtype = "text"; - _togglepassword = SharedLocalizer["HidePassword"]; - } - else - { - _passwordtype = "password"; - _togglepassword = SharedLocalizer["ShowPassword"]; - } - } } diff --git a/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx b/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx index 1ad645d9..b25b2477 100644 --- a/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx +++ b/Oqtane.Client/Resources/Modules/Admin/Users/Add.resx @@ -117,12 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Error Adding User. Please Ensure Password Meets Complexity Requirements And Username And Email Is Not Already In Use. - - - Passwords Entered Do Not Match - Error Adding User @@ -133,17 +127,11 @@ Identity - You Must Provide A Username, Password, Email Address And All Required Profile Information + You Must Provide A Username, Email Address And All Required Profile Information Username Already Exists - - Please enter the password again to confirm it matches with the value above - - - Confirm Password: - The full name of the user @@ -156,21 +144,12 @@ Email: - - The user's password. Please choose a password which is sufficiently secure. - - - Password: - A unique username for a user. Note that this field can not be modified once it is saved. Username: - - Password - Indicate if new users should receive an email notification diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 549e00e3..fcf6e1ea 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -147,11 +147,13 @@ namespace Oqtane.Controllers if (_userPermissions.IsAuthorized(User, user.SiteId, EntityNames.User, -1, PermissionNames.Write, RoleNames.Admin)) { user.EmailConfirmed = true; + user.IsAuthenticated = true; allowregistration = true; } else { user.EmailConfirmed = false; + user.IsAuthenticated = false; allowregistration = _sites.GetSite(user.SiteId).AllowRegistration; } diff --git a/Oqtane.Server/Managers/UserManager.cs b/Oqtane.Server/Managers/UserManager.cs index 5f234c0e..53fa1f22 100644 --- a/Oqtane.Server/Managers/UserManager.cs +++ b/Oqtane.Server/Managers/UserManager.cs @@ -12,6 +12,7 @@ using Oqtane.Enums; using Oqtane.Infrastructure; using Oqtane.Models; using Oqtane.Repository; +using Oqtane.Security; using Oqtane.Shared; namespace Oqtane.Managers @@ -145,13 +146,17 @@ namespace Oqtane.Managers } else { - var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false); - succeeded = result.Succeeded; - if (!succeeded) + succeeded = true; + if (!user.IsAuthenticated) { - errors = "Password Not Valid For User"; + var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false); + succeeded = result.Succeeded; + if (!succeeded) + { + errors = "Password Not Valid For User"; + } + user.EmailConfirmed = succeeded; } - user.EmailConfirmed = succeeded; } if (succeeded)