Esempio n. 1
0
        public void RemoteTwitchLogin(Security s, string username, ref string pCode)
        {
            if (username.ToLower().EndsWith("@beweb.co.nz"))
            {
                var remoteLogin         = "******";
                var isRemoteLoginOnline = false;

                try {
                    var twitchKey = Util.GetSetting("TwitchKey", "dsigbsd9uFSdsg897gasiu%%$#*gas79%*gakisfaf");
                    remoteLogin         = Http.Get("http://twitch.beweb.co.nz/Security/RemoteLogin?EncEmail=" + Crypto.Encrypt(username, twitchKey) + "&EncPassword="******"&EncRemembered=" + Crypto.Encrypt(Crypto.Decrypt(pCode), twitchKey));
                    isRemoteLoginOnline = true;
                } catch { }

                var localPerson  = new ActiveRecord(Security.PersonTableName, Security.PersonTableName + "ID");
                var personExists = localPerson.LoadData(new Sql("where Email = ", username.SqlizeText()));

                // If twitch is online and rejects the user login, then setup to fail the login
                if (isRemoteLoginOnline && remoteLogin == "Failed")
                {
                    pCode           = "invalid user " + Crypto.Random();
                    s.ResultMessage = "Invalid Twitch login";

                    if (personExists)
                    {
                        localPerson["IsActive"].ValueObject = false;
                        localPerson.Save();
                    }
                }

                if (remoteLogin != "Failed")
                {
                    if (!personExists)
                    {
                        localPerson["FirstName"].ValueObject = remoteLogin.Split("|")[0];
                        localPerson["LastName"].ValueObject  = remoteLogin.Split("|")[1] + "*";
                        localPerson["Email"].ValueObject     = username;
                        localPerson["Role"].ValueObject      = "administrators,superadmins,developers";
                        localPerson["Password"].ValueObject  = Security.CreateSecuredPassword(RandomPassword.Generate(5, 7));
                        localPerson["IsActive"].ValueObject  = true;
                        localPerson.Save();

                        s.ResultMessage = "Logged in via Twitch";
                    }
                    else
                    {
                        // log user in with existing account
                        localPerson["IsActive"].ValueObject = true;
                        localPerson.Save();
                        s.ResultMessage = "Logged in via Twitch, using local person";
                    }

                    pCode = Security.DecryptPassword(localPerson["Password"].ToString());
                }
            }
        }
Esempio n. 2
0
    /// <summary>
    /// The Subscribe page must call this function if Request["optin"]!=null to provide the completion of double opt in.
    /// </summary>
    /// <example>if (Request["optin"]!=null) { Models.TextBlock myTextBlock = VerificationLinkClicked(Request["optin"]) }</example>
    /// <param name="optInCode">You need to pass in Request["optin"]</param>
    /// <returns>Returns a Models.TextBlock containing the title and body text to be displayed to the user</returns>
    public static Models.TextBlock VerificationLinkClicked(string optInCode)
    {
        Models.TextBlock textBlock;
        //Web.Write("optinCode: "+Crypto.DecryptID(optInCode));
        //Web.End();
        //var person = Person.LoadID(Crypto.DecryptID(optInCode));
        var person = new ActiveRecord <int>("Person", "PersonID");

        AssertFieldsExist(person);
        bool exists = person.LoadID(Crypto.DecryptID(optInCode));

        if (!exists)
        {
            // not on database, show error
            // get text to display on screen
            textBlock = Models.TextBlock.LoadBySectionCode("Double_OptIn_Error");
            // create if not found
            if (textBlock == null)
            {
                textBlock = new Models.TextBlock {
                    SectionCode      = "Double_OptIn_Error",
                    Title            = "Problem with confirmation link",
                    IsTitleAvailable = true,
                    IsBodyPlainText  = false,
                    BodyTextHtml     = "Sorry, the link you clicked did not work. Your record was not found in our database.<br><br>If you would like to subscribe to our email newsletter, please use the subscribe panel on the right and try the process again."
                };

                textBlock.Save();
            }
        }
        else
        {
            // opt in
            person["SubscribeDate"].ValueObject     = DateTime.Now;
            person["HasValidatedEmail"].ValueObject = true;
            person.Save();

            // get text to display on screen
            textBlock = Models.TextBlock.LoadBySectionCode("Double_OptIn_Confirmed");
            // create if not found
            if (textBlock == null)
            {
                textBlock = new Models.TextBlock {
                    SectionCode      = "Double_OptIn_Confirmed",
                    IsBodyPlainText  = false,
                    IsTitleAvailable = true,
                    Title            = "Subscribe Confirmed",
                    BodyTextHtml     = "Thanks very much for confirming your subscription.<br><br>You are now subscribed to our email newsletter."
                };
                textBlock.Save();
            }
        }
        return(textBlock);
    }
