// //======================================================================== // public static void processJoinForm(CoreController core) { try { string ErrorMessage = ""; string FirstName = null; string LastName = null; string FullName = null; string Email = null; int errorCode = 0; // string loginForm_Username = ""; string loginForm_Password = ""; loginForm_Username = core.docProperties.getText("username"); loginForm_Password = core.docProperties.getText("password"); // if (!GenericController.encodeBoolean(core.siteProperties.getBoolean("AllowMemberJoin", false))) { ErrorController.addUserError(core, "This site does not accept public main_MemberShip."); } else { if (!core.session.isNewCredentialOK(loginForm_Username, loginForm_Password, ref ErrorMessage, ref errorCode)) { ErrorController.addUserError(core, ErrorMessage); } else { if (!(!core.doc.userErrorList.Count.Equals(0))) { using (var csData = new CsModel(core)) { csData.open("people", "ID=" + DbController.encodeSQLNumber(core.session.user.id)); if (!csData.ok()) { LogController.logError(core, new Exception("Could not open the current members account to set the username and password.")); } else { if ((csData.getText("username") != "") || (csData.getText("password") != "") || (csData.getBoolean("admin")) || (csData.getBoolean("developer"))) { // // if the current account can be logged into, you can not join 'into' it // core.session.logout(); } FirstName = core.docProperties.getText("firstname"); LastName = core.docProperties.getText("lastname"); FullName = FirstName + " " + LastName; Email = core.docProperties.getText("email"); csData.set("FirstName", FirstName); csData.set("LastName", LastName); csData.set("Name", FullName); csData.set("username", loginForm_Username); csData.set("password", loginForm_Password); core.session.authenticateById(core.session.user.id, core.session); } csData.close(); } } } } PersonModel.invalidateCacheOfRecord <PersonModel>(core.cpParent, core.session.user.id); } catch (Exception ex) { LogController.logError(core, ex); throw; } }
// //==================================================================================================== /// <summary> /// Send the Member his username and password /// </summary> /// <param name="Email"></param> /// <returns></returns> public static bool sendPassword(CoreController core, string Email, ref string returnUserMessage) { bool result = false; returnUserMessage = ""; try { const string passwordChrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678999999"; const int passwordChrsLength = 62; // string workingEmail = GenericController.encodeText(Email); // string Message = ""; string FromAddress = ""; string subject = ""; if (string.IsNullOrEmpty(workingEmail)) { ErrorController.addUserError(core, "Please enter your email address before requesting your username and password."); } else { int atPtr = GenericController.strInstr(1, workingEmail, "@"); if (atPtr < 2) { // // email not valid // ErrorController.addUserError(core, "Please enter a valid email address before requesting your username and password."); } else { string EMailName = strMid(workingEmail, 1, atPtr - 1); // LogController.addSiteActivity(core, "password request for email " + workingEmail, core.session.user.id, core.session.user.organizationId); // bool allowEmailLogin = core.siteProperties.getBoolean("allowEmailLogin", false); int recordCnt = 0; using (var csData = new CsModel(core)) { string sqlCriteria = "(email=" + DbController.encodeSQLText(workingEmail) + ")"; sqlCriteria = sqlCriteria + "and((dateExpires is null)or(dateExpires>" + DbController.encodeSQLDate(core.dateTimeNowMockable) + "))"; csData.open("People", sqlCriteria, "ID", true, core.session.user.id, "username,password", 1); if (!csData.ok()) { // // valid login account for this email not found // if (encodeText(strMid(workingEmail, atPtr + 1)).ToLowerInvariant() == "contensive.com") { // // look for expired account to renew // csData.close(); csData.open("People", "((email=" + DbController.encodeSQLText(workingEmail) + "))", "ID"); if (csData.ok()) { // // renew this old record // csData.set("developer", "1"); csData.set("admin", "1"); if (csData.getDate("dateExpires") > DateTime.MinValue) { csData.set("dateExpires", core.dateTimeNowMockable.AddDays(7).Date.ToString()); } } else { // // inject support record // csData.close(); csData.insert("people"); csData.set("name", "Contensive Support"); csData.set("email", workingEmail); csData.set("developer", "1"); csData.set("admin", "1"); csData.set("dateExpires", core.dateTimeNowMockable.AddDays(7).Date.ToString()); } } else { ErrorController.addUserError(core, "No current user was found matching this email address. Please try again. "); } } if (csData.ok()) { FromAddress = core.siteProperties.getText("EmailFromAddress", "info@" + core.webServer.requestDomain); subject = "Password Request at " + core.webServer.requestDomain; Message = ""; while (csData.ok()) { bool updateUser = false; if (string.IsNullOrEmpty(Message)) { Message = "This email was sent in reply to a request at " + core.webServer.requestDomain + " for the username and password associated with this email address. "; Message += "If this request was made by you, please return to the login screen and use the following:\r\n"; Message += Environment.NewLine; } else { Message += Environment.NewLine; Message += "Additional user accounts with the same email address: \r\n"; } // // username // string Username = csData.getText("Username"); bool usernameOK = true; int Ptr = 0; if (!allowEmailLogin) { if (Username != Username.Trim()) { Username = Username.Trim(); updateUser = true; } if (string.IsNullOrEmpty(Username)) { usernameOK = false; Ptr = 0; while (!usernameOK && (Ptr < 100)) { Username = EMailName + encodeInteger(Math.Floor(encodeNumber(Microsoft.VisualBasic.VBMath.Rnd() * 9999))); usernameOK = !core.session.isLoginOK(Username, "test"); Ptr = Ptr + 1; } if (usernameOK) { updateUser = true; } } Message += " username: "******"Password"); if (Password.Trim() != Password) { Password = Password.Trim(); updateUser = true; } if (string.IsNullOrEmpty(Password)) { for (Ptr = 0; Ptr <= 8; Ptr++) { int Index = encodeInteger(Microsoft.VisualBasic.VBMath.Rnd() * passwordChrsLength); Password = Password + strMid(passwordChrs, Index, 1); } updateUser = true; } Message += " password: "******"username", Username); csData.set("password", Password); } recordCnt = recordCnt + 1; } csData.goNext(); } } } } } if (result) { string sendStatus = ""; EmailController.queueAdHocEmail(core, "Password Email", core.session.user.id, workingEmail, FromAddress, subject, Message, "", "", "", true, false, 0, ref sendStatus); } } catch (Exception ex) { LogController.logError(core, ex); throw; } return(result); }