Skip to content

Commit

Permalink
Merge pull request #92 from UpendoVentures/dev
Browse files Browse the repository at this point in the history
Merging dev and main
  • Loading branch information
WillStrohl authored May 23, 2024
2 parents 7e04414 + 8968e7a commit 2bd1314
Show file tree
Hide file tree
Showing 17 changed files with 706 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,4 @@
<data name="NotPermissions.Text" xml:space="preserve">
<value>You do not have the necessary security permissions to use this application.</value>
</data>
<data name="UsernameInUse.Text" xml:space="preserve">
<value>The username is already in use.</value>
</data>
</root>
33 changes: 33 additions & 0 deletions Modules/UserManager/App_LocalResources/UserRoles.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,36 @@
<data name="AddRole.Text" xml:space="preserve">
<value>Add Role</value>
</data>
<data name="Cancel.Text" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="ClearDates.Text" xml:space="preserve">
<value>Clear the Dates</value>
</data>
<data name="ClearStartEndDate.Text" xml:space="preserve">
<value>This role has a start date and/or end date assigned to it. Clicking OK will clear those values. This action CANNOT be undone. Do you want to proceed?</value>
</data>
<data name="CorrectlyEdited.Text" xml:space="preserve">
<value>Success: Correctly edited</value>
</data>
<data name="Delete.Text" xml:space="preserve">
<value>Delete</value>
</data>
<data name="ErrorOccurred.Text" xml:space="preserve">
<value>Error: an error has occurred</value>
</data>
<data name="Expires.Text" xml:space="preserve">
<value>EXPIRES</value>
</data>
<data name="ExpiresDate.Text" xml:space="preserve">
<value>Expires date</value>
</data>
<data name="NoRolesFounds.Text" xml:space="preserve">
<value>No roles founds</value>
</data>
<data name="Ok.text" xml:space="preserve">
<value>Ok</value>
</data>
<data name="Role.Text" xml:space="preserve">
<value>ROLE</value>
</data>
Expand All @@ -138,7 +162,16 @@
<data name="SearchCriteria.Text" xml:space="preserve">
<value>with this search criteria</value>
</data>
<data name="Start.Text" xml:space="preserve">
<value>START</value>
</data>
<data name="StartDate.Text" xml:space="preserve">
<value>Start date</value>
</data>
<data name="UserList.Text" xml:space="preserve">
<value>User List</value>
</data>
<data name="YouAreSure.Text" xml:space="preserve">
<value>You're sure?</value>
</data>
</root>
160 changes: 140 additions & 20 deletions Modules/UserManager/Controllers/UserManageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using DotNetNuke.Entities.Users;
using DotNetNuke.Framework.JavaScriptLibraries;
using DotNetNuke.Instrumentation;
using DotNetNuke.Security.Membership;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Localization;
using DotNetNuke.Web.Mvc.Framework.ActionFilters;
using DotNetNuke.Web.Mvc.Framework.Controllers;
using System;
using System.Net;
using System.Web.Mvc;
using Upendo.Modules.UserManager.Models.DnnModel;
using Upendo.Modules.UserManager.Utility;
using Upendo.Modules.UserManager.ViewModels;
using static Telerik.Web.UI.OrgChartStyles;