Esempio n. 3
0
                //public class GalleryCategoryYearsViewModel {
                //	public Page ContentPage;
                //}

        //public ActionResult GalleryCategoryYears(Page contentPage) {
        //	var model = new GalleryCategoryYearsViewModel();
        //	model.ContentPage = contentPage;
        //	return View(model);
        //}
#endif

        public ActionResult TrackingGif(string guid)
        {
            var sql    = new Sql("select * from MailLog where TrackingGuid = ", guid.SqlizeText());
            var record = new ActiveRecord("MailLog", "MailLogID");

            if (record.LoadData(sql))
            {
                record["DateViewTracked"].ValueObject = DateTime.Now;
                record.Save();
            }
            var str   = "R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
            var bytes = Convert.FromBase64String(str);

            Response.Clear();
            Response.ContentType = "image/gif";
            Response.BinaryWrite(bytes);
            return(null);
        }
Esempio n. 4
0
    /// <summary>
    /// When a new person subscribes, you need to add a Person record for them (using Models.Person) and complete all the fields you have data for, then pass it to this method.
    /// This method sends an email to the person asking them to click a link.
    /// The final part of double opt in is when the link is clicked.  The link takes them back to the Subscribe page with a URL parameter of "optin=[encryptedid]", and you need to call VerificationLinkClicked(Request["optin"]).
    /// </summary>
    /// <param name="person">A Models.Person object with email address and any other fields completed.</param>
    /// <param name="subscribePageFileName">File name of subscribe or optin page that calls VerificationLinkClicked (may include path from site root, may start with ~)</param>
    public static void SendVerificationEmail(ActiveRecord person, string subscribePageFileName)
    {
        // check person record is OK
        AssertFieldsExist(person);
        string email = person["Email"].ToString();

        // validate
        if (email.IsBlank())
        {
            throw new Exception("NewsletterDoubleOptIn: Email address was null or empty.");
        }
        if (!email.IsEmail())
        {
            throw new Exception("NewsletterDoubleOptIn: Email address was not valid [" + email + "].");
        }

        // send double opt in email

        Models.TextBlock emailText = Models.TextBlock.LoadBySectionCode("Double_OptIn_Email");
        // create if not found
        if (emailText == null)
        {
            emailText = new Models.TextBlock()
            {
                SectionCode      = "Double_OptIn_Email",
                IsBodyPlainText  = true,
                IsTitleAvailable = true,
                BodyTextHtml     = string.Format("Please confirm that you wish to subscribe to our email newsletter.{0}{0}Click the link below if you wish to subscribe:", Environment.NewLine),
                Title            = "Email Newsletter - Please Confirm"
            };
            emailText.Save();
        }

        string emailBody = emailText.BodyTextHtml;

        emailBody += Environment.NewLine + Web.ResolveUrlFull(subscribePageFileName) + "?optin=" + Crypto.EncryptID((int)person["PersonID"].ValueObject).UrlEncode();
        SendEMail.SimpleSendEmail(email, emailText.Title, emailBody);

        person["DoubleOptInEmailSentDate"].ValueObject = DateTime.Now;
        person.Save();
    }
