added profile management
This commit is contained in:
		@ -56,6 +56,7 @@
 | 
			
		||||
            user = await UserService.LoginUserAsync(user, false, false);
 | 
			
		||||
            if (user.IsAuthenticated)
 | 
			
		||||
            {
 | 
			
		||||
                await logger.LogInformation("Login Successful For Username {Username}", Username);
 | 
			
		||||
                // complete the login on the server so that the cookies are set correctly on SignalR
 | 
			
		||||
                var interop = new Interop(jsRuntime);
 | 
			
		||||
                string antiforgerytoken = await interop.GetElementByName("__RequestVerificationToken");
 | 
			
		||||
@ -78,6 +79,7 @@
 | 
			
		||||
            user = await UserService.LoginUserAsync(user, true, Remember);
 | 
			
		||||
            if (user.IsAuthenticated)
 | 
			
		||||
            {
 | 
			
		||||
                await logger.LogInformation("Login Successful For Username {Username}", Username);
 | 
			
		||||
                authstateprovider.NotifyAuthenticationChanged();
 | 
			
		||||
                NavigationManager.NavigateTo(NavigateUrl(ReturnUrl, Reload.Site));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@ -80,6 +80,14 @@
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        }
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label class="control-label">Url: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@url" disabled />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label class="control-label">Template: </label>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										165
									
								
								Oqtane.Client/Modules/Admin/Profiles/Edit.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								Oqtane.Client/Modules/Admin/Profiles/Edit.razor
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,165 @@
 | 
			
		||||
@namespace Oqtane.Modules.Admin.Profiles
 | 
			
		||||
@inherits ModuleBase
 | 
			
		||||
@inject NavigationManager NavigationManager
 | 
			
		||||
@inject IProfileService ProfileService
 | 
			
		||||
 | 
			
		||||
    <table class="table table-borderless">
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Name: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@name" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Title: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@title" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Description: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <textarea class="form-control" @bind="@description" rows="5" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Category: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@category" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Order: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@vieworder" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Length: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@maxlength" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Default Value: </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <input class="form-control" @bind="@defaultvalue" />
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Required? </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <select class="form-control" @bind="@isrequired">
 | 
			
		||||
                    <option value="True">Yes</option>
 | 
			
		||||
                    <option value="False">No</option>
 | 
			
		||||
                </select>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <label for="Name" class="control-label">Private? </label>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <select class="form-control" @bind="@isprivate">
 | 
			
		||||
                    <option value="True">Yes</option>
 | 
			
		||||
                    <option value="False">No</option>
 | 
			
		||||
                </select>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
    </table>
 | 
			
		||||
<button type="button" class="btn btn-success" @onclick="SaveProfile">Save</button>
 | 
			
		||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
 | 
			
		||||
 | 
			
		||||
@code {
 | 
			
		||||
    public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
 | 
			
		||||
    public override string Actions { get { return "Add,Edit"; } }
 | 
			
		||||
 | 
			
		||||
    int profileid = -1;
 | 
			
		||||
    string name = "";
 | 
			
		||||
    string title = "";
 | 
			
		||||
    string description = "";
 | 
			
		||||
    string category = "";
 | 
			
		||||
    string vieworder = "0";
 | 
			
		||||
    string maxlength = "0";
 | 
			
		||||
    string defaultvalue = "";
 | 
			
		||||
    string isrequired = "False";
 | 
			
		||||
    string isprivate = "False";
 | 
			
		||||
 | 
			
		||||
    protected override async Task OnInitializedAsync()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            if (PageState.QueryString.ContainsKey("id"))
 | 
			
		||||
            {
 | 
			
		||||
                profileid = Int32.Parse(PageState.QueryString["id"]);
 | 
			
		||||
                Profile profile = await ProfileService.GetProfileAsync(profileid);
 | 
			
		||||
                if (profile != null)
 | 
			
		||||
                {
 | 
			
		||||
                    name = profile.Name;
 | 
			
		||||
                    title = profile.Title;
 | 
			
		||||
                    description = profile.Description;
 | 
			
		||||
                    category = profile.Category;
 | 
			
		||||
                    vieworder = profile.ViewOrder.ToString();
 | 
			
		||||
                    maxlength = profile.MaxLength.ToString();
 | 
			
		||||
                    defaultvalue = profile.DefaultValue;
 | 
			
		||||
                    isrequired = profile.IsRequired.ToString();
 | 
			
		||||
                    isprivate = profile.IsPrivate.ToString();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            await logger.LogError(ex, "Error Loading Profile {ProfileId} {Error}", profileid, ex.Message);
 | 
			
		||||
            AddModuleMessage("Error Loading Profile", MessageType.Error);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task SaveProfile()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            Profile profile;
 | 
			
		||||
            if (profileid != -1)
 | 
			
		||||
            {
 | 
			
		||||
                profile = await ProfileService.GetProfileAsync(profileid);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                profile = new Profile();
 | 
			
		||||
            }
 | 
			
		||||
            profile.Name = name;
 | 
			
		||||
            profile.Title = title;
 | 
			
		||||
            profile.Description = description;
 | 
			
		||||
            profile.Category = category;
 | 
			
		||||
            profile.ViewOrder = int.Parse(vieworder);
 | 
			
		||||
            profile.MaxLength = int.Parse(maxlength);
 | 
			
		||||
            profile.DefaultValue = defaultvalue;
 | 
			
		||||
            profile.IsRequired = (isrequired == null ? false : Boolean.Parse(isrequired));
 | 
			
		||||
            profile.IsPrivate = (isprivate == null ? false : Boolean.Parse(isprivate));
 | 
			
		||||
            profile = await ProfileService.UpdateProfileAsync(profile);
 | 
			
		||||
            await logger.LogInformation("Profile Saved {Profile}", profile);
 | 
			
		||||
            NavigationManager.NavigateTo(NavigateUrl());
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", profileid, ex.Message);
 | 
			
		||||
            AddModuleMessage("Error Saving Profile", MessageType.Error);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										51
									
								
								Oqtane.Client/Modules/Admin/Profiles/Index.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Oqtane.Client/Modules/Admin/Profiles/Index.razor
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
			
		||||
@namespace Oqtane.Modules.Admin.Profiles
 | 
			
		||||
@inherits ModuleBase
 | 
			
		||||
@inject IProfileService ProfileService
 | 
			
		||||
 | 
			
		||||
@if (Profiles == null)
 | 
			
		||||
{
 | 
			
		||||
    <p><em>Loading...</em></p>
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
{
 | 
			
		||||
    <ActionLink Action="Add" Text="Add Profile" Control="Edit" />
 | 
			
		||||
 | 
			
		||||
    <Pager Items="@Profiles">
 | 
			
		||||
        <Header>
 | 
			
		||||
            <th> </th>
 | 
			
		||||
            <th> </th>
 | 
			
		||||
            <th>Name</th>
 | 
			
		||||
        </Header>
 | 
			
		||||
        <Row>
 | 
			
		||||
            <td><ActionLink Action="Edit" Parameters="@($"id=" + context.ProfileId.ToString())" /></td>
 | 
			
		||||
            <td><ConfirmationDialog Header="Delete Profile" Message="@("Are You Sure You Wish To Delete " + context.Name + "?")" Action="Delete" Class="btn btn-danger" OnClick="@(async () => await DeleteProfile(context.ProfileId))" /></td>
 | 
			
		||||
            <td>@context.Name</td>
 | 
			
		||||
        </Row>
 | 
			
		||||
    </Pager>
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@code {
 | 
			
		||||
    public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
 | 
			
		||||
 | 
			
		||||
    List<Profile> Profiles;
 | 
			
		||||
 | 
			
		||||
    protected override async Task OnInitializedAsync()
 | 
			
		||||
    {
 | 
			
		||||
        Profiles = await ProfileService.GetProfilesAsync(PageState.Site.SiteId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async Task DeleteProfile(int ProfileId)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            await ProfileService.DeleteProfileAsync(ProfileId);
 | 
			
		||||
            await logger.LogInformation("Profile Deleted {ProfileId}", ProfileId);
 | 
			
		||||
            AddModuleMessage("Profile Deleted", MessageType.Success);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            await logger.LogError(ex, "Error Deleting Profile {ProfileId} {Error}", ProfileId, ex.Message);
 | 
			
		||||
            AddModuleMessage("Error Deleting Profile", MessageType.Error);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -22,7 +22,7 @@
 | 
			
		||||
    </tr>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td>
 | 
			
		||||
            <label for="Name" class="control-label">Auto Assigned: </label>
 | 
			
		||||
            <label for="Name" class="control-label">Auto Assigned? </label>
 | 
			
		||||
        </td>
 | 
			
		||||
        <td>
 | 
			
		||||
            <select class="form-control" @bind="@isautoassigned">
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,7 @@
 | 
			
		||||
    </tr>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td>
 | 
			
		||||
            <label for="Name" class="control-label">Auto Assigned: </label>
 | 
			
		||||
            <label for="Name" class="control-label">Auto Assigned? </label>
 | 
			
		||||
        </td>
 | 
			
		||||
        <td>
 | 
			
		||||
            <select class="form-control" @bind="@isautoassigned" readonly>
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,7 @@
 | 
			
		||||
    </tr>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td>
 | 
			
		||||
            <label for="Name" class="control-label">Auto Assigned: </label>
 | 
			
		||||
            <label for="Name" class="control-label">Auto Assigned? </label>
 | 
			
		||||
        </td>
 | 
			
		||||
        <td>
 | 
			
		||||
            <select class="form-control" @bind="@isautoassigned">
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
@namespace Oqtane.Modules.Admin.Profile
 | 
			
		||||
@namespace Oqtane.Modules.Admin.UserProfile
 | 
			
		||||
@inherits ModuleBase
 | 
			
		||||
@inject NavigationManager NavigationManager
 | 
			
		||||
@inject IUserService UserService
 | 
			
		||||
@ -12,17 +12,20 @@
 | 
			
		||||
    public string Action { get; set; }
 | 
			
		||||
 | 
			
		||||
    [Parameter]
 | 
			
		||||
    public string Text { get; set; } // optional
 | 
			
		||||
    public string Text { get; set; } // optional - defaults to Action if not specified
 | 
			
		||||
 | 
			
		||||
    [Parameter]
 | 
			
		||||
    public string Parameters { get; set; } // optional
 | 
			
		||||
    public string Parameters { get; set; } // optional - querystring parameter should be in the form of "id=x&name=y"
 | 
			
		||||
 | 
			
		||||
    [Parameter]
 | 
			
		||||
    public string Class { get; set; } // optional
 | 
			
		||||
    public string Class { get; set; } // optional - defaults to primary if not specified
 | 
			
		||||
 | 
			
		||||
    [Parameter]
 | 
			
		||||
    public string Style { get; set; } // optional
 | 
			
		||||
 | 
			
		||||
    [Parameter]
 | 
			
		||||
    public string Control { get; set; } // optional - can be used to explicitly link an Action to a Module Control
 | 
			
		||||
 | 
			
		||||
    string text = "";
 | 
			
		||||
    string url = "";
 | 
			
		||||
    string parameters = "";
 | 
			
		||||
@ -57,7 +60,15 @@
 | 
			
		||||
 | 
			
		||||
        if (PageState.EditMode)
 | 
			
		||||
        {
 | 
			
		||||
            string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
 | 
			
		||||
            string typename;
 | 
			
		||||
            if (string.IsNullOrEmpty(Control))
 | 
			
		||||
            {
 | 
			
		||||
                typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Action + ",");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0) + ",", Control + ",");
 | 
			
		||||
            }
 | 
			
		||||
            Type moduleType = Type.GetType(typename);
 | 
			
		||||
            if (moduleType != null)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
@ -125,7 +125,7 @@ namespace Oqtane.Modules
 | 
			
		||||
            ModuleInstance.HideProgressIndicator();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // logging method
 | 
			
		||||
        // logging methods
 | 
			
		||||
        public async Task Log(LogLevel level, Exception exception, string message, params object[] args)
 | 
			
		||||
        {
 | 
			
		||||
            int PageId = PageState.Page.PageId;
 | 
			
		||||
@ -153,6 +153,10 @@ namespace Oqtane.Modules
 | 
			
		||||
                    function = LogFunction.Read;
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
            if (feature == "Login")
 | 
			
		||||
            {
 | 
			
		||||
                function = LogFunction.Security;
 | 
			
		||||
            }
 | 
			
		||||
            await LoggingService.Log(PageId, ModuleId, UserId, category, feature, function, level, exception, message, args);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user