@foreach (Profile profile in profiles)
@@ -106,8 +89,8 @@ else
}
-
- @if (!string.IsNullOrEmpty(p.Options))
+
+ @if (!string.IsNullOrEmpty(p.Options))
{
@@ -139,17 +122,18 @@ else
}
- }
-
-
+
+
-
-
@SharedLocalizer["Cancel"]
-
-
-
+
+
@SharedLocalizer["Cancel"]
+
+
+
+}
-@code {
+ @code {
+ private bool _initialized = false;
private string _passwordrequirements;
private int userid;
private string username = string.Empty;
@@ -159,9 +143,6 @@ else
private string confirm = string.Empty;
private string email = string.Empty;
private string displayname = string.Empty;
- private FileManager filemanager;
- private int photofileid = -1;
- private File photo = null;
private string isdeleted;
private string lastlogin;
private string lastipaddress;
@@ -179,32 +160,23 @@ else
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
- protected override async Task OnParametersSetAsync()
+ protected override async Task OnInitializedAsync()
{
try
{
- if (PageState.QueryString.ContainsKey("id"))
+ _passwordrequirements = await UserService.GetPasswordRequirementsAsync(PageState.Site.SiteId);
+ _togglepassword = SharedLocalizer["ShowPassword"];
+ profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
+
+ if (PageState.QueryString.ContainsKey("id") && int.TryParse(PageState.QueryString["id"], out int UserId))
{
- _passwordrequirements = await UserService.GetPasswordRequirementsAsync(PageState.Site.SiteId);
- _togglepassword = SharedLocalizer["ShowPassword"];
- profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
- userid = Int32.Parse(PageState.QueryString["id"]);
+ userid = UserId;
var user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
if (user != null)
{
username = user.Username;
email = user.Email;
displayname = user.DisplayName;
- if (user.PhotoFileId != null)
- {
- photofileid = user.PhotoFileId.Value;
- photo = await FileService.GetFileAsync(photofileid);
- }
- else
- {
- photofileid = -1;
- photo = null;
- }
isdeleted = user.IsDeleted.ToString();
lastlogin = string.Format("{0:MMM dd yyyy HH:mm:ss}", user.LastLoginOn);
lastipaddress = user.LastIPAddress;
@@ -218,6 +190,8 @@ else
deletedon = user.DeletedOn;
}
}
+
+ _initialized = true;
}
catch (Exception ex)
{
@@ -240,35 +214,37 @@ else
{
try
{
- if (username != string.Empty && email != string.Empty && ValidateProfiles())
+ if (username != string.Empty && email != string.Empty)
{
if (_password == confirm)
{
- var user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
- 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.PhotoFileId = filemanager.GetFileId();
- if (user.PhotoFileId == -1)
+ if (ValidateProfiles())
{
+ var user = await UserService.GetUserAsync(userid, PageState.Site.SiteId);
+ user.SiteId = PageState.Site.SiteId;
+ user.Username = username;
+ user.Password = _password;
+ user.Email = email;
+ user.DisplayName = string.IsNullOrWhiteSpace(displayname) ? username : displayname;
user.PhotoFileId = null;
- }
+ if (user.PhotoFileId == -1)
+ {
+ user.PhotoFileId = null;
+ }
- user.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
+ user.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
- user = await UserService.UpdateUserAsync(user);
- if (user != null)
- {
- await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
- await logger.LogInformation("User Saved {User}", user);
- NavigationManager.NavigateTo(NavigateUrl());
- }
- else
- {
- AddModuleMessage(Localizer["Message.Password.Complexity"], MessageType.Error);
+ user = await UserService.UpdateUserAsync(user);
+ if (user != null)
+ {
+ await SettingService.UpdateUserSettingsAsync(settings, user.UserId);
+ await logger.LogInformation("User Saved {User}", user);
+ NavigationManager.NavigateTo(NavigateUrl());
+ }
+ else
+ {
+ AddModuleMessage(Localizer["Message.Password.Complexity"], MessageType.Error);
+ }
}
}
else
@@ -290,27 +266,33 @@ else
private bool ValidateProfiles()
{
- bool valid = true;
foreach (Profile profile in profiles)
{
- if (string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty)) && !string.IsNullOrEmpty(profile.DefaultValue))
+ var value = GetProfileValue(profile.Name, string.Empty);
+ if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(profile.DefaultValue))
{
settings = SettingService.SetSetting(settings, profile.Name, profile.DefaultValue);
}
if (!profile.IsPrivate || UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin))
{
- if (valid == true && profile.IsRequired && string.IsNullOrEmpty(SettingService.GetSetting(settings, profile.Name, string.Empty)))
+ if (profile.IsRequired && string.IsNullOrEmpty(value))
{
- valid = false;
+ AddModuleMessage(string.Format(SharedLocalizer["ProfileRequired"], profile.Title), MessageType.Warning);
+ return false;
}
- if (valid == true && !string.IsNullOrEmpty(profile.Validation))
+ if (!string.IsNullOrEmpty(profile.Validation))
{
Regex regex = new Regex(profile.Validation);
- valid = regex.Match(SettingService.GetSetting(settings, profile.Name, string.Empty)).Success;
+ bool valid = regex.Match(value).Success;
+ if (!valid)
+ {
+ AddModuleMessage(string.Format(SharedLocalizer["ProfileInvalid"], profile.Title), MessageType.Warning);
+ return false;
+ }
}
}
}
- return valid;
+ return true;
}
private void ProfileChanged(ChangeEventArgs e, string SettingName)
diff --git a/Oqtane.Client/Modules/Admin/Users/Index.razor b/Oqtane.Client/Modules/Admin/Users/Index.razor
index 6957e3e6..82862c12 100644
--- a/Oqtane.Client/Modules/Admin/Users/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Users/Index.razor
@@ -17,26 +17,17 @@ else
{
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
|
|
|
SortTable("Username"))">@Localizer["Username"] |
- SortTable("DisplayName"))">@Localizer["Name"] |
+ SortTable("DisplayName"))">@Localizer["Name"] |
+ SortTable("Email"))">@Localizer["Email"] |
SortTable("LastLoginOn"))">@Localizer["LastLoginOn"] |
@@ -50,11 +41,12 @@ else
@context.User.Username |
- @((MarkupString)string.Format("{1}", @context.User.Email, @context.User.DisplayName)) |
+ @context.User.DisplayName |
+ @((MarkupString)string.Format("{1}", @context.User.Email, @context.User.Email)) |
@((context.User.LastLoginOn != DateTime.MinValue) ? string.Format("{0:dd-MMM-yyyy HH:mm:ss}", context.User.LastLoginOn) : "") |
-
+
}
@if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
@@ -259,7 +266,22 @@ else