public virtual void AuthenticateUser(UserData user, PortalSettings settings, string IPAddress, Action <NameValueCollection> addCustomProperties, Action <UserAuthenticatedEventArgs> onAuthenticated) { var loginStatus = UserLoginStatus.LOGIN_FAILURE; var objUserInfo = UserController.ValidateUser(settings.PortalId, user.Id, string.Empty, _service, string.Empty, settings.PortalName, IPAddress, ref loginStatus); // Raise UserAuthenticated Event var eventArgs = new UserAuthenticatedEventArgs(objUserInfo, user.Id, loginStatus, _service) { AutoRegister = true }; // TODO: var profileProperties = new NameValueCollection(); if (string.IsNullOrEmpty(objUserInfo?.FirstName) && !string.IsNullOrEmpty(user.FirstName)) { profileProperties.Add("FirstName", user.FirstName); } if (string.IsNullOrEmpty(objUserInfo?.LastName) && !string.IsNullOrEmpty(user.LastName)) { profileProperties.Add("LastName", user.LastName); } if (string.IsNullOrEmpty(objUserInfo?.Email) && !string.IsNullOrEmpty(user.Email)) { profileProperties.Add("Email", user.Email); } if (string.IsNullOrEmpty(objUserInfo?.DisplayName) && !string.IsNullOrEmpty(user.DisplayName)) { profileProperties.Add("DisplayName", user.DisplayName); } if (string.IsNullOrEmpty(objUserInfo?.Profile.GetPropertyValue("Website")) && !string.IsNullOrEmpty(user.Website)) { profileProperties.Add("Website", user.Website); } if (string.IsNullOrEmpty(objUserInfo?.Profile.GetPropertyValue("PreferredLocale")) && !string.IsNullOrEmpty(user.Locale)) { if (LocaleController.IsValidCultureName(user.Locale.Replace('_', '-'))) { profileProperties.Add("PreferredLocale", user.Locale.Replace('_', '-')); } else { profileProperties.Add("PreferredLocale", settings.CultureCode); } } //if (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("PreferredTimeZone")))) //{ // if (string.IsNullOrEmpty(user.TimeZoneInfo)) // { // if (Int32.TryParse(user.Timezone, out int timeZone)) // { // var timeZoneInfo = Localization.ConvertLegacyTimeZoneOffsetToTimeZoneInfo(timeZone); // profileProperties.Add("PreferredTimeZone", timeZoneInfo.Id); // } // } // else // { // profileProperties.Add("PreferredTimeZone", user.TimeZoneInfo); // } //} addCustomProperties(profileProperties); eventArgs.Profile = profileProperties; onAuthenticated(eventArgs); }
public virtual void AuthenticateUser(UserData user, PortalSettings settings, string IPAddress, Action <NameValueCollection> addCustomProperties, Action <UserAuthenticatedEventArgs> onAuthenticated) { var loginStatus = UserLoginStatus.LOGIN_FAILURE; string userName = PrefixServiceToUserName ? Service + "-" + user.Id : user.Id; string token = Service + "-" + user.Id; UserInfo objUserInfo; if (AutoMatchExistingUsers) { objUserInfo = MembershipProvider.Instance().GetUserByUserName(settings.PortalId, userName); if (objUserInfo != null) { //user already exists... lets check for a token next... var dnnAuthToken = MembershipProvider.Instance().GetUserByAuthToken(settings.PortalId, token, Service); if (dnnAuthToken == null) { DataProvider.Instance().AddUserAuthentication(objUserInfo.UserID, Service, token, objUserInfo.UserID); } } } objUserInfo = UserController.ValidateUser(settings.PortalId, userName, "", Service, token, settings.PortalName, IPAddress, ref loginStatus); //Raise UserAuthenticated Event var eventArgs = new UserAuthenticatedEventArgs(objUserInfo, token, loginStatus, Service) { AutoRegister = true, UserName = userName, }; var profileProperties = new NameValueCollection(); if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.FirstName) && !string.IsNullOrEmpty(user.FirstName))) { profileProperties.Add("FirstName", user.FirstName); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.LastName) && !string.IsNullOrEmpty(user.LastName))) { profileProperties.Add("LastName", user.LastName); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Email) && !string.IsNullOrEmpty(user.Email))) { profileProperties.Add("Email", user.PreferredEmail); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.DisplayName) && !string.IsNullOrEmpty(user.DisplayName))) { profileProperties.Add("DisplayName", user.DisplayName); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("ProfileImage")) && !string.IsNullOrEmpty(user.ProfileImage))) { profileProperties.Add("ProfileImage", user.ProfileImage); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("Website")) && !string.IsNullOrEmpty(user.Website))) { profileProperties.Add("Website", user.Website); } if ((objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("PreferredLocale")))) && !string.IsNullOrEmpty(user.Locale)) { if (LocaleController.IsValidCultureName(user.Locale.Replace('_', '-'))) { profileProperties.Add("PreferredLocale", user.Locale.Replace('_', '-')); } else { profileProperties.Add("PreferredLocale", settings.CultureCode); } } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("PreferredTimeZone")))) { if (String.IsNullOrEmpty(user.TimeZoneInfo)) { int timeZone; if (Int32.TryParse(user.Timezone, out timeZone)) { var timeZoneInfo = Localization.Localization.ConvertLegacyTimeZoneOffsetToTimeZoneInfo(timeZone); profileProperties.Add("PreferredTimeZone", timeZoneInfo.Id); } } else { profileProperties.Add("PreferredTimeZone", user.TimeZoneInfo); } } addCustomProperties(profileProperties); eventArgs.Profile = profileProperties; if (Mode == AuthMode.Login) { SaveTokenCookie(String.Empty); } onAuthenticated(eventArgs); }
public virtual void AuthenticateUser(UserData user, PortalSettings settings, string IPAddress, Action <NameValueCollection> addCustomProperties, Action <UserAuthenticatedEventArgs> onAuthenticated) { var loginStatus = UserLoginStatus.LOGIN_FAILURE; string userName = Service + "-" + user.Id; var objUserInfo = UserController.ValidateUser(settings.PortalId, userName, "", Service, "", settings.PortalName, IPAddress, ref loginStatus); //Raise UserAuthenticated Event var eventArgs = new UserAuthenticatedEventArgs(objUserInfo, userName, loginStatus, Service) { AutoRegister = true }; var profileProperties = new NameValueCollection(); if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.FirstName) && !string.IsNullOrEmpty(user.FirstName))) { profileProperties.Add("FirstName", user.FirstName); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.LastName) && !string.IsNullOrEmpty(user.LastName))) { profileProperties.Add("LastName", user.LastName); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Email) && !string.IsNullOrEmpty(user.Email))) { profileProperties.Add("Email", user.PreferredEmail); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.DisplayName) && !string.IsNullOrEmpty(user.DisplayName))) { profileProperties.Add("DisplayName", user.DisplayName); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("ProfileImage")) && !string.IsNullOrEmpty(user.ProfileImage))) { profileProperties.Add("ProfileImage", user.ProfileImage); } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("Website")) && !string.IsNullOrEmpty(user.Website))) { profileProperties.Add("Website", user.Website); } if ((objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("PreferredLocale")))) && !string.IsNullOrEmpty(user.Locale)) { if (LocaleController.IsValidCultureName(user.Locale.Replace('_', '-'))) { profileProperties.Add("PreferredLocale", user.Locale.Replace('_', '-')); } else { profileProperties.Add("PreferredLocale", settings.CultureCode); } } if (objUserInfo == null || (string.IsNullOrEmpty(objUserInfo.Profile.GetPropertyValue("PreferredTimeZone")))) { if (String.IsNullOrEmpty(user.TimeZoneInfo)) { int timeZone; if (Int32.TryParse(user.Timezone, out timeZone)) { var timeZoneInfo = Localization.Localization.ConvertLegacyTimeZoneOffsetToTimeZoneInfo(timeZone); profileProperties.Add("PreferredTimeZone", timeZoneInfo.Id); } } else { profileProperties.Add("PreferredTimeZone", user.TimeZoneInfo); } } addCustomProperties(profileProperties); eventArgs.Profile = profileProperties; if (Mode == AuthMode.Login) { SaveTokenCookie(String.Empty); } onAuthenticated(eventArgs); }