//private static void UpdateProfile(UserInfo objUser, bool update) //{ // bool bUpdateUser = false; // if (ProfileProperties.Count > 0) // { // foreach (string key in ProfileProperties) // { // switch (key) // { // case "FirstName": // if (objUser.FirstName != ProfileProperties[key]) // { // objUser.FirstName = ProfileProperties[key]; // bUpdateUser = true; // } // break; // case "LastName": // if (objUser.LastName != ProfileProperties[key]) // { // objUser.LastName = ProfileProperties[key]; // bUpdateUser = true; // } // break; // case "Email": // if (objUser.Email != ProfileProperties[key]) // { // objUser.Email = ProfileProperties[key]; // bUpdateUser = true; // } // break; // case "DisplayName": // if (objUser.DisplayName != ProfileProperties[key]) // { // objUser.DisplayName = ProfileProperties[key]; // bUpdateUser = true; // } // break; // default: // objUser.Profile.SetProfileProperty(key, ProfileProperties[key]); // break; // } // } // if (update) // { // if (bUpdateUser) // { // UserController.UpdateUser(PortalSettings.Current.PortalId, objUser); // } // ProfileController.UpdateUserProfile(objUser); // } // } //} /// ----------------------------------------------------------------------------- /// <summary> /// ValidateUser runs when the user has been authorized by the data store. It validates for /// things such as an expiring password, valid profile, or missing DNN User Association /// </summary> /// <param name="objUser">The logged in User</param> /// <param name="ignoreExpiring">Ignore the situation where the password is expiring (but not yet expired)</param> /// ----------------------------------------------------------------------------- private static ActionResult ValidateUser(UserInfo objUser, bool ignoreExpiring) { ActionResult actionResult = new ActionResult(); UserValidStatus validStatus = UserValidStatus.VALID; string strMessage = Null.NullString; DateTime expiryDate = Null.NullDate; validStatus = UserController.ValidateUser(objUser, PortalSettings.Current.PortalId, ignoreExpiring); if (PasswordConfig.PasswordExpiry > 0) { expiryDate = objUser.Membership.LastPasswordChangeDate.AddDays(PasswordConfig.PasswordExpiry); } //Check if the User has valid Password/Profile switch (validStatus) { case UserValidStatus.VALID: //check if the user is an admin/host and validate their IP if (Host.EnableIPChecking) { bool isAdminUser = objUser.IsSuperUser || objUser.IsInRole(PortalSettings.Current.AdministratorRoleName); if (isAdminUser) { if (IPFilterController.Instance.IsIPBanned(HttpContext.Current.Request.UserHostAddress)) { PortalSecurity.Instance.SignOut(); actionResult.AddError("IPAddressBanned", Localization.GetString("IPAddressBanned", LocalResourceFile)); break; } } } //Set the Page Culture(Language) based on the Users Preferred Locale if ((objUser.Profile != null) && (objUser.Profile.PreferredLocale != null) && LocaleEnabled(objUser.Profile.PreferredLocale)) { Localization.SetLanguage(objUser.Profile.PreferredLocale); } else { Localization.SetLanguage(PortalSettings.Current.DefaultLanguage); } //Set the Authentication Type used AuthenticationController.SetAuthenticationType(AuthenticationType); //Complete Login IUserRequestIPAddressController userRequestIpAddressController = UserRequestIPAddressController.Instance; string ipAddress = userRequestIpAddressController.GetUserRequestIPAddress(new HttpRequestWrapper(HttpContext.Current.Request)); UserController.UserLogin(PortalSettings.Current.PortalId, objUser, PortalSettings.Current.PortalName, ipAddress, RememberMe); //check whether user request comes with IPv6 and log it to make sure admin is aware of that if (string.IsNullOrWhiteSpace(ipAddress)) { string ipAddressV6 = userRequestIpAddressController.GetUserRequestIPAddress(new HttpRequestWrapper(HttpContext.Current.Request), IPAddressFamily.IPv6); if (!string.IsNullOrWhiteSpace(ipAddressV6)) { AddEventLog(objUser.UserID, objUser.Username, PortalSettings.Current.PortalId, "IPv6", ipAddressV6); } } //redirect browser //var redirectUrl = RedirectURL; //Clear the cookie HttpContext.Current.Response.Cookies.Set(new HttpCookie("returnurl", "") { Expires = DateTime.Now.AddDays(-1), Path = (!string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/") }); actionResult.RedirectURL = GetRedirectUrl(); break; case UserValidStatus.PASSWORDEXPIRED: //strMessage = string.Format(Localization.GetString("PasswordExpired", LocalResourceFile), expiryDate.ToLongDateString()); //AddLocalizedModuleMessage(strMessage, ModuleMessage.ModuleMessageType.YellowWarning, true); actionResult.AddError("PASSWORDEXPIRED", string.Format(Localization.GetString("PasswordExpired", LocalResourceFile), expiryDate.ToLongDateString())); break; case UserValidStatus.PASSWORDEXPIRING: //strMessage = string.Format(Localization.GetString("PasswordExpiring", LocalResourceFile), expiryDate.ToLongDateString()); //AddLocalizedModuleMessage(strMessage, ModuleMessage.ModuleMessageType.YellowWarning, true); actionResult.AddError("PASSWORDEXPIRING", string.Format(Localization.GetString("PasswordExpiring", LocalResourceFile), expiryDate.ToLongDateString())); break; case UserValidStatus.UPDATEPASSWORD: string portalAlias = Globals.AddHTTP(PortalSettings.Current.PortalAlias.HTTPAlias); if (MembershipProviderConfig.PasswordRetrievalEnabled || MembershipProviderConfig.PasswordResetEnabled) { UserController.ResetPasswordToken(objUser); objUser = UserController.GetUserById(objUser.PortalID, objUser.UserID); } string redirTo = string.Format("{0}/default.aspx?ctl=PasswordReset&resetToken={1}&forced=true", portalAlias, objUser.PasswordResetToken); //Response.Redirect(redirTo); break; case UserValidStatus.UPDATEPROFILE: //Save UserID in ViewState so that can update profile later //When the user need update its profile to complete login, we need clear the login status because if the logrin is from //3rd party login provider, it may call UserController.UserLogin because they doesn't check this situation. actionResult.Data = new { UserExtensionURL = ServiceProvider.NavigationManager.NavigateURL("", "mid=0", "icp=true", "guid=fa7ca744-1677-40ef-86b2-ca409c5c6ed3#/updateprofile?uid=" + objUser.UserID) }; PortalSecurity.Instance.SignOut(); //Admin has forced profile update actionResult.AddError("ProfileUpdate", Localization.GetString("ProfileUpdate", LocalResourceFile)); break; case UserValidStatus.MUSTAGREETOTERMS: if (PortalSettings.Current.DataConsentConsentRedirect == -1) { //AddModuleMessage("MustConsent", ModuleMessage.ModuleMessageType.YellowWarning, true); actionResult.AddError("MUSTAGREETOTERMS", string.Format(Localization.GetString("MustConsent", LocalResourceFile), expiryDate.ToLongDateString())); } else { // Use the reset password token to identify the user during the redirect UserController.ResetPasswordToken(objUser); objUser = UserController.GetUserById(objUser.PortalID, objUser.UserID); actionResult.RedirectURL = ServiceProvider.NavigationManager.NavigateURL(PortalSettings.Current.DataConsentConsentRedirect, "", string.Format("token={0}", objUser.PasswordResetToken)); } break; } return(actionResult); }
protected static ActionResult CompleteUserCreation(UserCreateStatus createStatus, UserInfo newUser, bool notify, bool register) { ActionResult actionResult = new ActionResult(); string strMessage = ""; ModuleMessage.ModuleMessageType message = ModuleMessage.ModuleMessageType.RedError; if (register) { //send notification to portal administrator of new user registration //check the receive notification setting first, but if register type is Private, we will always send the notification email. //because the user need administrators to do the approve action so that he can continue use the website. if (PortalSettings.Current.EnableRegisterNotification || PortalSettings.Current.UserRegistration == (int)Globals.PortalRegistrationType.PrivateRegistration) { strMessage += Mail.SendMail(newUser, MessageType.UserRegistrationAdmin, PortalController.Instance.GetCurrentSettings() as PortalSettings); SendAdminNotification(newUser, PortalController.Instance.GetCurrentSettings() as PortalSettings); } UserLoginStatus loginStatus = UserLoginStatus.LOGIN_FAILURE; //complete registration switch (PortalSettings.Current.UserRegistration) { case (int)Globals.PortalRegistrationType.PrivateRegistration: strMessage += Mail.SendMail(newUser, MessageType.UserRegistrationPrivate, PortalController.Instance.GetCurrentSettings() as PortalSettings); //show a message that a portal administrator has to verify the user credentials if (string.IsNullOrEmpty(strMessage)) { strMessage += Localization.GetString("PrivateConfirmationMessage", Localization.SharedResourceFile); message = ModuleMessage.ModuleMessageType.GreenSuccess; } break; case (int)Globals.PortalRegistrationType.PublicRegistration: Mail.SendMail(newUser, MessageType.UserRegistrationPublic, PortalController.Instance.GetCurrentSettings() as PortalSettings); UserController.UserLogin(PortalSettings.Current.PortalId, newUser.Username, newUser.Membership.Password, "", PortalSettings.Current.PortalName, "", ref loginStatus, false); break; case (int)Globals.PortalRegistrationType.VerifiedRegistration: Mail.SendMail(newUser, MessageType.UserRegistrationVerified, PortalController.Instance.GetCurrentSettings() as PortalSettings); UserController.UserLogin(PortalSettings.Current.PortalId, newUser.Username, newUser.Membership.Password, "", PortalSettings.Current.PortalName, "", ref loginStatus, false); break; } //store preferredlocale in cookie Localization.SetLanguage(newUser.Profile.PreferredLocale); if (!(HttpContext.Current.Request.IsAuthenticated && PortalSecurity.IsInRole(PortalSettings.Current.AdministratorRoleName)) && !(HttpContext.Current.Request.IsAuthenticated && (newUser.UserID == (PortalController.Instance.GetCurrentSettings() as PortalSettings).UserInfo.UserID)) && message == ModuleMessage.ModuleMessageType.RedError) { //HS Skin Messages //actionResult.AddError("SendMail_Error", string.Format(Localization.GetString("SendMail.Error", Localization.SharedResourceFile), newUser.Email)); Exceptions.LogException(new Exception("Skin Messages : " + string.Format(Localization.GetString("SendMail.Error", Localization.SharedResourceFile), newUser.Email))); actionResult.Message = strMessage; } else { if (message == ModuleMessage.ModuleMessageType.RedError) { actionResult.AddError("CompleteUserCreation", strMessage); } else { actionResult.Message = strMessage; } } } else { if (notify) { //Send Notification to User if (PortalSettings.Current.UserRegistration == (int)Globals.PortalRegistrationType.VerifiedRegistration) { strMessage += Mail.SendMail(newUser, MessageType.UserRegistrationVerified, PortalController.Instance.GetCurrentSettings() as PortalSettings); } else { strMessage += Mail.SendMail(newUser, MessageType.UserRegistrationPublic, PortalController.Instance.GetCurrentSettings() as PortalSettings); } } } actionResult.Message = strMessage; return(actionResult); }