infolink

Saturday, February 27, 2010

How to create your own DotNetNuke Registration page

About a week ago I was working on a project that required user registration. The out of the box registration form included in the core framework of DNN was just not what I wanted. I spent quite a few hours trying to figure out how to create my own. All I could find were modules to purchase or create my own membershipo provider.

Well purchasing a module was not in my scope as I wanted to figure out how. Creating my own provider was just too much work. So I decided to dive into the core code and here is what I came up with:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security.Membership;
using System.Web.Security;
using System.Threading;
using DotNetNuke.Common;
using DotNetNuke.Entities.Users;


namespace DotNetNuke.mymods.Modules.Membership
{
/// -----------------------------------------------------------------------------
///
/// The ViewMembership class displays the content
///

///
///

///
///

/// -----------------------------------------------------------------------------
partial class ViewMembership : PortalModuleBase, IActionable
{

#region Private Members

private string strTemplate;

#endregion

#region Public Methods

public bool DisplayAudit()
{
bool retValue = false;

if ((string)Settings["auditinfo"] == "Y")
{
retValue = true;
}

return retValue;
}

#endregion

#region Event Handlers

/// -----------------------------------------------------------------------------
///
/// Page_Load runs when the control is loaded
///

///
///

///
///

/// -----------------------------------------------------------------------------
protected void Page_Load(System.Object sender, System.EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}

}
public void btnRegister_Click(object sender, EventArgs e)
{
try
{

UserCreateStatus userstatus = UserCreateStatus.AddUser;
UserInfo NewUser = new UserInfo();
NewUser.PortalID = 0;
NewUser.FirstName = txtFirstName.Text;
NewUser.LastName = txtLastName.Text;
NewUser.Username = txtEmail.Text;
NewUser.DisplayName = txtFirstName.Text + " " + txtLastName.Text;
NewUser.Profile.City = txtCity.Text;
NewUser.Profile.Country = "United States";
NewUser.Email = txtEmail.Text;
NewUser.Username = txtEmail.Text;
NewUser.Membership.Password = txtNewPassword.Text;
NewUser.Profile.SetProfileProperty("State", ddlState.SelectedValue);

if (PortalSettings.UserRegistration == Convert.ToInt32(DotNetNuke.Common.Globals.PortalRegistrationType.PublicRegistration))
{
NewUser.Membership.Approved = true;
}
else
{
NewUser.Membership.Approved = false;
}

UserCreateStatus userstatsus = UserController.CreateUser(ref NewUser);
switch (userstatsus.ToString())
{
case "Success":
{
MessageCell.InnerHtml = "you have successfully registered";

break;
}
case "InvalidPassword":
{
MessageCell.InnerHtml = "Your password is too short";
break;
}

default:
MessageCell.InnerText = "" + userstatus.ToString() + "";
break;
}
}


//MessageCell.InnerText = userstatsus.ToString();

catch (Exception ex)
{
Console.Write(ex);
}

}

protected void lstContent_ItemDataBound(System.Object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
string strContent = strTemplate;
string strValue = Null.NullString;

//add content to template
ArrayList objProperties = CBO.GetPropertyInfo(typeof(MembershipInfo));
int intProperty;
foreach (PropertyInfo objPropertyInfo in objProperties)
{
if (strContent.IndexOf("[" + objPropertyInfo.Name.ToUpper() + "]") != -1)
{
strValue = Server.HtmlDecode(DataBinder.Eval(e.Item.DataItem, objPropertyInfo.Name).ToString());
strContent = strContent.Replace("[" + objPropertyInfo.Name.ToUpper() + "]", strValue);
}
}

//assign the content
Label lblContent = (Label)e.Item.FindControl("lblContent");
lblContent.Text = strContent;
}

#endregion

#region Optional Interfaces

/// -----------------------------------------------------------------------------
///
/// Registers the module actions required for interfacing with the portal framework
///

///
///
///
///
///

/// -----------------------------------------------------------------------------
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection Actions = new ModuleActionCollection();
Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl(), false, SecurityAccessLevel.Edit, true, false);
return Actions;
}
}

#endregion

}
}

Thursday, February 25, 2010

Best 404 Errors Ever

Great article over at the huffintonpost, vote for your favorite 404 page:

http://www.huffingtonpost.com/2010/02/11/best-404-error-pages-ever_n_456767.html

Agent Ransack an Awesome free tool!

Figure I should pass this on, especially to those that have found google desktop to be a hog and windows search not working as expected.

Many times I have found myself looking for that file, the text in the file, or occurrences of a term in multiple files.

For so long I delt with what I knew of, which wasn't much then stated above. Well, one day someone suggested this program to me called Agent Ransack.

The minute I installed it, I fell in love. It works so well and has helped me immensely, especially when it comes to diving into someone else's code. It not only tells you the files the term occurs in, it tells you the line numbers in the file (yuuuuuuuummmmm).

Anyway, I do not work for them, was never asked to review this, I just want to pass this on. You can download it for free here:

http://www.mythicsoft.com/agentransack/Page.aspx?page=download

ASP.NET FileUpload Web Control Issue in DotNetNuke

Today I uploaded a form which included an ASP.NET File Upload Control. At first glance it looked like everything was fine. It turns out, no matter what I did the controls hasfile property was false.

After some searching I came accross this on MSDN:

Note:
The FileUpload control is designed to be used only in postback scenarios and not in asynchronous postback scenarios during partial-page rendering. When you use a FileUpload control inside an UpdatePanel control, the file must be uploaded by using a control that is a PostBackTrigger object for the panel. UpdatePanel controls are used to update selected regions of a page instead of updating the whole page with a postback. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.


Well hmm, this is in dotnetnuke and in it's settings page which I know is an update panel this has to be my issue. So as a workaround and instead of using a PostBackTrigger, I decided to use the build in dnn upload control located in root/admin/files/webupload.asx.

Wednesday, February 24, 2010

Do you travel with your pet?

If so check out this site, great people and good application. They are a community for pet lovers alike. Hotel pet policies and booking all online. Great destination travel guide and an interesting road trip planner. Check them out and go pet friendly.

Plus, I personally did a bunch of work on this site and Amy and Rod are the best!

http://www.gopetfriendly.com

DotNetNuke Module Deployment

Yesterday I posted a DotNetNuke Module in DotNetNuke version 4.9.2. At that time, when I would bring up the page I put the module on, nothing but the skin would appear. I did the following to troubleshoot it:

  • Check code - exact match
  • Check DNN Event Log - clean
  • Look for errors - none
  • Restart Site - same issue
  • Check Windows Logs - clean
  • Bang Head against desk - same issue, although now I have a headache
Lastly, I decided to go line by line in the code to figure out where my module was failing and not causing any errors.

I am currently using an ASP.NET MultiView, which I populate using XSLT. The XSLT file I call when doing the transform had a local path, since the file was not found, the control don't load. Funny my try catch didn't work, but as soon as I changed the path to the XSLT file everything worked out fine.

Amazon1