public UserCreateStatus AddDNNUser(UserInfo AuthenticationUser) { PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings(); PortalSecurity objSecurity = new PortalSecurity(); Entities.Users.UserController objDNNUsers = new Entities.Users.UserController(); UserController objAuthUsers = new UserController(); Entities.Users.UserInfo objDNNUser = (Entities.Users.UserInfo)AuthenticationUser; int AffiliateId = -1; if (HttpContext.Current.Request.Cookies["AffiliateId"] != null) { AffiliateId = int.Parse(HttpContext.Current.Request.Cookies["AffiliateId"].Value); } int UserID = -1; UserCreateStatus createStatus; createStatus = Entities.Users.UserController.CreateUser(ref objDNNUser); UserID = objDNNUser.UserID; if (AuthenticationUser.AuthenticationExists && UserID > -1) { AuthenticationUser.UserID = UserID; AddUserRoles(_portalSettings.PortalId, AuthenticationUser); } return createStatus; }
public UserInfo ProcessFormAuthentication( string loggedOnUserName, string loggedOnPassword ) //DotNetNuke.Entities.Users.UserInfo { Configuration configuration = Configuration.GetConfig(); UserController objAuthUserController = new UserController(); if( configuration.WindowsAuthentication ) { UserInfo objAuthUser = objAuthUserController.GetUser( loggedOnUserName, loggedOnPassword ); return objAuthUser; } return null; //Return -1 }
public void AuthenticationLogon() { Configuration configuration = Configuration.GetConfig(); UserController authUserController = new UserController(); string authCookies = Configuration.AUTHENTICATION_KEY + "_" + _portalSettings.PortalId; string LoggedOnUserName = HttpContext.Current.Request.ServerVariables[Configuration.LOGON_USER_VARIABLE]; // HACK : Modified to not error if object is null. //if( LoggedOnUserName.Length > 0 ) if (!String.IsNullOrEmpty(LoggedOnUserName)) { UserInfo authUser; int intUserId = 0; Entities.Users.UserInfo dnnUser = Entities.Users.UserController.GetUserByName( _portalSettings.PortalId, LoggedOnUserName, false ); if( dnnUser != null ) { intUserId = dnnUser.UserID; // Synchronize role membership if it's required in settings if( configuration.SynchronizeRole ) { authUser = authUserController.GetUser( LoggedOnUserName ); // user object might be in simple version in none active directory network if( authUser.GUID.Length != 0 ) { authUser.UserID = intUserId; UserController.AddUserRoles( _portalSettings.PortalId, authUser ); } } } else { // User not exists in DNN database, obtain user info from provider to add new authUser = authUserController.GetUser( LoggedOnUserName ); if( authUser != null ) { authUserController.AddDNNUser( authUser ); intUserId = authUser.UserID; SetStatus( _portalSettings.PortalId, AuthenticationStatus.WinLogon ); } } if( intUserId > 0 ) { FormsAuthentication.SetAuthCookie( Convert.ToString( LoggedOnUserName ), true ); //check if user has supplied custom value for expiration int PersistentCookieTimeout = 0; if (Config.GetSetting("PersistentCookieTimeout") != null) { PersistentCookieTimeout = int.Parse(Config.GetSetting("PersistentCookieTimeout")); //only use if non-zero, otherwise leave as asp.net value if (PersistentCookieTimeout != 0) { //locate and update cookie string authCookie = FormsAuthentication.FormsCookieName; foreach (string cookie in HttpContext.Current.Response.Cookies) { if (cookie.Equals(authCookie)) { HttpContext.Current.Response.Cookies[cookie].Expires = DateTime.Now.AddMinutes(PersistentCookieTimeout); } } } } SetStatus( _portalSettings.PortalId, AuthenticationStatus.WinLogon ); // Get ipAddress for eventLog string ipAddress = ""; if( HttpContext.Current.Request.UserHostAddress != null ) { ipAddress = HttpContext.Current.Request.UserHostAddress; } EventLogController eventLog = new EventLogController(); LogInfo eventLogInfo = new LogInfo(); eventLogInfo.AddProperty( "IP", ipAddress ); eventLogInfo.LogPortalID = _portalSettings.PortalId; eventLogInfo.LogPortalName = _portalSettings.PortalName; eventLogInfo.LogUserID = intUserId; eventLogInfo.LogUserName = LoggedOnUserName; eventLogInfo.AddProperty( "WindowsAuthentication", "True" ); eventLogInfo.LogTypeKey = "LOGIN_SUCCESS"; eventLog.AddLog( eventLogInfo ); } } else { // Not Windows Authentication } // params "logon=windows" does nothing, just to force page to be refreshed string strURL = Globals.NavigateURL( _portalSettings.ActiveTab.TabID, "", "logon=windows" ); HttpContext.Current.Response.Redirect( strURL, true ); }