Exemple #1
0
        //
        //========================================================================
        /// <summary>
        /// Process the login form username and password
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        public static bool processLoginFormDefault(CoreController core)
        {
            bool returnResult = false;

            try {
                //
                if ((core.session.visit.loginAttempts < core.siteProperties.maxVisitLoginAttempts) && core.session.visit.cookieSupport)
                {
                    int LocalMemberId = core.session.getUserIdForUsernameCredentials(
                        core.docProperties.getText("username"),
                        core.docProperties.getText("password")
                        );
                    if (LocalMemberId == 0)
                    {
                        if ((core.session.isAuthenticated) || (core.session.isRecognized()))
                        {
                            core.session.logout();
                        }
                        core.session.visit.loginAttempts = core.session.visit.loginAttempts + 1;
                        core.session.visit.save(core.cpParent);
                    }
                    else
                    {
                        returnResult = core.session.authenticateById(LocalMemberId, core.session);
                        if (returnResult)
                        {
                            LogController.addSiteActivity(core, "successful username/password login", core.session.user.id, core.session.user.organizationId);
                        }
                        else
                        {
                            LogController.addSiteActivity(core, "bad username/password login", core.session.user.id, core.session.user.organizationId);
                        }
                    }
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Exemple #2
0
        //
        //====================================================================================================
        /// <summary>
        /// Process manual changes needed for special cases
        /// </summary>
        /// <param name="isDelete"></param>
        /// <param name="contentName"></param>
        /// <param name="recordId"></param>
        /// <param name="recordName"></param>
        /// <param name="recordParentID"></param>
        /// <param name="useContentWatchLink"></param>
        public static void processAfterSave(CoreController core, bool isDelete, string contentName, int recordId, string recordName, int recordParentID, bool useContentWatchLink)
        {
            try {
                PageContentModel.markReviewed(core.cpParent, recordId);
                string tableName = MetadataController.getContentTablename(core, contentName);
                //
                // -- invalidate the specific cache for this record
                core.cache.invalidateDbRecord(recordId, tableName);
                //
                string tableNameLower = tableName.ToLower(CultureInfo.InvariantCulture);
                if (tableNameLower == AddonCollectionModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- addon collection
                    processAfterSave_AddonCollection(core, isDelete, contentName, recordId, recordName, recordParentID, useContentWatchLink);
                }
                else if (tableNameLower == LinkForwardModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- link forward
                    core.routeMapCacheClear();
                }
                else if (tableNameLower == LinkAliasModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- link alias
                    core.routeMapCacheClear();
                }
                else if (tableNameLower == AddonModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- addon
                    core.routeMapCacheClear();
                }
                else if (tableNameLower == PersonModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- PersonModel
                    var person = PersonModel.create <PersonModel>(core.cpParent, recordId);
                    if (person != null)
                    {
                        if (isDelete)
                        {
                            LogController.addSiteActivity(core, "deleting user #" + recordId + " (" + recordName + ")", recordId, person.organizationId);
                        }
                        else
                        {
                            LogController.addSiteActivity(core, "saving changes to user #" + recordId + " (" + recordName + ")", recordId, person.organizationId);
                        }
                    }
                }
                else if (tableNameLower == OrganizationModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- Log Activity for changes to people and organizattions
                    if (isDelete)
                    {
                        LogController.addSiteActivity(core, "deleting organization #" + recordId + " (" + recordName + ")", 0, recordId);
                    }
                    else
                    {
                        LogController.addSiteActivity(core, "saving changes to organization #" + recordId + " (" + recordName + ")", 0, recordId);
                    }
                }
                else if (tableNameLower == SitePropertyModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- Site Properties
                    switch (GenericController.toLCase(recordName))
                    {
                    case "allowlinkalias":
                        PageContentModel.invalidateCacheOfTable <PageContentModel>(core.cpParent);
                        break;

                    case "sectionlandinglink":
                        PageContentModel.invalidateCacheOfTable <PageContentModel>(core.cpParent);
                        break;

                    case Constants._siteproperty_serverPageDefault_name:
                        PageContentModel.invalidateCacheOfTable <PageContentModel>(core.cpParent);
                        break;
                    }
                }
                else if (tableNameLower == PageContentModel.tableMetadata.tableNameLower)
                {
                    //
                    // -- set ChildPagesFound true for parent page
                    if (recordParentID > 0)
                    {
                        if (!isDelete)
                        {
                            core.db.executeNonQuery("update ccpagecontent set ChildPagesfound=1 where ID=" + recordParentID);
                        }
                    }
                    if (isDelete)
                    {
                        //
                        // Clear the Landing page and page not found site properties
                        if (recordId == GenericController.encodeInteger(core.siteProperties.getText("PageNotFoundPageID", "0")))
                        {
                            core.siteProperties.setProperty("PageNotFoundPageID", "0");
                        }
                        if (recordId == core.siteProperties.landingPageID)
                        {
                            core.siteProperties.setProperty("landingPageId", "0");
                        }
                        //
                        // Delete Link Alias entries with this PageID
                        core.db.executeNonQuery("delete from cclinkAliases where PageID=" + recordId);
                    }
                    DbBaseModel.invalidateCacheOfRecord <PageContentModel>(core.cpParent, recordId);
                }
                else if (tableNameLower == LibraryFilesModel.tableMetadata.tableNameLower)
                {
                    //
                    // --
                    processAfterSave_LibraryFiles(core, isDelete, contentName, recordId, recordName, recordParentID, useContentWatchLink);
                }
                //
                // Process Addons marked to trigger a process call on content change
                //
                Dictionary <string, string> instanceArguments;
                bool onChangeAddonsAsync = core.siteProperties.getBoolean("execute oncontentchange addons async", false);
                using (var csData = new CsModel(core)) {
                    int contentId = ContentMetadataModel.getContentId(core, contentName);
                    csData.open("Add-on Content Trigger Rules", "ContentID=" + contentId, "", false, 0, "addonid");
                    string Option_String = null;
                    if (isDelete)
                    {
                        instanceArguments = new Dictionary <string, string> {
                            { "action", "contentdelete" },
                            { "contentid", contentId.ToString() },
                            { "recordid", recordId.ToString() }
                        };
                        Option_String = ""
                                        + Environment.NewLine + "action=contentdelete"
                                        + Environment.NewLine + "contentid=" + contentId
                                        + Environment.NewLine + "recordid=" + recordId + "";
                    }
                    else
                    {
                        instanceArguments = new Dictionary <string, string> {
                            { "action", "contentchange" },
                            { "contentid", contentId.ToString() },
                            { "recordid", recordId.ToString() }
                        };
                        Option_String = ""
                                        + Environment.NewLine + "action=contentchange"
                                        + Environment.NewLine + "contentid=" + contentId
                                        + Environment.NewLine + "recordid=" + recordId + "";
                    }
                    while (csData.ok())
                    {
                        var addon = DbBaseModel.create <AddonModel>(core.cpParent, csData.getInteger("Addonid"));
                        if (addon != null)
                        {
                            if (onChangeAddonsAsync)
                            {
                                //
                                // -- execute addon async
                                core.addon.executeAsync(addon, instanceArguments);
                            }
                            else
                            {
                                //
                                // -- execute addon
                                core.addon.execute(addon, new CPUtilsBaseClass.addonExecuteContext {
                                    addonType             = CPUtilsBaseClass.addonContext.ContextOnContentChange,
                                    backgroundProcess     = false,
                                    errorContextMessage   = "",
                                    argumentKeyValuePairs = instanceArguments
                                });
                            }
                        }
                        csData.goNext();
                    }
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
        }
Exemple #3
0
        //
        //====================================================================================================
        /// <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);
        }