Esempio n. 5
0
        /// <summary>
        /// Run the import. To tailor the import to handle a specific data format, create a derived class and override the various methods.
        /// </summary>
        public void ImportFilesInDropbox()
        {
            if (IsDropboxNotEmpty())
            {
                string dropboxFullPath          = Web.MapPath(IncomingPath);
                string dropboxProcessedFullPath = null;
                string dropboxRejectsFullPath   = null;
                if (!NoFilePermissionsMode)
                {
                    dropboxProcessedFullPath = Web.MapPath(ProcessedPath);
                    dropboxRejectsFullPath   = Web.MapPath(RejectsPath);
                }

                try {
                    Init(dropboxFullPath, dropboxProcessedFullPath, dropboxRejectsFullPath);

                    string[] files;
                    if (DirectoryFilter.IsNotBlank())
                    {
                        files = Directory.GetFiles(dropboxFullPath, DirectoryFilter);
                    }
                    else
                    {
                        files = Directory.GetFiles(dropboxFullPath);
                    }

                    foreach (var pathname in files)
                    {
                        string filename = pathname.RightFrom("\\");

                        this.fileName = filename;

                        if (!NoFilePermissionsMode || new Sql("select count(*) from DataImport where filename=", filename.SqlizeText()).FetchIntOrZero() == 0)
                        {
                            // process new file
                            var ok = ProcessFile(dropboxFullPath, filename);

                            bool useUniqueFiles = Util.GetSettingBool("ImporterUniqueFiles", true);
                            if (ok)
                            {
                                if (NoFilePermissionsMode)
                                {
                                    var log = new ActiveRecord("DataImport", "DataImportID");
                                    log["FileName"].ValueObject     = filename;
                                    log["DateImported"].ValueObject = DateTime.Now;
                                    log["ImportedBy"].ValueObject   = "Importer";
                                    log.Save();
                                }
                                else
                                {
                                    //bool useUniqueFiles = Util.GetSettingBool("ImporterUniqueFiles", true);
                                    string destfilename = filename;
                                    if (useUniqueFiles)
                                    {
                                        destfilename = FileSystem.GetUniqueFilename(dropboxFullPath + "\\", filename, 50, true);
                                    }

                                    if (Util.GetSettingBool("ImporterMoveFiles", true) && MoveImportedFiles)
                                    {
                                        bool allowOverwrite = !useUniqueFiles;
                                        FileSystem.Move(dropboxFullPath + "\\" + filename, dropboxProcessedFullPath + "\\" + destfilename, allowOverwrite);
                                    }
                                }

                                //Web.Response.Write("Imported file: " + filename + "<br>");
                                ImportSuccess(pathname);
                            }
                            else
                            {
                                if (ErrorAction == ErrorActions.ThrowError)
                                {
                                    throw new ProgrammingErrorException("Data Import Error: could not import file [" + filename + "]");
                                }
                                else if (ErrorAction == ErrorActions.EmailDeveloper)
                                {
                                    SendEMail.SimpleSendEmail(SendEMail.EmailAboutError, Util.GetSiteName() + " Import error", "Data Import Error: could not import file [" + filename + "]. Moved to Rejects folder.");
                                }
                                if (!NoFilePermissionsMode)
                                {
                                    if (!IsIgnoredIfError)
                                    {
                                        if (useUniqueFiles)
                                        {
                                            filename = FileSystem.GetUniqueFilename(dropboxRejectsFullPath + "\\", filename, 50, true);
                                        }
                                        bool allowOverwrite = !useUniqueFiles;

                                        try {
                                            FileSystem.Move(dropboxFullPath + "\\" + filename, dropboxRejectsFullPath + "\\" + filename, allowOverwrite);
                                        } catch (Exception e) {
                                            Web.Response.Write("NOK:file did not process ok. Also failed to move file: " + filename + " exception[" + e.Message + "]<br>");
                                        }
                                    }
                                }
                                Web.Response.Write("Could not import file: " + filename + "<br>");
                                //return; // just go on to the next file

                                ImportFailure(pathname);
                            }
                        }
                    }
                } catch (System.UnauthorizedAccessException accessException) {
                    throw new System.UnauthorizedAccessException("Drop folder problem: you need to grant the user ASPNET read/write/delete permissions over the folder '" + dropboxFullPath + "'.\n" + accessException.Message);
                }
            }
        }
Esempio n. 6
0
        private void LogMessage()
        {
#if ActiveRecord
            if (!BewebData.TableExists("MailLog"))
            {
                new Sql("CREATE TABLE [dbo].[MailLog]([MailLogID] [int] IDENTITY(1,1) NOT NULL, [EmailTo] [nvarchar](150) NULL, [EmailSubject] [nvarchar](150) NULL, [Result] [nvarchar](250) NULL, [DateSent] [datetime] NULL, [EmailFrom] [nvarchar](150) NULL, CONSTRAINT [MailLog_PK] PRIMARY KEY NONCLUSTERED ([MailLogID] ASC))").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "DateSent"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [DateSent] [datetime] NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailTo"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailTo] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailFrom"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailFrom] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailFromName"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailFromName] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailToName"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailToName] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailCC"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailCC] [nvarchar](250) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "DateViewTracked"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [DateViewTracked] [datetime] NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "TrackingGUID"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [TrackingGUID] [nvarchar](50) NULL").Execute();
            }
            if (MailLogFullText)
            {
                if (!BewebData.FieldExists("MailLog", "EmailBodyPlain"))
                {
                    new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailBodyPlain] [nvarchar](max) NULL").Execute();
                }
                if (!BewebData.FieldExists("MailLog", "EmailBodyHtml"))
                {
                    new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailBodyHtml] [nvarchar](max) NULL").Execute();
                }
            }
            var maillog = new ActiveRecord("MailLog", "MailLogID");
            maillog["DateSent"].ValueObject      = DateTime.Now;
            maillog["EmailFromName"].ValueObject = FromName.Left(150);
            maillog["EmailFrom"].ValueObject     = FromAddress.Left(150);
            maillog["EmailToName"].ValueObject   = ToName.Left(150);
            maillog["EmailTo"].ValueObject       = ToAddress.Left(150);
            maillog["EmailSubject"].ValueObject  = Subject.Left(150);
            maillog["EmailCC"].ValueObject       = CC.Left(250);
            maillog["TrackingGUID"].ValueObject  = trackingGuid;

            if (MailLogFullText)
            {
                maillog["EmailBodyPlain"].ValueObject = BodyPlain;
                maillog["EmailBodyHtml"].ValueObject  = BodyHtml;
            }
            maillog["Result"].ValueObject = ErrorResult.Left(250) ?? "OK";
            maillog.Save();
#endif
        }