Esempio n. 1
0
        private static SUserRow LoadUser(String AUserID, out TPetraIdentity APetraIdentity, TDBTransaction ATransaction)
        {
            SUserRow   ReturnValue;
            SUserTable UserDT = null;
            SUserRow   UserDR;
            DateTime   LastLoginDateTime;
            DateTime   FailedLoginDateTime;

            // Check if user exists in s_user DB Table
            if (!SUserAccess.Exists(AUserID, ATransaction))
            {
                throw new EUserNotExistantException(StrInvalidUserIDPassword);
            }

            // User exists, so load User record
            UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ATransaction);

            UserDR = UserDT[0];

            if (!UserDR.IsFailedLoginDateNull())
            {
                FailedLoginDateTime = UserDR.FailedLoginDate.Value;
                FailedLoginDateTime = FailedLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.FailedLoginTime));
            }
            else
            {
                FailedLoginDateTime = DateTime.MinValue;
            }

            if (!UserDR.IsLastLoginDateNull())
            {
                LastLoginDateTime = UserDR.LastLoginDate.Value;
                LastLoginDateTime = LastLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.LastLoginTime));
            }
            else
            {
                LastLoginDateTime = DateTime.MinValue;
            }

            Int64 PartnerKey;

            if (!UserDR.IsPartnerKeyNull())
            {
                PartnerKey = UserDR.PartnerKey;
            }
            else
            {
                // to make it not match PartnerKey 0, which might be stored in the DB or in a variable
                PartnerKey = -1;
            }

            // Create PetraIdentity
            APetraIdentity = new Ict.Petra.Shared.Security.TPetraIdentity(
                AUserID.ToUpper(), UserDR.LastName, UserDR.FirstName, UserDR.LanguageCode, UserDR.AcquisitionCode, DateTime.MinValue,
                LastLoginDateTime, FailedLoginDateTime, UserDR.FailedLogins, PartnerKey, UserDR.DefaultLedgerNumber, UserDR.AccountLocked,
                UserDR.Retired, UserDR.CanModify);
            ReturnValue = UserDR;

            return(ReturnValue);
        }
Esempio n. 2
0
        private static SUserRow LoadUser(String AUserID, TDBTransaction ATransaction)
        {
            // Check if user exists in s_user DB Table
            if (!SUserAccess.Exists(AUserID, ATransaction))
            {
                throw new EUserNotExistantException(StrInvalidUserIDPassword);
            }

            // User exists, so load User record
            SUserTable UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ATransaction);

            return(UserDT[0]);
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves the e-mail address of the given user
        /// </summary>
        private static bool GetEmailOfUser(string AUserID, TDBTransaction ATransaction,
                                           out string AEmailAddress, out string ALanguageCode,
                                           out string AFirstName, out string ALastName)
        {
            SUserTable Users = SUserAccess.LoadByPrimaryKey(AUserID, ATransaction);

            AEmailAddress = Users[0].EmailAddress;
            ALanguageCode = Users[0].LanguageCode;
            AFirstName    = Users[0].FirstName;
            ALastName     = Users[0].LastName;

            return(true);
        }