namespace Upendo.Modules.UserManager.Controllers
{
Expand Down Expand Up @@ -122,21 +127,48 @@ public ActionResult Create(UserViewModel item)
{
DotNetNuke.Framework.JavaScriptLibraries.JavaScript.RequestRegistration(CommonJs.DnnPlugins);
var portalId = ModuleContext.PortalId;
var user = UserController.GetUserByName(portalId, item.Username);
ModelState.Remove("UserId");
if (user != null)
if (!ModelState.IsValid)
{
string errorMessage = Localization.GetString("UsernameInUse.Text", ResourceFile);
ModelState.AddModelError(string.Empty, @errorMessage);
return View(item);
}

if (!ModelState.IsValid)
var userCreateStatus = UserRepository.CreateUser(item, portalId);
if (userCreateStatus == UserCreateStatus.Success)
{
return RedirectToAction("Index");
}
else
{
switch (userCreateStatus)
{
case UserCreateStatus.DuplicateEmail:
ModelState.AddModelError("Email", "Duplicate; Email Address already in use on another User Account");
break;
case UserCreateStatus.InvalidEmail:
ModelState.AddModelError("Email", "Invalid; Email Address did not pass validation");
break;
case UserCreateStatus.InvalidPassword:
ModelState.AddModelError("Password", "Invalid; Password requirements were not met");
break;
case UserCreateStatus.BannedPasswordUsed:
ModelState.AddModelError("Password", "Invalid; Password is banned");
break;
case UserCreateStatus.DuplicateUserName:
case UserCreateStatus.UserAlreadyRegistered:
case UserCreateStatus.UsernameAlreadyExists:
ModelState.AddModelError("Username", "Duplicate; Username already in use on another User Account");
break;
case UserCreateStatus.InvalidUserName:
ModelState.AddModelError("Username", "Invalid; Username does not meet requirements");
break;
default:
ModelState.AddModelError(string.Empty, $"Create User Failed. Unhandled or Unknown UserCreateStatus: {userCreateStatus}");
break;
}
string errorMessage = UserController.GetUserCreateStatus(userCreateStatus);
ModelState.AddModelError(string.Empty, errorMessage);
return View(item);
}
UserRepository.CreateUser(item, portalId);
return RedirectToAction("Index");
}

public ActionResult Edit(int itemId)
Expand Down Expand Up @@ -249,23 +281,111 @@ public ActionResult UserRoles(double? take, int? pageIndex, int? goToPage, strin
var result1 = UserRepository.GetRolesByUser(takeValue, pageIndexValue, goToPage, portalId, search, itemId);
return View(result1);
}

if (roleId != null)
{
if (actionView == "Add")
{
RoleController.Instance.AddUserRole(portalId, itemId, roleIdValue, RoleStatus.Approved, false, DateTime.Now, DateTime.Now.AddDays(30));
}
else
{
RoleController.Instance.UpdateUserRole(portalId, itemId, roleIdValue, RoleStatus.Approved, false, true);
}
}
ViewBag.User = UserRepository.GetUser(portalId, itemId);
var result = UserRepository.GetRolesByUser(takeValue, pageIndexValue, goToPage, portalId, search, itemId);
return View(result);
}
}

[HttpPost]
public ActionResult AddUserRole(int itemId, int roleId)
{
bool isAuthenticated = Request.IsAuthenticated;
// Check if the authenticated user has the required permission
var hasPermission = Functions.HasPermission(ModuleContext);

if (!isAuthenticated || !hasPermission)
{
string errorMessage = Localization.GetString("NotPermissions.Text", ResourceFile);
ViewBag.ErrorMessage = errorMessage;
return View("Error");
}
else
{
try
{
var portalId = ModuleContext.PortalId;
RoleController.Instance.AddUserRole(portalId, itemId, roleId, RoleStatus.Approved, false, DateTime.MinValue, DateTime.MinValue);
}
catch (Exception ex)
{
// Log the exception
LoggerSource.Instance.GetLogger(typeof(UserRepository)).Error(ex);
}
return Content("");
}
}

[HttpPost]
public ActionResult RemoveUserRole(int itemId, int roleId)
{
bool isAuthenticated = Request.IsAuthenticated;
// Check if the authenticated user has the required permission
var hasPermission = Functions.HasPermission(ModuleContext);

if (!isAuthenticated || !hasPermission)
{
string errorMessage = Localization.GetString("NotPermissions.Text", ResourceFile);
ViewBag.ErrorMessage = errorMessage;
return View("Error");
}
else
{
try
{
var portalId = ModuleContext.PortalId;
RoleController.Instance.UpdateUserRole(portalId, itemId, roleId, RoleStatus.Approved, false, true);
}
catch (Exception ex)
{
// Log the exception
LoggerSource.Instance.GetLogger(typeof(UserRepository)).Error(ex);
}
return Content("");
}
}

[HttpPost]
public ActionResult UpdateDateTimeUserRole(int itemId, int roleId, DateTime? effectiveDate, DateTime? expiryDate)
{
try
{
var portalId = ModuleContext.PortalId;
UserRepository.UpdateDateTimeUserRole(portalId, itemId, roleId, effectiveDate, expiryDate);
}
catch (Exception ex)
{
// Log the exception
LoggerSource.Instance.GetLogger(typeof(UserRepository)).Error(ex);
}
return Content("");
}

