Esempio n. 1
0
        public string SignUpSelfService(string AEmailAddress, string AFirstName, string ALastName, string APassword, string ALanguageCode, out TVerificationResultCollection AVerification)
        {
            AVerification = new TVerificationResultCollection();

            try
            {
                TServerAdminWebConnector.LoginServerAdmin("SELFSERVICE");
                bool Result = TMaintenanceWebConnector.SignUpSelfService(AEmailAddress, AFirstName, ALastName, APassword, ALanguageCode, out AVerification);
                Logout();
                return("{" + "\"AVerification\": " + THttpBinarySerializer.SerializeObject(AVerification) + "," + "\"result\": " + THttpBinarySerializer.SerializeObject(Result) + "}");
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during SignUpSelfService:" + Environment.NewLine +
                             Exc.ToString());

                throw;
            }
        }
Esempio n. 2
0
        public string SetNewPassword(string AUserID, string AToken, string ANewPassword)
        {
            // make sure we are logged out. especially SYSADMIN could be logged in when a new user is created.
            Logout();

            TSession.InitThread("SetNewPassword", TAppSettingsManager.ConfigFileName);

            TVerificationResultCollection VerificationResult;
            bool Result = TMaintenanceWebConnector.SetNewPassword(AUserID, AToken, ANewPassword, out VerificationResult);

            return("{" + "\"AVerificationResult\": " + THttpBinarySerializer.SerializeObject(VerificationResult) + "," + "\"result\": " + THttpBinarySerializer.SerializeObject(Result) + "}");
        }
Esempio n. 3
0
        /// throws an exception if the current user does not have enough permission to access the method;
        /// this uses a custom attribute associated with the method of the connector
        static public string CheckUserPermissionsForMethod(System.Type AConnectorType, string AMethodName, string AParameterTypes, Int32 ALedgerNumber = -1, bool ADontThrowException = false)
        {
            MethodInfo[] methods = AConnectorType.GetMethods();

            MethodInfo MethodToTest = null;

            AParameterTypes = AParameterTypes.Replace("[]", ".ARRAY");

            foreach (MethodInfo method in methods)
            {
                if (method.Name == AMethodName)
                {
                    string          ParameterTypes = ";";
                    ParameterInfo[] Parameters     = method.GetParameters();

                    foreach (ParameterInfo Parameter in Parameters)
                    {
                        string ParameterName = Parameter.ParameterType.ToString().Replace("&", "");

                        ParameterName = ParameterName.Replace("System.Collections.Generic.Dictionary`2", "DICTIONARY");
                        ParameterName = ParameterName.Replace("Ict.Common.", string.Empty);
                        ParameterName = ParameterName.Replace("Ict.Petra.Shared.MCommon.", string.Empty);
                        ParameterName = ParameterName.Replace("System.", string.Empty);

                        if (ParameterName.Contains("."))
                        {
                            ParameterName = ParameterName.Substring(ParameterName.LastIndexOf(".") + 1);
                        }

                        ParameterName = ParameterName.Replace("`1", string.Empty);
                        ParameterName = ParameterName.Replace("`2", string.Empty);
                        ParameterName = ParameterName.Replace("Boolean", "bool");
                        ParameterName = ParameterName.Replace("Int32", "int");
                        ParameterName = ParameterName.Replace("Int64", "long");
                        ParameterName = ParameterName.Replace("[]", ".Array");

                        ParameterTypes += ParameterName + ";";
                    }

                    ParameterTypes = ParameterTypes.ToUpper();

                    if (ParameterTypes == AParameterTypes)
                    {
                        MethodToTest = method;
                        break;
                    }
                }
            }

            if (MethodToTest != null)
            {
                System.Object[] attributes = MethodToTest.GetCustomAttributes(typeof(RequireModulePermissionAttribute), false);

                if ((attributes != null) && (attributes.Length > 0))
                {
                    RequireModulePermissionAttribute requiredModules = (RequireModulePermissionAttribute)attributes[0];

                    string moduleExpression = requiredModules.RequiredModulesExpression.ToUpper();

                    if (moduleExpression == "NONE")
                    {
                        return("OK");
                    }

                    // authenticated user
                    if (moduleExpression == "USER")
                    {
                        if (UserInfo.GetUserInfo() != null && UserInfo.GetUserInfo().UserID != null)
                        {
                            return("OK");
                        }
                    }

                    try
                    {
                        TSecurityChecks.CheckUserModulePermissions(moduleExpression);

                        if (ALedgerNumber != -1)
                        {
                            TSecurityChecks.CheckUserModulePermissions(SharedConstants.LEDGER_MODULESTRING + ALedgerNumber.ToString("0000"));
                        }
                    }
                    catch (ESecurityModuleAccessDeniedException Exc)
                    {
                        string msg =
                            String.Format(Catalog.GetString(
                                              "Module access permission was violated for method '{0}' in Connector class '{1}':  Required Module access permission: {2}, UserName: {3}"),
                                          AMethodName, AConnectorType, Exc.Module, Exc.UserName);
                        TLogging.Log(msg);

                        Exc.Context = AMethodName + " [raised by ModuleAccessManager]";

                        if (ADontThrowException)
                        {
                            TVerificationResultCollection VerificationResult = new TVerificationResultCollection();
                            VerificationResult.Add(new TVerificationResult("error", msg, "",
                                                                           "forms.NotEnoughPermissions", TResultSeverity.Resv_Critical));
                            return("{" + "\"AVerificationResult\": " + THttpBinarySerializer.SerializeObject(VerificationResult) + "," + "\"result\": false}");
                        }

                        throw;
                    }
                    catch (ArgumentException argException)
                    {
                        throw new EOPAppException("Problem with ModulePermissions, " +
                                                  argException.Message + ": '" +
                                                  moduleExpression + "' for " +
                                                  AConnectorType.ToString() + "." +
                                                  AMethodName + "()", argException);
                    }

                    return("OK");
                }
            }

            // TODO: resolve module permission from namespace?

            throw new EOPAppException(
                      "Missing definition of access permission for method " + AMethodName + " in Connector class " + AConnectorType);
        }