Esempio n. 4
0
        private static void SendEmailForUser(TDataBase ADataBaseObj, string AUserId, DataTable AErrors)
        {
            TDBTransaction ReadTransaction = new TDBTransaction();
            SUserRow       userrow         = null;

            // get the email address of the user
            ADataBaseObj.ReadTransaction(ref ReadTransaction,
                                         delegate
            {
                userrow = SUserAccess.LoadByPrimaryKey(AUserId, ReadTransaction)[0];
            });

            string   excelfile        = TAppSettingsManager.GetValue("DataChecks.TempPath") + "/errors" + AUserId + ".xlsx";
            DateTime Errors_SinceDate = DateTime.Today.AddDays(-1 * SENDREPORTFORDAYS_TOUSERS);

            DataView v = new DataView(AErrors,
                                      "(CreatedBy='" + AUserId + "' AND ModifiedBy IS NULL AND DateCreated > #" + Errors_SinceDate.ToString("MM/dd/yyyy") + "#) " +
                                      "OR (ModifiedBy='" + AUserId + "' AND DateModified > #" + Errors_SinceDate.ToString("MM/dd/yyyy") + "#)",
                                      string.Empty, DataViewRowState.CurrentRows);

            try
            {
                using (StreamWriter sw = new StreamWriter(excelfile))
                {
                    using (MemoryStream m = new MemoryStream())
                    {
                        if (!TCsv2Xml.DataTable2ExcelStream(v.ToTable(), m))
                        {
                            return;
                        }

                        m.WriteTo(sw.BaseStream);
                        m.Close();
                        sw.Close();
                    }
                }
            }
            catch (Exception e)
            {
                TLogging.Log("Problems writing to file " + excelfile);
                TLogging.Log(e.ToString());
                return;
            }

            string recipientEmail = string.Empty;

            if (!userrow.IsEmailAddressNull())
            {
                recipientEmail = userrow.EmailAddress;
            }
            else if (TAppSettingsManager.HasValue("DataChecks.Email.Recipient.UserDomain"))
            {
                recipientEmail = userrow.FirstName + "." + userrow.LastName + "@" + TAppSettingsManager.GetValue(
                    "DataChecks.Email.Recipient.UserDomain");
            }
            else if (TAppSettingsManager.HasValue("DataChecks.Email.Recipient"))
            {
                recipientEmail = TAppSettingsManager.GetValue("DataChecks.Email.Recipient");
            }

            if (recipientEmail.Length > 0)
            {
                new TSmtpSender().SendEmail("<" + TAppSettingsManager.GetValue("DataChecks.Email.Sender") + ">",
                                            "OpenPetra DataCheck Robot",
                                            recipientEmail,
                                            "Data Check for " + AUserId,
                                            "there are " + v.Count.ToString() + " errors. Please see attachment!",
                                            new string[] { excelfile });
            }
            else
            {
                TLogging.Log("no email can be sent to " + AUserId);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// overload. language code is part of TPetraPrincipal
        /// </summary>
        /// <param name="AUserID"></param>
        /// <param name="AReturnEnglishIfNotFound"></param>
        /// <param name="ATransaction">Instantiated DB Transaction.</param>
        /// <returns></returns>
        public String GetLogonMessage(string AUserID, Boolean AReturnEnglishIfNotFound, TDBTransaction ATransaction)
        {
            SUserTable user = SUserAccess.LoadByPrimaryKey(AUserID, ATransaction);

            return(GetLogonMessageLanguage(user[0].LanguageCode, false, ATransaction));
        }
Esempio n. 6
0
        public static SUserRow LoadUser(String AUserID, out TPetraIdentity APetraIdentity)
        {
            SUserRow       ReturnValue;
            TDBTransaction ReadWriteTransaction;
            Boolean        NewTransaction;
            SUserTable     UserDT;
            SUserRow       UserDR;
            Boolean        UserExists;
            DateTime       LastLoginDateTime;
            DateTime       FailedLoginDateTime;

            ReadWriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable,
                                                                                     TEnforceIsolationLevel.eilMinimum,
                                                                                     out NewTransaction);

            // Check if user exists in s_user DB Table
            try
            {
                UserExists = SUserAccess.Exists(AUserID, ReadWriteTransaction);
            }
            catch
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                }

                throw;
            }

            if (!UserExists)
            {
                throw new EUserNotExistantException(StrInvalidUserIDPassword);
            }
            else
            {
                try
                {
                    // Load User record
                    UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ReadWriteTransaction);
                }
                catch (Exception Exp)
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                    }

                    TLogging.LogAtLevel(8, "Exception occured while loading a s_user record: " + Exp.ToString());

                    throw;
                }

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                }

                UserDR = UserDT[0];

                if (!UserDR.IsFailedLoginDateNull())
                {
                    FailedLoginDateTime = UserDR.FailedLoginDate.Value;
                    FailedLoginDateTime = FailedLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.FailedLoginTime));
                }
                else
                {
                    FailedLoginDateTime = DateTime.MinValue;
                }

                if (!UserDR.IsLastLoginDateNull())
                {
                    LastLoginDateTime = UserDR.LastLoginDate.Value;
                    LastLoginDateTime = LastLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.LastLoginTime));
                }
                else
                {
                    LastLoginDateTime = DateTime.MinValue;
                }

                Int64 PartnerKey;

                if (!UserDR.IsPartnerKeyNull())
                {
                    PartnerKey = UserDR.PartnerKey;
                }
                else
                {
                    // to make it not match PartnerKey 0, which might be stored in the DB or in a variable
                    PartnerKey = -1;
                }

                // Create PetraIdentity
                APetraIdentity = new Ict.Petra.Shared.Security.TPetraIdentity(
                    AUserID.ToUpper(), UserDR.LastName, UserDR.FirstName, UserDR.LanguageCode, UserDR.AcquisitionCode, DateTime.MinValue,
                    LastLoginDateTime, FailedLoginDateTime, UserDR.FailedLogins, PartnerKey, UserDR.DefaultLedgerNumber, UserDR.Retired,
                    UserDR.CanModify);
                ReturnValue = UserDR;
            }

            return(ReturnValue);
        }