public ActionResult SetDateTimeUserRoleNull(int itemId, int roleId)
{
try
{
var portalId = ModuleContext.PortalId;
var roleController = new RoleController();
roleController.AddUserRole(portalId, itemId, roleId, DateTime.MinValue, DateTime.MinValue);

// Log the action
var user = UserController.GetUserById(portalId, itemId);
UserRoleInfo userRole = roleController.GetUserRole(portalId, itemId, roleId);
var currentUser = UserController.Instance.GetCurrentUserInfo();

var logMessage = $"The effective date and expiration date for Role {userRole.FullName} were cleared for User {user.Username} by Username {currentUser.Username}.";
var logger = LoggerSource.Instance.GetLogger(typeof(UserManageController));
logger.Info(logMessage);
}
catch (Exception ex)
{
// Log the exception
LoggerSource.Instance.GetLogger(typeof(UserManageController)).Error(ex);
}
return Content("");
}

public ActionResult PasswordResetLink(int itemId)
{
var portalId = ModuleContext.PortalId;
Expand Down
14 changes: 14 additions & 0 deletions Modules/UserManager/Module.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,17 @@
.color-black {
color: black !important;
}

/* version 1.01.02 additions */
.field-validation-error {
color: darkred;
font-size: small;
}

.datepicker-dropdown.datepicker-orient-left:after {
left: 50% !important;
}

.datepicker-dropdown.datepicker-orient-top:before {
border-top: 0 solid rgba(0, 0, 0, .15) !important;
}
66 changes: 33 additions & 33 deletions Modules/UserManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Upendo DNN User Manager Module for DNN")]
[assembly: AssemblyDescription("Upendo DNN User Manager Extension for DNN")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Upendo Ventures, LLC")]
[assembly: AssemblyProduct("UserManager Modules Extension for DNN")]
[assembly: AssemblyCopyright("Copyright (C) Upendo Ventures, LLC")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8DB6F62D-9211-4721-820A-6F39CE44E058")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("01.01.01")]
[assembly: AssemblyFileVersion("01.01.01")]
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Upendo DNN User Manager Module for DNN")]
[assembly: AssemblyDescription("Upendo DNN User Manager Extension for DNN")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Upendo Ventures, LLC")]
[assembly: AssemblyProduct("UserManager Modules Extension for DNN")]
[assembly: AssemblyCopyright("Copyright (C) Upendo Ventures, LLC")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8DB6F62D-9211-4721-820A-6F39CE44E058")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("01.02.00")]
[assembly: AssemblyFileVersion("01.02.00")]
1 change: 1 addition & 0 deletions Modules/UserManager/Upendo.Modules.UserManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Compile Include="ViewModels\Pagination.cs" />
<Compile Include="ViewModels\ResultJsonViewModel.cs" />
<Compile Include="ViewModels\RolesViewModel.cs" />
<Compile Include="ViewModels\UserRoleDates.cs" />
<Compile Include="ViewModels\UserViewModel.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Modules/UserManager/Upendo.UserManager.dnn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<dotnetnuke type="Package" version="6.0">
<packages>
<package name="Upendo.Modules.UserManager" type="Module" version="01.01.01">
<package name="Upendo.Modules.UserManager" type="Module" version="01.02.00">
<friendlyName>Upendo DNN User Manager</friendlyName>
<description><![CDATA[<p>The Upendo DNN User Manager empowers authorized end-users in your DNN website to be able to manage user accounts and their assigned security roles.</p>]]></description>
<iconFile>DesktopModules/MVC/Upendo.Modules.UserManager/Images/logo.png</iconFile>
Expand Down Expand Up @@ -60,7 +60,7 @@
<attributes>
<businessControllerClass>Upendo.Modules.UserManager.Components.UserManagerController, Upendo.Modules.UserManager</businessControllerClass>
<desktopModuleID>[DESKTOPMODULEID]</desktopModuleID>
<upgradeVersionsList>01.00.00,01.01.00,01.01.01</upgradeVersionsList>
<upgradeVersionsList>01.00.00,01.01.00,01.01.01,01.02.00</upgradeVersionsList>
</attributes>
</eventMessage>
</component>
Expand All @@ -69,7 +69,7 @@
<assembly>
<name>Upendo.Modules.UserManager.dll</name>
<path>bin</path>
<version>01.01.01</version>
<version>01.02.00</version>
</assembly>
</assemblies>
</component>
Expand All @@ -92,7 +92,7 @@
<script type="UnInstall">
<path>Providers\DataProviders\SqlDataProvider</path>
<name>Uninstall.SqlDataProvider</name>
<version>01.01.01</version>
<version>01.02.00</version>
</script>
</scripts>
</component>
Expand Down
Loading

0 comments on commit 2bd1314

Please sign in to comment.