Showing posts with label DNN. Show all posts
Showing posts with label DNN. Show all posts

Wednesday, February 27, 2013

DNN Manage Button Hidden Behind Another Module

There is one issue I've run into several times with DNN and that is an HTML module covering up another module.  I had this issue with the Dark Knight skin.  An HTML module I had on the ContentPane was covering up the dropdown menu, so I had to make some CSS adjustments to the z-index property.

The issue I have now is slightly different.  I've written several modules that either:
  1. Do not display anything in the View (they work in the background), but you still need to access the Settings to make changes
  2. Do not display anything in the View if there is no data
The problem is if you are in Edit mode and nothing is being displayed, you cannot get to the Manage button because it is 'behind' the Manage button of the module below it.


I've come up with a simple fix for this that I include in my View.ascx file:


<% if(DotNetNuke.Common.Globals.IsEditMode()) { %> 
 
<div runat="server" id="showIfEditMode" >
   <br />
   <br />
   <br />
</div>
 
<% } %> 
 
 


This adds some padding below the module when you are in Edit mode. That way, your Manage button will be visible even when there is nothing to display.

Monday, February 11, 2013

Sorting ArrayList with Linq

This was my first forray into Linq, so I thought I'd post it in case I need it again in the near future.

I needed a list of user to populate a DropDownList.  In DotNetNuke, you can get an ArrayList of all users on the system with a call to: UserController.GetUsers(int PortalID).

The problem is the list is sorted by UserID, so when you open the DDL, you'll see all the users in what seems to be random order.  I wanted the list to be sorted by LastName, FirstName without having to write some sort of IComparer.

