public static NdiPrincipal AuthLogin(String userName, String userPassw, IIdentity contIdentity)
        {
            NdiPrincipal principal;
              Guid orgGuid;

              User user = new User(userName);
              //user.Password = Password.ComputeHash(userPassw);
              user.Password = userPassw;

              IUserService userSrv = ServiceFactory.GetUserService();
              ArrayList a = new ArrayList();

              if (userSrv.UserAuthenticate(user))
              {
            a.Add("Registered");

            User userSelected = userSrv.UserSelectForAuthorization(userName);

            if (!userSelected.OrganisationRef.IsNull)
            {
              orgGuid = userSelected.OrganisationRef;
              if (userSelected.Right.Equals("W"))
              {
            string writerRole = orgGuid.ToString() + ".Writer";
            a.Add(writerRole);
              }
              if (userSelected.Right.Equals("R"))
              {
            string readerRole = orgGuid.ToString() + ".Reader";
            a.Add(readerRole);
              }
            }
            else
            {
              throw new Exception("A felhasználó nem tartozik szervezethez.");
            }

            string[] roles = {};
            roles = (string[]) a.ToArray(typeof (string));

            GenericIdentity identity = new GenericIdentity(userName);

            principal =
              new NdiPrincipal(identity, roles, userSelected.OrganisationName, userSelected.OrganisationRef,
                           userSelected.Name);

            return principal;
              }
              else
              {
            return null;
              }
        }
Exemple #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
              {
            #if DEBUG
            txtUserName.Text = "Administrator";
            txtPassword.Text = "NdiAdministrator";
            #endif
            //	---	Check input data
            bool isValidated = CheckData();

            if (!isValidated)
            {
              DialogResult = DialogResult.None;
              return;
            }

            User user = new User(txtUserName.Text);
            user.Password = Password.ComputeHash(txtPassword.Text);

            IUserService userSrv = ServiceFactory.GetUserService();
            if (userSrv.AdminAuthenticate(user))
            {
              User authenticatedUser = userSrv.UserSelectForAuthorization(user.LoginName);
              string[] roles = {"Administrator"};
              GenericIdentity identity = new GenericIdentity(authenticatedUser.LoginName);
              NdiPrincipal principal = new NdiPrincipal(identity, roles, authenticatedUser.Name);
              Thread.CurrentPrincipal = principal;
            }
            else
            {
              MessageBox.Show("Hibás felhasználónév vagy jelszó. Belépés sikertelen.", "NDI HelpDesk Adminisztrátor",
                          MessageBoxButtons.OK, MessageBoxIcon.Error);
              txtPassword.Text = "";
              txtPassword.Focus();
              DialogResult = DialogResult.None;
              return;
            }
              }
              catch (Exception ex)
              {
            //	---	Log exception
            ExceptionManager.Publish(ex);
            //	---	Display Exception
            ErrorHandler.DisplayError("Hiba a bejelentkezés során.", ex);
            //	---	Handle dialogresult
            DialogResult = DialogResult.None;
              }
        }
