Hi,
I'm trying to create a very simple web application that uses DNN user authentication. It means that a registered user of my DNN portal, should be able to log in to my web application using his/her portal userid and passw. So my web-app needs to ask somehow DNN if the userid and passw given by the user is correct or not. Here is what I have done so far:
1. Checked Signin.ascx.vb to see what's happening there, when clicking the login button of a DNN Portal (see code attached to the end of this message)
2. Created a C# website (application) project in VS2005
3. Added a reference to my project for dotnetnuke.dll
4. Added the code below to my Page_Load function
5. Running the application I got exceptions like:
The type initializer for 'DotNetNuke.Entities.Users.UserController' threw an exception.
The type initializer for 'DotNetNuke.Services.Cache.CachingProvider' threw an exception.
I'm quite sure I missed a few steps. I have never done anything similar before, and totally no idea what to do, please take a look at the codes below, I would really appreciate any guidlines to this!
Thanks!
Örs Téglásy
C# code from my demo webapp, trying to ask DNN to check userid and passw:
using DotNetNuke;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "before try";
try
{
DotNetNuke.Entities.Users.UserInfo dnnUserInfo = new DotNetNuke.Entities.Users.UserInfo();
DotNetNuke.Security.Membership.UserLoginStatus dnnUserLoginStatus = new DotNetNuke.Security.Membership.UserLoginStatus();
String ipAddress = Request.UserHostAddress;
//String veriCode = Request.QueryString["verificationcode"];
String portalName = DotNetNuke.Entities.Portals.PortalSettings.GetPortalByID(0, "");
dnnUserInfo = DotNetNuke.Entities.Users.UserController.ValidateUser(0, "johnsmith", "abc1234", "", portalName , ipAddress, ref dnnUserLoginStatus);
Label1.Text = dnnUserInfo.DisplayName;
}
catch (TypeInitializationException ex)
{
Label1.Text = "in catch: " + ex.Message;
}
}
}
This is the code from Signin.ascx.vb, to see what's happening there when you click the login button:
Private Sub cmdLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdLogin.Click
If (UseCaptcha And ctlCaptcha.IsValid) OrElse (Not UseCaptcha) Then
'Try to validate user
Dim loginStatus As UserLoginStatus
Dim objUser As UserInfo = UserController.ValidateUser(PortalId, txtUsername.Text, txtPassword.Text, txtVerification.Text, PortalSettings.PortalName, ipAddress, loginStatus)
If objUser Is Nothing Then 'Some kind of Login failure
If loginStatus = UserLoginStatus.LOGIN_FAILURE Then
'Try Windows Authorization
'(user may be authorized in Windows, but not in DNN yet)
objUser = WindowsAuthorization(loginStatus)
End If
End If
If objUser Is Nothing Then
Select Case loginStatus
Case UserLoginStatus.LOGIN_USERNOTAPPROVED
'Check if its the first time logging in to a verified site
If PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
If Not rowVerification1.Visible Then
'Display Verification Rows so User can enter verification code
rowVerification1.Visible = True
rowVerification2.Visible = True
Else
If txtVerification.Text <> "" Then
AddModuleMessage("InvalidCode", ModuleMessageType.RedError, True)
Else
AddModuleMessage("EnterCode", ModuleMessageType.GreenSuccess, True)
End If
End If
End If
Case UserLoginStatus.LOGIN_USERLOCKEDOUT
AddModuleMessage("UserLockedOut", ModuleMessageType.RedError, True)
' notify administrator about account lockout ( possible hack attempt )
Dim Custom As New ArrayList
Custom.Add(txtUsername.Text)
Mail.SendMail(PortalSettings.Email, PortalSettings.Email, "", _
Localization.GetSystemMessage(PortalSettings, "EMAIL_USER_LOCKOUT_SUBJECT", Localization.GlobalResourceFile, Custom), _
Localization.GetSystemMessage(PortalSettings, "EMAIL_USER_LOCKOUT_BODY", Localization.GlobalResourceFile, Custom), _
"", "", "", "", "", "")
Case UserLoginStatus.LOGIN_FAILURE
AddModuleMessage("LoginFailed", ModuleMessageType.RedError, True)
End Select
Else 'Login Success
UserAuthorized(objUser, False)
End If
End If
End Sub