This is a great use case for Linq ( I've heard a lot about it, but never used it).


ArrayList a = UserController.GetUsers(0);
var so = from UserInfo s in a orderby s.LastName,s.FirstName select s;
            
ddlUser.DataSource = so;
ddlUser.DataValueField = "UserID"; // Alias Name from Sproc
ddlUser.DataTextField = "DisplayName";   // Alias name from sproc
ddlUser.DataBind();
ddlUser.Items.Insert(0, new ListItem("Select One", "0")); // Adds items to DDL


If you are using a custom object (ie UserInfo), then you must explicitly declare the type.
When using LINQ to query non-generic IEnumerable collections such as ArrayList, you must explicitly declare the type of the range variable to reflect the specific type of the objects in the collection.

Friday, June 29, 2012

MS SQL UPDATE with a JOIN

This describes how to UPDATE a table when you have to JOIN another table.  This is for MS SQL Server, so the syntax varies with other versions.

In this example, I am updating the [aspnet_Membership] table, but I want to join the [aspnet_Users] table so I can do it user UserName.  This script allows me to set the password of a user to my password so I can log in as that user.  This is done by updating the ASP.NET Membership table.  I would need to store the [Password] and [PasswordSalt] of this account if I wanted to change it back.



UPDATE m 
SET   m.[Password] = 'mrhLMUfIWCuTHDwOtm1s/I9ABMQsS=='
    , m.[PasswordSalt] = 'suyp+Nsd2lmMPpQ=='
FROM [dnnDB].[dbo].[aspnet_Membership] m
JOIN [dnnDB].[dbo].[aspnet_Users] u on m.UserId = u.UserId
WHERE 1=1
  AND u.UserName in 
  (
      'FirstUser'
    , 'SecondUser'
    , 'ThirdUser'
  )
  

Friday, March 9, 2012

ASPX Hyperlinks: Opening automatically and in New Windows

Here's a couple quick tips that took me some time to work out.

1. Opening a Hyperlink in a new window:

ASPX


<asp:HyperLink ID="jiraLink" 
runat="server">&nbsp;&nbsp;&nbsp;&nbsp;Click here to Expand Window </asp:HyperLink>

Code-behind:


String jiraURL = "http://" + jiraServerURL +"/jira/secure/IssueNavigator.jspa?sId=" + sessionGUID;
jiraLink.NavigateUrl = jiraURL;
jiraLink.Target = "_blank";



And, to automatically open a Hyperlink, put this in the Page_Load:


Response.Write("<script type='text/javascript'>window.open('" + serverURL+ "','_blank');</script>");

Tuesday, February 28, 2012

DotNetNuke Update Custom Profile fields

I had a good bit of trouble with this, but I was able to get it working.

You may need to make sure the custom property you have created is marked Visible, but this is the code that ended up working for me in DNN 6.1.2.




UserInfo _currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
// Create Token
string sessionGuid = TokenLibrary.TokenSupport.CreateToken(_currentUser).ToString();
 
if (sessionGuid == null || (sessionGuid.Trim().Length < 1 )
sessionGuid = "00000000-0000-0000-0000-000000000000";
 
// Set User Property called "sessionGUID"
_currentUser.Profile.SetProfileProperty("sessionGUID", sessionGuid);
UserController.UpdateUser(_currentUser.PortalID, _currentUser);

Tuesday, February 15, 2011

Migrating users to DotNetNuke

I've been on a 2 month hiatus, but I've come back with some new skills.  I've been working on a DotNetNuke portal to replace our existing MojoPortal.  I really wanted to like MojoPortal because of it's simplicity and ease of setup, but in the end MojoPortal Core development pretty much came to a halt.  There are just too many standard features that are missing, plus DNN has so much out of the box, I couldn't resist.  Plus, the community behind DNN is huge.

While browsing Mitchel Sellers' blog, I found some SQL that allows me to migrate the 700+ user accounts in our MojoPortal to DotNetNuke.  I've put it in a script and parametized it.

After I created this, I created a table from my old MojoPortal, which contains: UserName, FirstName, LastName, DisplayName, Email, and RoleName (Primary Role, which must exist in DNN before running the script).  Then, I ran it through a cursor and added all the users.

** ADDITION NOTE:  If you are using {owner}{prefix} in DNN, you'll need to modify the script.



-- =======================================================================================================
-- Author:        Larry Eisenstein
-- Create date: 2/15/2011
-- Description:    Creates a DNN User by copying an existing user.
-- This can be used to script a single account creation or migrating users from another system.
-- This works by creating the NewUser from an existing user.
-- The script was pulled from Mitchel Sellers website.  He has a great blog, so you should visit it.
-- http://www.mitchelsellers.com/blogs/articletype/articleview/articleid/84/creating-a-standard-dotnetnuke-user-via-sql.aspx
-- 
-- 
-- Req: 
-- 1. Know the Username/Password of an existing user. The password for the user you create will be the password 
-- of this user
-- 2. If you are assigning Roles, the RoleName MUST existing in the DotNetNuke site
-- 
-- Defaults:  I set up some defaults, but these can be changed via params or just change the defaults in the script.
-- 
-- Notes: 
-- Stored Procs used: aspnet_Membership_CreateUser
-- Tables Updated: users, Roles, UserPortals
 
-- The password works by copying the encrypted password, passwordsalt of the ExistingUser to your new user.  Then, you can
-- just login with that user's password.
-- ==========================================================================================================
CREATE PROCEDURE [dbo].[AAA_MigrateUser_sp]
@ApplicationName varchar(255) = 'DotNetNuke',  -- Search for applicationName in your web.config
@ExistingUserName varchar(255) = 'TestUser',   -- This must be an existing DNN user
@FirstName varchar(255) = 'Migrated',            
@LastName varchar(255) = 'UserAccount',
@DisplayName varchar(255) = 'Migrated UserAccount',
@NewUserName varchar(255),
@RoleName varchar(255) = 'Registered Users',
@PortalId int = 0,
@Email nvarchar(256) = 'TestUser@email.org'
AS
BEGIN
 
DECLARE @PasswordQuestion varchar(256),
@PasswordAnswer varchar(256),
@Pw varchar(255),
@PasswordSalt varchar(255),
@PasswordFormat int,
@IsApproved bit,
@CurrentTimeUtc datetime,
@CreateDate datetime,
@UniqueEmail int,
@UserId uniqueidentifier,
@DNNUserId int,
@NumUsers int
 
 
SELECT    @PasswordQuestion = '',
@PasswordAnswer = '',
@IsApproved = 1,
@CurrentTimeUtc = GETDATE(),
@CreateDate = @CurrentTimeUtc,
@UniqueEmail = 0
 
 
 
 
SELECT @NumUsers = COUNT(*)
FROM aspnet_Users
WHERE UserName = @NewUserName
 
 
IF(@NumUsers != 0)
return -1
 
 
SELECT    @Pw = m.password,
@PasswordSalt = m.passwordsalt,
@PasswordFormat = m.passwordformat
FROM aspnet_users u
INNER JOIN aspnet_membership m  ON (u.userid = m.userid)
WHERE u.UserName = @ExistingUserName
 
 
 
-- Make the stored procedure call
EXEC dbo.aspnet_Membership_CreateUser @ApplicationName, @NewUserName, @Pw,
@PasswordSalt, @email, @passwordquestion, @PasswordAnswer, 
@IsApproved, @CurrentTimeUtc, @CreateDate, @UniqueEmail,
@PasswordFormat, @UserId
 
 
-- Insert the record into the DotNetNuke users table
INSERT INTO users (Username, FirstName, LastName, IsSuperUser, Email,
DisplayName, UpdatePassword)
VALUES(@NewUserName, @FirstName, @LastName, 0, @Email, @DisplayName, 0)
 
 
-- Get the new userid, from the DNN users table
SELECT @dnnuserid = userid
FROM Users
WHERE username = @NewUserName
 
 
-- Now, insert the record into the user portals table
INSERT INTO UserPortals (userId, PortalId, CreatedDate)
VALUES(@dnnuserid, @PortalId, GETDATE()) 
 
 
-- Now Give the user permissions to the User Group you specified
IF(@RoleName != 'Registered Users' and @RoleName IS NOT NULL)
BEGIN
INSERT INTO UserRoles (userId, roleId)
SELECT @dnnuserid,
roleId
FROM Roles
WHERE RoleName = @RoleName
END
 
-- Now Give the user permissions to the REGISTERED Users group
INSERT INTO UserRoles (userId, roleId)
SELECT @dnnuserid,
roleId
FROM Roles
WHERE RoleName = 'Registered Users'
 
 
 
END