Esempio n. 4
0
        public string SetNewPassword(string AUserID, string AToken, string ANewPassword)
        {
            TVerificationResultCollection VerificationResult;
            bool Result = TMaintenanceWebConnector.SetNewPassword(AUserID, AToken, ANewPassword, out VerificationResult);

            return("{" + "\"AVerificationResult\": " + THttpBinarySerializer.SerializeObject(VerificationResult) + "," + "\"result\": " + THttpBinarySerializer.SerializeObject(Result) + "}");
        }
Esempio n. 5
0
        public string TestDateTime(string date)
        {
            DateTime outDateTomorrow;

            DateTime result = TMyServiceWebConnector.TestDateTime((DateTime)THttpBinarySerializer.DeserializeObject(date,
                                                                                                                    "binary"), out outDateTomorrow);

            return(THttpBinarySerializer.SerializeObjectWithType(outDateTomorrow) + "," + THttpBinarySerializer.SerializeObjectWithType(result));
        }
Esempio n. 6
0
        public void TestAdjustGiftBatch()
        {
            int GiftBatchNumber = ImportAndPostGiftBatch();

            TGet_GLM_Info getGLM_InfoBeforeTest73 = new TGet_GLM_Info(FLedgerNumber, "0200", "7300");
            TGet_GLM_Info getGLM_InfoBeforeTest35 = new TGet_GLM_Info(FLedgerNumber, "0200", "3500");

            string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file",
                                                                         "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptTemplate.html");
            Encoding     encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile);
            StreamReader sr          = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false);
            string       FileContent = sr.ReadToEnd();

            sr.Close();

            string receiptsBefore;
            string receiptsPDF;

            TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual",
                                                             new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31),
                                                             FileContent, null, String.Empty, null, String.Empty, "de-DE",
                                                             out receiptsPDF, out receiptsBefore);
            Assert.AreNotEqual(0, receiptsBefore.Trim().Length, "old receipt must not be empty");

            int AdjustBatchNumber;

            TAdjustmentWebConnector.GiftRevertAdjust(FLedgerNumber,
                                                     GiftBatchNumber, -1, -1, false, -1,
                                                     DateTime.Today, GiftAdjustmentFunctionEnum.AdjustGiftBatch,
                                                     false, -1.0m, out AdjustBatchNumber);

            bool         BatchIsUnposted;
            string       CurrencyCode;
            GiftBatchTDS BatchTDS = TGiftTransactionWebConnector.LoadGiftTransactionsForBatch(
                FLedgerNumber, AdjustBatchNumber, out BatchIsUnposted, out CurrencyCode);

            // find the transaction to modify
            Int32 ToModify = (BatchTDS.AGiftDetail[1].GiftTransactionNumber == 2)?1:0;

            // change the amount from 20 to 25
            BatchTDS.AGiftDetail[ToModify].GiftTransactionAmount = 25;
            // the money should go to field 35 instead of field 73
            BatchTDS.AGiftDetail[ToModify].RecipientKey = 35000000;
            // TODO change of donor
            // BatchTDS.Gift[1].DonorKey =

            TVerificationResultCollection VerificationResult;

            if (TGiftTransactionWebConnector.SaveGiftBatchTDS(ref BatchTDS, out VerificationResult) != TSubmitChangesResult.scrOK)
            {
                Assert.Fail("Adjustment Gift Batch was not saved: " + VerificationResult.BuildVerificationResultString());
            }

            int generatedGlBatchNumber;

            if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, AdjustBatchNumber, out generatedGlBatchNumber, out VerificationResult))
            {
                Assert.Fail("Adjustment Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString());
            }

            TGet_GLM_Info getGLM_InfoAfterTest73 = new TGet_GLM_Info(FLedgerNumber, "0200", "7300");
            TGet_GLM_Info getGLM_InfoAfterTest35 = new TGet_GLM_Info(FLedgerNumber, "0200", "3500");

            // Test balance on the related account/Costcentre
            Assert.AreEqual(getGLM_InfoBeforeTest73.YtdActual - 20, getGLM_InfoAfterTest73.YtdActual, "The amount of 20 should be derived from the 73 costcentre");
            Assert.AreEqual(getGLM_InfoBeforeTest35.YtdActual + 25, getGLM_InfoAfterTest35.YtdActual, "The amount of 25 should be added to the 35 costcentre");

            // Test the number of rows on the gift receipt.
            // the difference should be 3 lines removed, 3 lines added. no double donations.
            string receiptsAfter;

            TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual",
                                                             new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31),
                                                             FileContent, null, String.Empty, null, String.Empty, "de-DE",
                                                             out receiptsPDF, out receiptsAfter);
            receiptsBefore = THttpBinarySerializer.DeserializeFromBase64(receiptsBefore);
            receiptsAfter  = THttpBinarySerializer.DeserializeFromBase64(receiptsAfter);

            TLogging.Log("TestAdjustGiftBatch Diff:");
            TLogging.Log(TTextFile.Diff(receiptsBefore, receiptsAfter));
            string[] diff = TTextFile.Diff(receiptsBefore, receiptsAfter).Trim().Split(Environment.NewLine);
            Assert.AreEqual(6, diff.Length, "difference on receipts are 6 lines");
        }
