-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from UpendoVentures/feature-set-demousers
Feature set demousers
- Loading branch information
Showing
11 changed files
with
548 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,15 @@ | |
<data name="CaptchaModeToggled.Text" xml:space="preserve"> | ||
<value>CAPTCHA has been toggled {0} on this website. </value> | ||
</data> | ||
<data name="CreateUserExists.Text" xml:space="preserve"> | ||
<value>User already exists, not created: {0} ({1}).</value> | ||
</data> | ||
<data name="CreateUserFailure.Text" xml:space="preserve"> | ||
<value>Error creating user: {0} ({1}).</value> | ||
</data> | ||
<data name="CreateUserSuccess.Text" xml:space="preserve"> | ||
<value>Successfully created user: {0} ({1}).</value> | ||
</data> | ||
<data name="DebugDisabled.Text" xml:space="preserve"> | ||
<value>Debugging is disabled throughout the site. </value> | ||
</data> | ||
|
@@ -141,6 +150,24 @@ | |
<data name="DebugStatusWebConfig.Text" xml:space="preserve"> | ||
<value>Debugging in the web.config is {0}.</value> | ||
</data> | ||
<data name="DeleteDemoUsers.Text" xml:space="preserve"> | ||
<value>Allows you to delete the user accounts created using the `set-demousers` command, in bulk.</value> | ||
</data> | ||
<data name="DeleteUserNotNeeded.Text" xml:space="preserve"> | ||
<value>User account does not exist, not deleted: {0} {1} ({2}).</value> | ||
</data> | ||
<data name="DeleteUserSuccess.Text" xml:space="preserve"> | ||
<value>Successfully deleted user account: {0} {1} ({2}).</value> | ||
</data> | ||
<data name="DemoUserAccountsAdded.Text" xml:space="preserve"> | ||
<value>Successfully added demo user accounts... We saved some time together. Yay! :)</value> | ||
</data> | ||
<data name="DemoUsers.Text" xml:space="preserve"> | ||
<value>Helps when developing or building out demos, by automatically adding a bunch of fun user accounts to play with.</value> | ||
</data> | ||
<data name="DemoUsersDeleted.Text" xml:space="preserve"> | ||
<value>Successfully deleted demo user accounts... We saved some time together. Yay! :)</value> | ||
</data> | ||
<data name="Deprecated.Text" xml:space="preserve"> | ||
<value>This command has been deprecated. Please use '{0}' instead. This command will be removed in a future release.</value> | ||
</data> | ||
|
@@ -265,6 +292,21 @@ | |
<code class="block">list-debug</code> | ||
</div></value> | ||
</data> | ||
<data name="Prompt_DeleteDemoUsers_ResultHtml.Text" xml:space="preserve"> | ||
<value><div> | ||
<p>This is a companion command for the `set-demousers` command. This version of the command will permanently delete the users accounts created by that command.</p> | ||
<h4>Using delete-demousers</h4> | ||
<code class="block">delete-demousers</code> | ||
<p>This command does not have any flags</p> | ||
<code class="block">delete-demousers</code> | ||
<h4>Output</h4> | ||
<p>If successful, you should see a message for each demo user deleted, stating the result of the deletion of the account.</p> | ||
<p>User Deleted:</p> | ||
<code class="block">Successfully deleted user account: Jane Doe ({[email protected]}).</code> | ||
<p>User Doesn't Exist:</p> | ||
<code class="block">User account does not exist, not deleted: Jane Doe ({[email protected]}).</code> | ||
</div></value> | ||
</data> | ||
<data name="Prompt_DeletePackages_ResultHtml.Text" xml:space="preserve"> | ||
<value><div> | ||
<p>Newer versions of DNN saves any installed extension into the `/App_Data/ExtensionPackages/` folder. This | ||
|
@@ -301,6 +343,24 @@ | |
</p> | ||
</div></value> | ||
</data> | ||
<data name="Prompt_DemoUsers_ResultHtml.Text" xml:space="preserve"> | ||
<value><div> | ||
<p>When working on building a website or extension, you often need some demo users to use for your work. This command adds a handful of test user accounts for you.</p> | ||
<h4>Using set-demousers</h4> | ||
<code class="block">set-demousers</code> | ||
<p>This command does not have any flags</p> | ||
<code class="block">set-demousers</code> | ||
<h4>Output</h4> | ||
<p>If successful, you should see a message for each demo user, stating the result of the creation of the account.</p> | ||
<p>User Created:</p> | ||
<code class="block">Successfully created user: Jane Doe ({[email protected]}).</code> | ||
<p>User Exists:</p> | ||
<code class="block">User already exists, not created: Jane Doe ({[email protected]}).</code> | ||
<p>Error Creating User:</p> | ||
<code class="block">Error creating user: Jane Doe ({[email protected]}).</code> | ||
<p>(<em>if this happens, check the Admin Log to see why, or run `set-debug` and then check the Log4NET log file for more details.</em>)</p> | ||
</div></value> | ||
</data> | ||
<data name="Prompt_ImpersonateFlagsInvalid.Text" xml:space="preserve"> | ||
<value>You must either specify a valid UserID -OR- Username value to impersonate another user account. Both were empty. Please only specify one.</value> | ||
</data> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#region License | ||
|
||
// Distributed under the MIT License | ||
// ============================================================ | ||
// Copyright (c) Upendo Ventures, LLC | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
// and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
// including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION 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.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Web; | ||
using System.Web.UI; | ||
using DotNetNuke.Instrumentation; | ||
using Upendo.Modules.UpendoPrompt.Components; | ||
using Constants = Upendo.Modules.UpendoPrompt.Components.Constants; | ||
|
||
// required for DNN Prompt | ||
//using DotNetNuke.Prompt; // deprecated Prompt is replaced with this | ||
using Dnn.PersonaBar.Library.Helper; | ||
using Dnn.PersonaBar.Library.Prompt; | ||
using Dnn.PersonaBar.Library.Prompt.Attributes; | ||
using Dnn.PersonaBar.Library.Prompt.Models; | ||
using DotNetNuke.Common.Utilities; // added for the commented-out clearing of cache below | ||
using DotNetNuke.Entities.Portals; | ||
using DotNetNuke.Entities.Users; | ||
using Upendo.Modules.UpendoPrompt.Entities; | ||
|
||
namespace Upendo.Modules.UpendoPrompt.Commands | ||
{ | ||
[ConsoleCommand("delete-demousers", Constants.PromptCategory, "DeleteDemoUsers")] | ||
public class DeleteDemoUsers : PromptBase, IConsoleCommand | ||
{ | ||
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(DeleteDemoUsers)); | ||
|
||
#region Implementation | ||
|
||
public override void Init(string[] args, PortalSettings portalSettings, UserInfo userInfo, int activeTabId) | ||
{ | ||
// no paramters | ||
} | ||
|
||
public override ConsoleResultModel Run() | ||
{ | ||
try | ||
{ | ||
var messages = new List<PromptMessage>(); | ||
|
||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Tony", | ||
LastName = "Stark", | ||
Email = "[email protected]", | ||
Username = "tstark" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Diana", | ||
LastName = "Prince", | ||
Email = "[email protected]", | ||
Username = "dprince" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Peter", | ||
LastName = "Quill", | ||
Email = "[email protected]", | ||
Username = "pquill" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Rey", | ||
LastName = "Skywalker", | ||
Email = "[email protected]", | ||
Username = "rskywalker" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Ethan", | ||
LastName = "Hunt", | ||
Email = "[email protected]", | ||
Username = "ehunt" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Wade", | ||
LastName = "Wilson", | ||
Email = "[email protected]", | ||
Username = "wwilson" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Natasha", | ||
LastName = "Romanov", | ||
Email = "[email protected]", | ||
Username = "nromanov" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Hermione", | ||
LastName = "Granger", | ||
Email = "[email protected]", | ||
Username = "hgranger" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "John", | ||
LastName = "Wick", | ||
Email = "[email protected]", | ||
Username = "jwick" | ||
})); | ||
messages.Add(DeleteUserAccount(new DemoUser | ||
{ | ||
FirstName = "Eggsy", | ||
LastName = "Unwin", | ||
Email = "[email protected]", | ||
Username = "eunwin" | ||
})); | ||
|
||
// emp | ||
|
||
var output = this.LocalizeString(Constants.LocalizationKeys.DemoUsersDeleted); | ||
|
||
// clear DNN cache | ||
//DataCache.ClearCache(); | ||
|
||
return new ConsoleResultModel | ||
{ | ||
Output = output, | ||
Data = messages, | ||
IsError = false | ||
}; | ||
} | ||
catch (Exception e) | ||
{ | ||
LogError(e); | ||
return new ConsoleErrorResultModel(string.Concat(Constants.OutputPrefix, this.LocalizeString(Constants.LocalizationKeys.ErrorOccurred))); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Helpers | ||
|
||
private PromptMessage DeleteUserAccount(DemoUser newUser) | ||
{ | ||
var OUser = DotNetNuke.Entities.Users.UserController.GetUserByName(this.PortalId, newUser.Username); | ||
var blnExists = (OUser != null); | ||
|
||
if (blnExists) | ||
{ | ||
// delete the user account | ||
DotNetNuke.Entities.Users.UserController.DeleteUser(ref OUser, false, false); | ||
DotNetNuke.Entities.Users.UserController.RemoveUser(OUser); | ||
return new PromptMessage(string.Format(this.LocalizeString(Constants.LocalizationKeys.DeleteUserSuccess), newUser.FirstName, newUser.LastName, newUser.Email)); | ||
} | ||
|
||
// message about the user not needing to be deleted | ||
return new PromptMessage(string.Format(this.LocalizeString(Constants.LocalizationKeys.DeleteUserNotNeeded), newUser.FirstName, newUser.LastName, newUser.Email)); | ||
} | ||
|
||
protected override void LogError(Exception ex) | ||
{ | ||
if (ex != null) | ||
{ | ||
Logger.Error(ex.Message, ex); | ||
if (ex.InnerException != null) | ||
{ | ||
Logger.Error(ex.InnerException.Message, ex.InnerException); | ||
} | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
Oops, something went wrong.