Exemple #3
0
        private void Global_AuthorizeRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication) sender;

              if (application.Context.User != null && application.Context.User.Identity.IsAuthenticated == true)
              {
            if (Context.User.Identity.IsAuthenticated)
            {
              if (Context.User.Identity.AuthenticationType == "Forms")
              {

            IUserService userSrv = ServiceFactory.GetUserService();
            //IUserService srvUser = ServiceFactory.GetUserService();

            Guid orgID = Guid.Empty;
            ArrayList a = new ArrayList();
            a.Add("Registered");

            //mielõtt meghatároznánk a jogosultságot és elmentenénk a Context.User-be a
            //szervezet azonosítót meg kell nézni hogy létezik e még ez a szervezet és hogy
            //utolsó használat óta nem változott e meg a jogosultság
            User userReg = userSrv.UserSelect(Context.User.Identity.Name);

            #region : Registred jog beállítása - a user adatok mentéséhez szükséges :

            string[] rolesRegistred = {};
            rolesRegistred = (string[]) a.ToArray(typeof (string));

            NdiPrincipal principalRegistred =
              new NdiPrincipal(Context.User.Identity, rolesRegistred, userReg.OrganisationName, orgID, userReg.Name);

            Context.User = principalRegistred;
            Thread.CurrentPrincipal = principalRegistred;

            #endregion

            if (!userReg.OrganisationRef.IsNull)
            {
              IOrganisationUserService srvOrgUser = ServiceFactory.GetOrganisationUserService();
              OrganisationUser ou = srvOrgUser.OrganisationUserSelect(userReg.OrganisationRef, userReg.LoginName);

              if (ou == null)
              {
                //már nem tartozik a felhasználó ahhez aszervezethez ... kiválasztjuk az elsõt
                DataSet ds = srvOrgUser.OrganisationUserSelectRights(userReg.LoginName);

                userReg.OrganisationRef = DBGuid.Null;
                userReg.Right = UserRights.NonOrganisation;

                if (ds.Tables.Count > 0)
                {
                  if (ds.Tables[0].Rows.Count > 0)
                  {
                    userReg.OrganisationRef = new Guid(ds.Tables[0].Rows[0]["uOrganisationRef"].ToString());
                    userReg.Right = ds.Tables[0].Rows[0]["cRight"].ToString();
                  }
                }

                userSrv.UserUpdate(userReg);
              }
              else
              {
                //van ilyen szervezet ... lássuk stimmel e a jogosultság
                if (userReg.Right != ou.Right)
                {
                  userReg.Right = ou.Right;
                  userSrv.UserUpdate(userReg);
                }
              }
            }
            else
            {
              //ha tartozik hozzá szervezetkiválasztjuk az elsõt
              IOrganisationUserService srvOrgUser = ServiceFactory.GetOrganisationUserService();
              DataSet ds = srvOrgUser.OrganisationUserSelectRights(userReg.LoginName);

              if (ds.Tables.Count > 0)
              {
                if (ds.Tables[0].Rows.Count > 0)
                {
                  userReg.OrganisationRef = new Guid(ds.Tables[0].Rows[0]["uOrganisationRef"].ToString());
                  userReg.Right = ds.Tables[0].Rows[0]["cRight"].ToString();

                  userSrv.UserUpdate(userReg);
                }
              }
            }

            User user = userSrv.UserSelectForAuthorization(Context.User.Identity.Name);
            bool isKef = false;
            if (!user.OrganisationRef.IsNull)
            {
              orgID = user.OrganisationRef;
              if (user.Right.Equals("W"))
              {
                string writerRole = orgID.ToString() + ".Writer";
                a.Add(writerRole);
              }
              if (user.Right.Equals("R"))
              {
                string readerRole = orgID.ToString() + ".Reader";
                a.Add(readerRole);
              }
                IOrganisationService orgSrv = ServiceFactory.GetOrganisationService();
                Organisation org = orgSrv.OrganisationSelect(user.OrganisationRef);
                if (org != null)
                {
                 isKef = org.IsKef;
                }

            }

            string[] roles = {};
            roles = (string[]) a.ToArray(typeof (string));

            NdiPrincipal principal =
              new NdiPrincipal(Context.User.Identity, roles, user.OrganisationName, orgID, user.Name);
            principal.IsKef = isKef;

            OrganisationUserContainer contOrgUser = userSrv.SelectChildrenByUserOfOrganisationUser(user.LoginName);

            principal.OrganisationCount = contOrgUser.All.Count;

            // beállítjuk a felhasználó stylesheetjét:
            principal.StyleSheet = "StyleSheet.css";
            if (!user.StyleSheet.IsNull)
            {
              foreach (StyleSheet s in CacheCodeTables.StyleSheets)
              {
                if (user.StyleSheet.Equals(s.File))
                {
                  principal.StyleSheet = user.StyleSheet;
                }
              }
            }

            Context.User = principal;
            Thread.CurrentPrincipal = principal;

            // Ha jelszót kell változtatnia, nem tehet mást:
            if (user.MustChangePassword)
            {
              if (Request.Path.ToLower().IndexOf("userpassword.aspx") <= 0)
              {
                Response.Redirect("UserPassword.aspx");
              }
            }
              }
            }
              }
        }
        /// Megállítja az órát amíg lekérdezi az adatbázisból a leveleket, kiválogatja közülük az el nem
        /// küldötteket és meghívja rájuk a SendMail metodust, majd újraindítja az órát.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
        private void SendMailServiceTimerTick(object sender, ElapsedEventArgs e)
        {
            if (_first)
              {

            #region időzítő beállítása a mail funkcióhoz
            try
            {
              string intervallString = ConfigurationManager.AppSettings["JobTimerIntervall"];
              double intervall = 150000;
              try
              {
            intervall = Convert.ToDouble(intervallString);
            _sendMailTimer.Interval = intervall;
              }
              catch (Exception)
              {

              }

              _sendMailTimer.AutoReset = true;
              _sendMailTimer.Enabled = true;
              EventLog.WriteEntry("Ndi.HelpDesk.HostingService SendMailServiceTimerTick started!");
              _first = false;
            }

            catch (Exception ex)
            {
              EventLog.WriteEntry("Ndi.HelpDesk.HostingService_SendJobMailServiceTimerTick", ex.ToString(), EventLogEntryType.Error, 2001);
            }
            #endregion

              }

              _sendMailTimer.Stop();
              try
              {
            //--------------------------------------------------------------------------
            //Meg kell nézni kell-e levelet küldeni
            //  Levéltípusok:
            //Feladó, jelentkező értesítése a lejárat előtt mondjuk egy héttel (konfigurálható)
            //Feladó, jelentkező értesítése a lejárat előtt egy nappal
            //  Levelet akkor kell küldeni, h aeljött az dő, és még nem lett legyártva,
            //  kiküldve
            //--------------------------------------------------------------------------

            //------------------------------------------------------------
            // Inaktiválás
            //A lejárt hirdetések inaktiválása
            //Alejárt jelentkezések inaktiválása
            //------------------------------------------------------------
            IIdentity identity = new GenericIdentity("NDIService");
            string[] roles = { "Administrator" };
            NdiPrincipal principal =
                      new NdiPrincipal(identity, roles, "NDIService");
            Thread.CurrentPrincipal = principal;
            IJobOfferService srvOffer = ServiceFactory.GetJobOfferService();
            srvOffer.JobOfferSendNotificationSoonExpire();
            //srvOffer.JobOfferSendNotificationTomorrowExpire();
            srvOffer.JobOfferInactivateExpired();
            IJobFindService srvFind = ServiceFactory.GetJobFindService();
            srvFind.JobFindSendNotificationSoonExpire();
            //srvFind.JobFindSendNotificationTomorrowExpire();
            srvFind.JobFindInactivateExpired();

            IJobAnswerService srvAnswer = ServiceFactory.GetJobAnswerService();
            srvAnswer.JobAnswerInactivateExpired();
            //srvAnswer.JobAnswerTomorrowExpire();

              }
              catch (Exception ex)
              {
            EventLog.WriteEntry("Ndi.HelpDesk.HostingService_SendJobMailServiceTimerTick", ex.ToString(), EventLogEntryType.Error, 2001);
              }
              finally
              {
            _sendMailTimer.Start();
              }
        }
        /// Megállítja az órát amíg lekérdezi az adatbázisból a leveleket, kiválogatja közülük az el nem
        /// küldötteket és meghívja rájuk a SendMail metodust, majd újraindítja az órát.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
        private void NewsMailServiceTimerTick(object sender, ElapsedEventArgs e)
        {
            if (_firstNews)
              {

            #region időzítő beállítása a mail funkcióhoz
            try
            {
              string intervallString = ConfigurationManager.AppSettings["RssNewsMailTimerIntervall"];
              double intervall = 150000;
              try
              {
            intervall = Convert.ToDouble(intervallString);
            _newsMailTimer.Interval = intervall;
              }
              catch (Exception)
              {

              }
              _newsMailTimer.AutoReset = true;
              _newsMailTimer.Enabled = true;
              EventLog.WriteEntry("Ndi.HelpDesk.HostingServiceNewsMailServiceTimerTick started!");
              _firstNews = false;
            }

            catch (Exception ex)
            {
              EventLog.WriteEntry("Ndi.HelpDesk.HostingService_NewsMailServiceTimerTick", ex.ToString(), EventLogEntryType.Error, 2001);
            }
            #endregion

              }
              try
              {
            _newsMailTimer.Stop();
            //meg kell nézni, hogy kell-e most küldeni
            string intervallString = ConfigurationManager.AppSettings["RssNewsMailSendingDay"];
            DayOfWeek dayOfweek = DayOfWeek.Monday;
            switch (intervallString)
            {
              case "H":
            dayOfweek = DayOfWeek.Monday;
            break;
              case "K":
            dayOfweek = DayOfWeek.Tuesday;
            break;
              case "SZE":
            dayOfweek = DayOfWeek.Wednesday;
            break;
              case "CS":
            dayOfweek = DayOfWeek.Thursday;
            break;
              case "P":
            dayOfweek = DayOfWeek.Friday;
            break;
              case "SZO":
            dayOfweek = DayOfWeek.Saturday;
            break;
              case "V":
            dayOfweek = DayOfWeek.Sunday;
            break;
            }
            //ha ma az a nap van
            if (DateTime.Today.DayOfWeek == dayOfweek)
            {
              NameValueCollection collServFact = (NameValueCollection)ConfigurationManager.GetSection("PafiCompetition");
              if (collServFact != null)
              {
            string rssFeddUrl = collServFact["RssUrl"];
            string template = collServFact["RssTemplate"];
            string itemTemplate = collServFact["RssItemTemplate"];
            IIdentity identity = new GenericIdentity("NDIService");
            string[] roles = { "Administrator" };
            NdiPrincipal principal =
              new NdiPrincipal(identity, roles, "NDIService");
            Thread.CurrentPrincipal = principal;

            //megnézzük, hogy mamár próbáltunk-e küldeni
            IEmailService srvEmail = ServiceFactory.GetEmailService();
            Email filter = new Email(Guid.Empty);
            filter.Category = EmailCategory.NewsMailRSS;
            DateTime dateFrom = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day - 1, 23, 59, 59);
            DateTime dateTo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
            filter.FilterOnSentFrom = dateFrom;
            filter.FilterOnSentTo = dateTo;
            EmailContainer emails = srvEmail.EmailSelectFiltered(filter);
            if (emails.AllCount == 0) // ma még nem küldtünk
            {
              RssFeedPafi feed = RssReaderPafi.GetFeed(rssFeddUrl);
              if (feed.ErrorMessage == null || feed.ErrorMessage == "")
              {
                string html = RssReaderPafi.CreateHtml(feed, template, itemTemplate, "", 5);
                html = html.Replace("\\n", "\n");
                string body = "";
                string subject = "";
                IEmailTemplateService srvTemplate = ServiceFactory.GetEmailTemplateService();
                srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.NewsMailRSS);
                UserService srvUser = new UserService();
                UserContainer users = srvUser.UserSelectOfEmailRecipient(true, true, true, true, true, true);
                string to = "";
                for (int i = 0; i < users.All.Count; i++)
                {
                  string sEmail = ((User)users.All.Items[i]).Email;
                  if (sEmail.Length > 0)
                  {
                    if (to.IndexOf(sEmail) == -1)
                    {
                      to += sEmail;
                      to += ";";
                    }
                  }
                }
                if (to.Length > 0)
                {
                  //set mail:
                  Email mail = new Email(Guid.NewGuid());

                  mail.Category = EmailCategory.NewsMailRSS;
                  mail.Subject = subject;
                  mail.To = to;
                  mail.MailBody = html;

                  if (mail.MailBody != null && mail.To != null && mail.Subject != null)
                  {
                    // Save data to database
                    IEmailService emailSrv = ServiceFactory.GetEmailService();
                    emailSrv.EmailInsert(mail);
                    try
                    {
                      // Sending mail:
                      emailSrv.EmailSend(mail.ID);
                    }
                    catch (Exception)
                    {

                    }

                  }
                }
              }
            }
              }
            }
              }
              catch (Exception ex)
              {
            EventLog.WriteEntry("Ndi.HelpDesk.HostingService_NewsMailServiceTimerTick", ex.ToString(),
                            EventLogEntryType.Error, 2001);
              }
              finally
              {
            _newsMailTimer.Start();
              }
        }
        /// Megállítja az órát amíg lekérdezi az adatbázisból a leveleket, kiválogatja közülük az el nem
        /// küldötteket és meghívja rájuk a SendMail metodust, majd újraindítja az órát.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param>
        private void InactivationMailServiceTimerTick(object sender, ElapsedEventArgs e)
        {
            _inactivationMailTimer.Enabled = false;
              _inactivationMailTimer.Stop();
              bool isEnabled = false;
              if (_firstInactivation)
              {

            #region időzítő beállítása a mail funkcióhoz
            try
            {
              string intervallString = ConfigurationManager.AppSettings["InactivationTimerIntervall"];
              double intervall;
              try
              {
            intervall = Convert.ToDouble(intervallString);

            _inactivationMailTimer.Interval = intervall;
              }
              catch (Exception ex)
              {
            _inactivationMailTimer.Interval = 86400000;

              }
              string enabled = ConfigurationManager.AppSettings["InactivationEnabled"];

              bool.TryParse(enabled, out isEnabled);

              EventLog.WriteEntry("Ndi.HelpDesk.TimerService", "Ndi.HelpDesk.TimerService InactivationMailServiceTimerTick started!");
              _firstInactivation = false;
            }

            catch (Exception ex)
            {
              EventLog.WriteEntry("Ndi.HelpDesk.TimerService_InactivationMailServiceTimerTick", ex.ToString(), EventLogEntryType.Error, 2001);
            }
            #endregion

              }

              try
              {

              IIdentity identity = new GenericIdentity("NDIService");
              string[] roles = {"Administrator"};
              NdiPrincipal principal =
              new NdiPrincipal(identity, roles, "NDIService");
              Thread.CurrentPrincipal = principal;

              IOrganisationService organisationService = ServiceFactory.GetOrganisationService();
              IProgramService programService = ServiceFactory.GetProgramService();
              IEmailService emailService = ServiceFactory.GetEmailService();
              //Legelőször is kell egy lista az invalid szervezetekről
              string adminMail = ConfigurationManager.AppSettings["email.admin"];
              string inactivationDayCountString = ConfigurationManager.AppSettings["InactivationDayCount"];
              int inactivationDayCount = 365;
              int.TryParse(inactivationDayCountString, out inactivationDayCount);

              DataSet organisationDs = organisationService.OrganisationSelectInvalidWithMail();
              DataTable organisationDt = null;
              if (organisationDs.Tables != null && organisationDs.Tables.Count > 0)
              organisationDt = organisationDs.Tables[0];
              if (organisationDt != null)
              {
              foreach (DataRow row in organisationDt.Rows)
              {

                  Guid orgId = new Guid(row["uID"].ToString());

                  //miben volt hiba
                  Organisation org = organisationService.OrganisationSelect(orgId);

                  if (org != null)
                  {

                      DateTime sentDate = DateTime.Now;
                      DateTime.TryParse(row["dSent"].ToString(), out sentDate);
                      //ha legalább annyi idő eltellt, ami kell
                      if (sentDate.AddDays(inactivationDayCount) < DateTime.Now)
                      {

                          org.ValidationState = OrganisationValidate.IsValid;
                          //megnézzük az alapadatokat,
                          org.ValidationState = organisationService.OrganisationBaseDataValidateForService(org,
                                                                                                           inactivationDayCount,
                                                                                                           sentDate);
                          //megnézzük a szervezet kérdőívet
                          org.ValidationState = organisationService.OrganisationQuestionFromValidateForService(org,
                                                                                                               inactivationDayCount,
                                                                                                               sentDate);

                          //Lekérdezzük a programokat
                          var progFilter = new BusinessDocuments.Program(Guid.NewGuid())
                                               {
                                                   OrganisationRef = org.ID,
                                                   FilterOnIsActive = 1
                                               };

                          ProgramContainer progSelected = programService.ProgramSelectFiltered(progFilter);
                          //Ha van programja, végiglépkeedünk
                          if (progSelected.All.Count > 0)
                          {
                              foreach (BusinessDocuments.Program prog in progSelected.All)
                              {
                                  org.ValidationState = organisationService.ProgramQuestionFromValidateForService(org,
                                                                                                                  prog,
                                                                                                                  inactivationDayCount,
                                                                                                                  sentDate);
                              }
                          }
                          else
                          {
                              #region nincs program

                              // Nincs rögzített program
                              // Túl régi ehhez a template-hoz
                              org.ValidationState = organisationService.NoProgramValidate(org);

                              #endregion
                          }

                          if (org.ValidationState.Trim() != OrganisationValidate.IsValid) //nem módosított
                          {
                              //küldünk mailt az usernek
                              //küldünk mailt az adminnak
                              //inaktiváljuk a szervezetet
                              org.IsActive = false;

                              organisationService.OrganisationValidateSendEmailByCategory(org,
                                                                                          EmailCategory.
                                                                                              ValidationInactivation,
                                                                                          adminMail);
                              string inactivationEnabledString = ConfigurationManager.AppSettings["InactivationEnabled"];
                              bool inactivationEnabled = false;
                              bool.TryParse(inactivationEnabledString, out inactivationEnabled);
                              if (inactivationEnabled)

                                  organisationService.OrganisationSetActive(org);

                          }
                      }

                  }
              }
              }

              }
              catch (Exception ex)
              {
            EventLog.WriteEntry("Ndi.HelpDesk.TimerService_InactivationMailServiceTimerTick", ex.ToString(), EventLogEntryType.Error, 2001);
              }
              finally
              {
            _inactivationMailTimer.Enabled = true;
            _inactivationMailTimer.Start();
              }
        }