Esempio n. 7
0
        public void TestAnnualReceipt()
        {
            CommonNUnitFunctions.ResetDatabase();
            TPetraServerConnector.Connect("../../etc/TestServer.config");

            // import a test gift batch
            TVerificationResultCollection VerificationResult;

            if (!ImportAndPostGiftBatch(FLedgerNumber, out VerificationResult))
            {
                Assert.Fail("ImportAndPostGiftBatch failed: " + VerificationResult.BuildVerificationResultString());
            }

            // TODO test reversed gifts

            string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file",
                                                                         "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptTemplate.html");
            Encoding     encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile);
            StreamReader sr          = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false);
            string       FileContent = sr.ReadToEnd();

            sr.Close();

            string formletterExpectedFile = TAppSettingsManager.GetValue("ReceiptExpected.file",
                                                                         "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptExpected.html");

            Catalog.Init("de-DE", "de-DE");
            sr = new StreamReader(formletterExpectedFile, encodingOfHTMLfile, false);
            string ExpectedFormletterContent = sr.ReadToEnd().
                                               Replace("#TODAY#", DateTime.Now.ToString("d. MMMM yyyy")).
                                               Replace("#THISYEAR#", DateTime.Today.Year.ToString());

            sr.Close();

            StreamWriter sw = new StreamWriter(formletterExpectedFile + ".updated", false, encodingOfHTMLfile);

            sw.WriteLine(ExpectedFormletterContent);
            sw.Close();

            //TODO: Calendar vs Financial Date Handling - Check if this should use financial year start/end and not assume calendar
            string receipts;
            string receiptsPDF;
            bool   result =
                TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "ANNUAL",
                                                                 new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31),
                                                                 FileContent, null, String.Empty, null, String.Empty, "de-DE",
                                                                 out receiptsPDF, out receipts);

            receipts = THttpBinarySerializer.DeserializeFromBase64(receipts);

            Assert.AreEqual(true, result, "receipt was empty");

            sw = new StreamWriter(formletterExpectedFile + ".new", false, encodingOfHTMLfile);
            sw.WriteLine(receipts);
            sw.WriteLine();
            sw.Close();

            Assert.IsTrue(
                TTextFile.SameContent(formletterExpectedFile + ".updated", formletterExpectedFile + ".new"),
                "receipt was not printed as expected, check " + formletterExpectedFile + ".new");

            File.Delete(formletterExpectedFile + ".new");
            File.Delete(formletterExpectedFile + ".updated");
        }