protected void btnLogin_Click(object sender, EventArgs e) { try { if (txtLoginName.Text.Length == 0) throw new ArgumentNullException("User.LoginName", "A felhasználónév nincs megadva."); if (txtPassword.Text.Length == 0) throw new ArgumentNullException("User.Password", "A jelszó nincs megadva."); User user = new User(txtLoginName.Text); user.Password = Password.ComputeHash(txtPassword.Text); IUserService userSrv = ServiceFactory.GetUserService(); if (userSrv.UserAuthenticate(user)) { FormsAuthentication.SetAuthCookie(user.LoginName, false, FormsAuthentication.FormsCookiePath); Response.Redirect("Default.aspx"); } else { Response.Redirect("Login.aspx?failed=yes&login=" + txtLoginName.Text); } } catch (Exception ex) { errorPanel.Exception = ex; } }
protected void btnSetPassword_Click(object sender, EventArgs e) { try { if (!Page.IsValid) { return; } // Check old password: User checkUser = new User(Context.User.Identity.Name); checkUser.Password = Password.ComputeHash(txtOrigPassword.Text); IUserService srv = ServiceFactory.GetUserService(); if (srv.UserAuthenticate(checkUser)) { checkUser.Password = Password.ComputeHash(txtNewPassword.Text); checkUser.PasswordQuestion = txtPasswordQuestion.Text; srv.UserChangePassword(checkUser); } else { throw new ApplicationException("Hibás jelszó."); } Response.Redirect("UserData.aspx",true); } catch (Exception ex) { errorPanel.Exception = ex; } }
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; } }
public bool AdminAuthenticate(User user) { TraceCallEnterEvent.Raise(); try { // Check required fields if (user.LoginName.Length == 0) throw new ArgumentNullException("User.LoginName", "A login név nincs megadva."); if (user.Password.Length == 0) throw new ArgumentNullException("User.Password", "A jelszó nincs megadva."); bool result = false; User selected = base.UserSelect(user.LoginName); if (selected != null) { if (selected.IsActive) { if (selected.Password.Equals(user.Password) && selected.Right.Equals("A")) { result = true; } } } if (result) { // Log success BusinessAuditEvent.Success( new EventParameter("LoginName", user.LoginName) ); } else { // Log fail BusinessAuditEvent.Fail( new EventParameter("LoginName", user.LoginName) ); } TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("LoginName", user.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
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; } }
public virtual void UserDelete(User entity) { TraceCallEnterEvent.Raise(); try { m_DataContext.BeginNestedTran(); try { m_DataContext.ndihdUserDelete(entity.LoginName); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
// ------------------------------------------------------------------------------------- /// <summary> /// Inserts data /// </summary> // ------------------------------------------------------------------------------------- private void InsertData() { IUserService userSrv = ServiceFactory.GetUserService(); CurrentID = txtLoginName.Text; User usr = new User(CurrentID); // Get control values usr.Name = txtUserName.Text; if (rbtMan.Checked) usr.Sex = "F"; if (rbtWoman.Checked) usr.Sex = "N"; usr.BirthYear = txtBirthYear.Text; if (txtPhone.Text.Length > 0) usr.Phone = txtPhone.Text; usr.Email = txtEmail.Text; if (txtPostCode.Text.Length > 0) usr.PostCode = txtPostCode.Text; if (txtCity.Text.Length > 0) usr.City = txtCity.Text; if (txtAddress.Text.Length > 0) usr.Address = txtAddress.Text; if (txtCountry.Text.Length > 0) usr.Country = txtCountry.Text; usr.QualificationRef = cmbQualification.SelectedValue.ToString(); if (txtGraduation.Text.Length > 0) usr.Graduation = txtGraduation.Text; if (txtProfession.Text.Length > 0) usr.Profession = txtProfession.Text; if (txtJob.Text.Length > 0) usr.Job = txtJob.Text; usr.NewsMail = cbxNewsmail.Checked; usr.ReasonOfRegistration = txtReasonOfRegistration.Text; usr.Right = UserRights.Administrator; usr.IsActive = cbxActivate.Checked; // Save data userSrv.UserInsert(usr); }
public new void UserUpdate(User entity) { // Check permission: Registered or Administrator PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered"); PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permReg.Union(permAdmin).Demand(); TraceCallEnterEvent.Raise(); try { // Check required fields if (entity.LoginName.Length == 0) throw new ArgumentNullException("User.LoginName", "A felhasználó bejelentkezési neve nincs megadva."); if (entity.Name.Length == 0) throw new ArgumentNullException("User.Name", "A felhasználó neve nincs megadva."); if (entity.Sex.Length == 0) throw new ArgumentNullException("User.Sex", "A felhasználó neme nincs megadva."); if (entity.BirthYear.Length == 0) throw new ArgumentNullException("User.BirthYear", "A felhasználó születési éve nincs megadva."); if (entity.Email.Length == 0) throw new ArgumentNullException("User.Email", "A felhasználó e-mail címe nincs megadva."); if (entity.QualificationRef.Length == 0) throw new ArgumentNullException("User.QualificationRef", "A felhasználó legmagasabb iskolai végzettsége nincs megadva."); // Logical checks User selected = base.UserSelect(entity.LoginName); if (selected == null) throw new ApplicationException("Ezzel a bejelentkezési névvel nem létezik felhasználó."); if (! Thread.CurrentPrincipal.IsInRole("Administrator")) { if (! selected.IsActive) throw new ApplicationException("A felhasználó nem aktív."); } // Save data selected.Name = entity.Name; selected.Sex = entity.Sex; selected.BirthYear = entity.BirthYear; selected.Phone = entity.Phone; selected.Email = entity.Email; selected.Country = entity.Country; selected.PostCode = entity.PostCode; selected.City = entity.City; selected.Address = entity.Address; selected.QualificationRef = entity.QualificationRef; selected.Graduation = entity.Graduation; selected.Profession = entity.Profession; selected.Job = entity.Job; selected.NewsMail = entity.NewsMail; selected.StyleSheet = entity.StyleSheet; selected.OrganisationRef = entity.OrganisationRef; selected.Right = entity.Right; selected.UserAttachments = entity.UserAttachments; UserAttachmentService attSrv = new UserAttachmentService(m_DataContext); //Csak akkor töröljük a régit, ha volt új UserAttachmentContainer oldFiles = base.SelectChildrenByAttachementOfUser(entity.LoginName); foreach (UserAttachment oldFile in oldFiles.All) { if (selected.UserAttachments.CurrentCount > 0) { attSrv.UserAttachmentDelete(oldFile); } } UserAttachment newFile; // EDocumentAttachments - insert: foreach (UserAttachment file in selected.UserAttachments.Current) { if (file.FileData.Length == 0) { newFile = attSrv.UserAttachmentSelectFile(file.ID); } else { newFile = file; } newFile.LoginNameRef = selected.LoginName; newFile.Name = file.Name; newFile.Description = file.Description; newFile.CreatedDate = DateTime.Now; if (attSrv.UserAttachmentSelect(newFile.ID) != null) { attSrv.UserAttachmentUpdate(newFile); } else { attSrv.UserAttachmentInsert(newFile); } }; base.UserUpdate(selected); BusinessAuditEvent.Success( new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(); } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
public bool OrganisationValidateSendEmailByCategory(Organisation entity, string category, string adminMail) { //Check permission: Admin PrincipalPermission permissionAdm = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permissionAdm.Demand(); TraceCallEnterEvent.Raise(); try { // Logical checks: Organisation selected = base.OrganisationSelect(entity.ID); if (selected == null) throw new ApplicationException("A megadott azonosítóval nem létezik szervezet."); //Subject és body lekérdezése string body = ""; string subject = ""; EmailTemplateService srvTemplate = new EmailTemplateService(); srvTemplate.GetEmailTemplateByCode(ref subject, ref body, category); // Le kell kérdezni a szervezethez tartozó irási joggal rendelkező felhasználókat User filter = new User(DBString.Empty); filter.Right = "W"; filter.OrganisationRef = entity.ID; filter.IsActive = true; filter.FilterOnIsactive = DBInt.Null; filter.FilterOnLockedOut = 0; // Retrieving data from BusinessServices UserService srvUser = new UserService(); UserContainer allUser = srvUser.UserSelectFiltered(filter); if (allUser.AllCount == 0) { OrganisationService srvOrgUser = new OrganisationService(); OrganisationUserContainer orgUsers = srvOrgUser.SelectChildrenByOrganisationOfOrganisationUser(selected.ID); foreach (OrganisationUser orguser in orgUsers.All) { User user = srvUser.UserSelect(orguser.LoginNameRef); if (allUser[user.HashString()] == null) allUser.Add(user); } } foreach (User user in allUser.All) { string tmpBody = body; //set mail: Email mail = new Email(Guid.NewGuid()); mail.Category = category; mail.To = user.Email; //"*****@*****.**"; mail.OrganisationRef = entity.ID; tmpBody = tmpBody.Replace("<FULL_USER_NAME>", user.Name); tmpBody = tmpBody.Replace("<LOGIN_NAME>", user.LoginName); tmpBody = tmpBody.Replace("<ORGANISATION>", selected.Name); mail.MailBody = tmpBody; mail.Subject = subject; SendMail(mail); } if (!string.IsNullOrEmpty(adminMail)) //küldünk mailt az adminna is { string tmpBody = body; //set mail: Email mail = new Email(Guid.NewGuid()); mail.Category = EmailCategory.ValidationInactivationAdmin; mail.To = adminMail; //"*****@*****.**"; mail.OrganisationRef = entity.ID; tmpBody = tmpBody.Replace("<ORGANISATION>", selected.Name); mail.MailBody = tmpBody; mail.Subject = subject; SendMail(mail); } // Log success BusinessAuditEvent.Success(new EventParameter("OrganisationID", entity.ID.ToString())); TraceCallReturnEvent.Raise(); return true; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("RegisterUserID", entity.ID.ToString()) ); TraceCallReturnEvent.Raise(false); throw; } }
public new void UserInsert(User entity) { // Check permission: Administrator PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permAdmin.Demand(); TraceCallEnterEvent.Raise(); try { // Check required fields if (entity.LoginName.Length == 0) throw new ArgumentNullException("User.LoginName", "A felhasználó bejelentkezési neve nincs megadva."); if (entity.Name.Length == 0) throw new ArgumentNullException("User.Name", "A felhasználó neve nincs megadva."); if (entity.Sex.Length == 0) throw new ArgumentNullException("User.Sex", "A felhasználó neme nincs megadva."); if (entity.BirthYear.Length == 0) throw new ArgumentNullException("User.BirthYear", "A felhasználó születési éve nincs megadva."); if (entity.Email.Length == 0) throw new ArgumentNullException("User.Email", "A felhasználó e-mail címe nincs megadva."); if (entity.QualificationRef.Length == 0) throw new ArgumentNullException("User.QualificationRef", "A felhasználó legmagasabb iskolai végzettsége nincs megadva."); if (entity.Right.Length == 0) throw new ArgumentNullException("User.Right", "A felhasználó jogosultsági szintje nincs megadva."); if (entity.ReasonOfRegistration.Length == 0) throw new ArgumentNullException("User.ReasonOfRegistration", "Az adatbázis használatának célja nincs megadva."); // Logical checks if (UserCheckLoginName(entity.LoginName)) throw new ApplicationException("A megadott bejelentkezési név már foglalt. Kérem válasszon másikat."); // Save data entity.FailedAttemptCount = 0; entity.LockedOut = false; entity.MustChangePassword = true; entity.Password = Password.ComputeHash(Password.Generate()); base.UserInsert(entity); BusinessAuditEvent.Success( new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(); } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
public bool UserAuthenticate(User user) { TraceCallEnterEvent.Raise(); try { // Check required fields if (user.LoginName.Length == 0) throw new ArgumentNullException("User.LoginName", "A login név nincs megadva."); if (user.Password.Length == 0) throw new ArgumentNullException("User.Password", "A jelszó nincs megadva."); bool result = false; User selected = base.UserSelect(user.LoginName); if (selected != null) { if (selected.IsActive && !selected.LockedOut) { if (selected.Password.Equals(user.Password)) { selected.FailedAttemptCount = 0; selected.FailedAttemptDate = DBDateTime.Null; result = true; } else { if (selected.FailedAttemptCount >= Configuration.LockOutAfterInvalidAttempts) { selected.LockedOut = true; } selected.FailedAttemptCount += 1; selected.FailedAttemptDate = DBDateTime.Now; } base.UserUpdate(selected); } } if (result) { // Log success BusinessAuditEvent.Success( new EventParameter("LoginName", user.LoginName) ); } else { // Log fail BusinessAuditEvent.Fail( new EventParameter("LoginName", user.LoginName) ); } TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("LoginName", user.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
public bool RegisterUserAccept(RegisterUser entity) { //Check permission: Admin PrincipalPermission permissionAdm = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permissionAdm.Demand(); TraceCallEnterEvent.Raise(); try { // Check required fields if (entity.LoginName.Length == 0) throw new ArgumentNullException("RegisterUser.LoginName", "A regisztrálandó felhasználó bejelentkezési neve nincs megadva."); if (entity.Name.Length == 0) throw new ArgumentNullException("RegisterUser.Name", "A regisztrálandó felhasználó neve nincs megadva."); if (entity.Sex.Length == 0) throw new ArgumentNullException("RegisterUser.Sex", "A regisztrálandó felhasználó neme nincs megadva."); if (entity.BirthYear.Length == 0) throw new ArgumentNullException("RegisterUser.BirthYear", "A regisztrálandó felhasználó születési éve nincs megadva."); if (entity.Email.Length == 0) throw new ArgumentNullException("RegisterUser.Email", "A regisztrálandó felhasználó e-mail címe nincs megadva."); if (entity.QualificationRef.Length == 0) throw new ArgumentNullException("RegisterUser.QualificationRef", "A regisztrálandó felhasználó legmagasabb iskolai végzettsége nincs megadva."); if (entity.ReasonOfRegistration.Length == 0) throw new ArgumentNullException("RegisterUser.ReasonOfRegistration", "Az adatbázis használatának célja nincs megadva."); if (entity.Right.Length == 0) throw new ArgumentNullException("RegisterUser.Right", "A jogosultság nincs megadva."); // Logical checks: RegisterUser selected = base.RegisterUserSelect(entity.ID); if (selected == null) throw new ApplicationException("A megadott azonosítóval nem létezik regisztrálandó felhasználó."); if (!selected.Status.Equals(RegistrationStatus.New)) throw new ApplicationException("Csak új státuszú regisztráció bírálható el."); // Set properties entity.SentDate = selected.SentDate; entity.DecidedBy = Thread.CurrentPrincipal.Identity.Name; entity.DecidedDate = DBDateTime.Now; entity.Status = RegistrationStatus.Accepted; User newUser = new User(entity.LoginName); string generatedPassword = Password.Generate(); newUser.Password = Password.ComputeHash(generatedPassword); newUser.OrganisationRef = entity.OrganisationRef; newUser.Name = entity.Name; newUser.Sex = entity.Sex; newUser.BirthYear = entity.BirthYear; newUser.Phone = entity.Phone; newUser.Email = entity.Email; newUser.PostCode = entity.PostCode; newUser.City = entity.City; newUser.Address = entity.Address; newUser.Country = entity.Country; newUser.QualificationRef = entity.QualificationRef; newUser.ReasonOfRegistration = entity.ReasonOfRegistration; newUser.Right = entity.Right; newUser.IsActive = true; newUser.NewsMail = entity.NewsMail; newUser.MustChangePassword = true; newUser.LockedOut = false; newUser.FailedAttemptCount = 0; //set mail: Email mail = new Email(Guid.NewGuid()); mail.Category = EmailCategory.UserRegistrationAccept; mail.To = entity.Email; //Subject és body lekérdezése string body = ""; string subject = ""; EmailTemplateService srvTemplate = new EmailTemplateService(); srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.UserRegistrationAccept); mail.Subject = subject; body = body.Replace("<FULL_USER_NAME>", entity.Name); body = body.Replace("<LOGIN_NAME>", entity.LoginName); body = body.Replace("<PASSWORD>", generatedPassword); mail.MailBody = body; // Save data to database EmailService emailSrv = new EmailService(m_DataContext); m_DataContext.BeginNestedTran(); try { UserServiceBase userSrv = new UserServiceBase(m_DataContext); userSrv.UserInsert(newUser); base.RegisterUserUpdate(entity); emailSrv.EmailInsert(mail); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } // Sending mail: try { emailSrv.EmailSend(mail.ID); } catch (Exception ex) { ExceptionManager.Publish(ex); return false; } // Log success BusinessAuditEvent.Success( new EventParameter("RegisterUserID", entity.ID.ToString()), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(); return true; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("RegisterUserID", entity.ID.ToString()), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
// ------------------------------------------------------------------------------------- /// <summary> /// Copy constructor. /// </summary> /// <param name="LoginNameVal">Value of 'cLoginName' field</param> /// <param name="origInstance">Original document data to copy.</param> // ------------------------------------------------------------------------------------- public User(DBString LoginNameVal, User origInstance) : base(LoginNameVal, origInstance) { }
// ------------------------------------------------------------------------------------- /// <summary> /// Copy constructor. /// </summary> /// <param name="origInstance">Original document data to copy.</param> // ------------------------------------------------------------------------------------- public User(User origInstance) : base(origInstance) { }
public bool RegisterKefOrganisation(RegisterOrganisation entity, string regSearchCode, DBInt disSearchCode, string estYear, string estMonth, string areaHomePage) { //Check permission: Admin PrincipalPermission permissionAdm = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permissionAdm.Demand(); TraceCallEnterEvent.Raise(); try { // Check required fields // Organisation if (entity.Name.Length == 0) throw new ArgumentNullException("RegisterOrganisation.Name", "A regisztrálandó szervezet neve nincs megadva."); if (entity.RegionRef.Length == 0) throw new ArgumentNullException("RegisterOrganisation.RegionRef", "A regisztrálandó szervezet megyéje nincs megadva."); if (entity.WorkingAreaRef.Length == 0) throw new ArgumentNullException("RegisterOrganisation.WorkingAreaRef", "A regisztrálandó szervezet mûködési területe nincs megadva."); if (entity.OrganisationFormRef.Length == 0) throw new ArgumentNullException("RegisterOrganisation.OrganisationFormRef", "A regisztrálandó szervezet szervezeti formája nincs megadva."); if (entity.ReasonOfRegistration.Length == 0) throw new ArgumentNullException("RegisterOrganisation.ReasonOfRegistration", "Az adatbázis használatának célja nincs megadva."); if (entity.PostCode.Length == 0) throw new ArgumentNullException("RegisterOrganisation.PostCode", "A szervezet címének irányítószáma nincs megadva."); if (entity.City.Length == 0) throw new ArgumentNullException("RegisterOrganisation.City", "A szervezet címének település része nincs megadva."); if (entity.Address.Length == 0) throw new ArgumentNullException("RegisterOrganisation.Address", "A szervezet címének utca, házszám része nincs megadva."); // User if (entity.LoginName.Length == 0) throw new ArgumentNullException("RegisterOrganisation.LoginName", "A regisztrálandó felhasználó bejelentkezési neve nincs megadva."); if (entity.UserName.Length == 0) throw new ArgumentNullException("RegisterOrganisation.UserName", "A regisztrálandó felhasználó neve nincs megadva."); if (entity.UserSex.Length == 0) throw new ArgumentNullException("RegisterOrganisation.UserSex", "A regisztrálandó felhasználó neme nincs megadva."); if (entity.UserBirthYear.Length == 0) throw new ArgumentNullException("RegisterOrganisation.UserBirthYear", "A regisztrálandó felhasználó születési éve nincs megadva."); if (entity.UserEmail.Length == 0) throw new ArgumentNullException("RegisterOrganisation.UserEmail", "A regisztrálandó felhasználó e-mail címe nincs megadva."); if (entity.QualificationRef.Length == 0) throw new ArgumentNullException("RegisterOrganisation.QualificationRef", "A regisztrálandó felhasználó legmagasabb iskolai végzettsége nincs megadva."); Organisation newOrg = new Organisation(entity.ID); newOrg.Name = entity.Name; newOrg.Department = entity.Department; newOrg.PostCode = entity.PostCode; newOrg.City = entity.City; newOrg.Address = entity.Address; newOrg.Country = entity.Country; newOrg.Phone1 = entity.Phone1; newOrg.Fax = entity.Fax; newOrg.Email1 = entity.Email1; newOrg.HomePage = entity.HomePage; newOrg.RegionRef = entity.RegionRef; newOrg.WorkingAreaRef = entity.WorkingAreaRef; newOrg.WorkingAreaOther = entity.WorkingAreaOther; newOrg.OrganisationFormRef = entity.OrganisationFormRef; newOrg.ActivityPrevention = entity.ActivityPrevention; newOrg.ActivityRehabilitation = entity.ActivityRehabilitation; newOrg.ActivityResearch = entity.ActivityResearch; newOrg.ActivityOther = entity.ActivityOther; newOrg.SourceGovernment = 0; newOrg.SourceCompetition = 0; newOrg.SourceSponsor = 0; newOrg.SourceDonation = 0; newOrg.SourceTax = 0; newOrg.SourceOther = 0; newOrg.IsActive = true; // defaults newOrg.WorkersFix = 0; newOrg.WorkersExternal = 0; newOrg.WorkersVolunteer = 0; newOrg.JobPsychologist = 0; newOrg.JobPsychiater = 0; newOrg.JobDoctor = 0; newOrg.JobMedicalExpert = 0; newOrg.JobHealthExpert = 0; newOrg.JobSociologist = 0; newOrg.JobSocialPolitician = 0; newOrg.JobSocialWorker = 0; newOrg.JobSocialPedagogist = 0; newOrg.JobPedagogist = 0; newOrg.JobManualist = 0; newOrg.JobLawyer = 0; newOrg.JobPoliceman = 0; newOrg.JobMentalhygiene = 0; newOrg.JobCultureOrganizer = 0; newOrg.JobOther1 = 0; newOrg.JobOther2 = 0; newOrg.JobOther3 = 0; //It's a KEF -> set KEF specific data newOrg.IsKef = true; newOrg.RegionSearchCodeRef = regSearchCode; newOrg.DistrictSearchCodeRef = disSearchCode; newOrg.EstablishmentYear = estYear; newOrg.EstablishmentMonth = estMonth; newOrg.AreaHomePage = areaHomePage; newOrg.IsActual = true; newOrg.LastModified = DateTime.Now; //save the user User newUser = new User(entity.LoginName); newUser.OrganisationRef = entity.ID; string generatedPassword = Password.Generate(); newUser.Password = Password.ComputeHash(generatedPassword); newUser.Address = entity.UserAddress; newUser.Name = entity.UserName; newUser.Sex = entity.UserSex; newUser.BirthYear = entity.UserBirthYear; newUser.Phone = entity.UserPhone; newUser.Email = entity.UserEmail; newUser.PostCode = entity.UserPostCode; newUser.City = entity.UserCity; newUser.Address = entity.UserAddress; newUser.Country = entity.UserCountry; newUser.QualificationRef = entity.QualificationRef; newUser.ReasonOfRegistration = entity.ReasonOfRegistration; newUser.Right = UserRights.Write; newUser.IsActive = true; newUser.NewsMail = false; newUser.MustChangePassword = true; newUser.FailedAttemptCount = 0; newUser.LockedOut = false; //set mail: Email mail = new Email(Guid.NewGuid()); mail.Category = EmailCategory.OrganisationRegistrationAccept; mail.To = entity.UserEmail; //Subject és body lekérdezése string body = ""; string subject = ""; IEmailTemplateService srvTemplate = new EmailTemplateService(); srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.OrganisationRegistrationAccept); mail.Subject = subject; body = body.Replace("<FULL_USER_NAME>", entity.Name); body = body.Replace("<LOGIN_NAME>", entity.LoginName); body = body.Replace("<ORGANIZATION>", newOrg.Name); body = body.Replace("<PASSWORD>", generatedPassword); mail.MailBody = body; // Save data to database EmailService emailSrv = new EmailService(m_DataContext); m_DataContext.BeginNestedTran(); try { UserServiceBase userSrv = new UserServiceBase(m_DataContext); OrganisationService orgSrv = new OrganisationService(m_DataContext); orgSrv.OrganisationInsert(newOrg); userSrv.UserInsert(newUser); emailSrv.EmailInsert(mail); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } // Sending mail: try { emailSrv.EmailSend(mail.ID); } catch (Exception ex) { ExceptionManager.Publish(ex); return false; } // Log success BusinessAuditEvent.Success( new EventParameter("RegisterOrganisationID", entity.ID.ToString()), new EventParameter("OrganisationID", newOrg.ID.ToString()), new EventParameter("OrganisationName", entity.Name), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(); return true; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("RegisterOrganisationID", entity.ID.ToString()), new EventParameter("OrganisationName", entity.Name), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
public virtual User UserSelect(DBString LoginNameVal) { TraceCallEnterEvent.Raise(); try { User result = null; DataSet entitySet = m_DataContext.ndihdUserSelect(LoginNameVal); if (entitySet.Tables[0].Rows.Count != 0) { result = new User(entitySet); } TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
public virtual void UserUpdate(User entity) { TraceCallEnterEvent.Raise(); try { m_DataContext.BeginNestedTran(); try { int count; m_DataContext.ndihdUserUpdate(entity.LoginName, entity.Password, entity.PasswordQuestion, entity.OrganisationRef, entity.Name, entity.Sex, entity.BirthYear, entity.Phone, entity.Email, entity.PostCode, entity.City, entity.Address, entity.Country, entity.QualificationRef, entity.Graduation, entity.Profession, entity.Job, entity.ReasonOfRegistration, entity.Right, entity.IsActive, entity.NewsMail, entity.MustChangePassword, entity.LockedOut, entity.FailedAttemptCount, entity.FailedAttemptDate, entity.StyleSheet, out count); if (count == 0) throw new ServiceUpdateException(); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
public void UserResetPassword(User entity) { // Check permission: Administrator PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permReg.Demand(); TraceCallEnterEvent.Raise(); try { // Check required fields if (entity.Password.Length == 0) throw new ArgumentNullException("User.Password", "Az új jelszó nincs megadva."); // Logical checks User selected = base.UserSelect(entity.LoginName); if (selected == null) throw new ApplicationException("Ezzel a bejelentkezési névvel nem létezik felhasználó."); if (!selected.IsActive) throw new ApplicationException("A felhasználó nem aktív."); if (entity.PasswordQuestion.IndexOf(entity.Password) > 0) throw new ApplicationException("A segítõ kérdés nem tartalmazhatja magát a jelszót."); // Save data selected.Password = entity.Password; selected.MustChangePassword = true; base.UserUpdate(selected); BusinessAuditEvent.Success( new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(); } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("LoginName", entity.LoginName) ); TraceCallReturnEvent.Raise(false); throw; } }
/// <summary> /// Fill datagrid with data /// </summary> private void FillDatagrid(DBString ID) { try { string sSortColumn = "LoginName"; int nSelectedRow = -1; // Storing the previous sort order if (dtgMain.DataSource != null) { sSortColumn = ((DataTable) dtgMain.DataSource).DefaultView.Sort; } // Set filter User filter = new User(txtLoginName.Text.Length > 0 ? (DBString) txtLoginName.Text : DBString.Empty); if (cmbRight.SelectedIndex > 0) { filter.Right = cmbRight.SelectedValue.ToString(); } if (cmbOrganisation.SelectedIndex > 0) { filter.OrganisationRef = (DBGuid) (new Guid(cmbOrganisation.SelectedValue.ToString())); } filter.FilterOnIsactive = DBInt.Null; if (cmbStatus.SelectedIndex > 0) { bool bIsActive = (cmbStatus.SelectedValue.ToString() == "1" ? true : false); filter.FilterOnIsactive = (DBInt) Convert.ToInt32(bIsActive); filter.IsActive = bIsActive; } filter.FilterOnLockedOut = DBInt.Null; if (cmbLockedOut.SelectedIndex > 0) { bool bLockedOut = (cmbLockedOut.SelectedValue.ToString() == "1" ? true : false); filter.FilterOnLockedOut = (DBInt) Convert.ToInt32(bLockedOut); filter.LockedOut = bLockedOut; } // Retrieving data from BusinessServices IUserService srv = ServiceFactory.GetUserService(); UserContainer allData = srv.UserSelectFiltered(filter); DataTable dt = allData.AllAsDatatable; dt.DefaultView.Sort = sSortColumn; dtgMain.DataSource = dt; // Locates the row specified by ID param if (ID != DBString.Empty) { BindingManagerBase bm = dtgMain.BindingContext[dtgMain.DataSource, dtgMain.DataMember]; DataRow dr; int nPositionStart = bm.Position; for (int i = 0; i < bm.Count; i++) { dr = ((DataRowView) bm.Current).Row; if ((String) (dr["LoginName"]) == (String) ID) { nSelectedRow = i; break; } bm.Position += 1; } bm.Position = nPositionStart; } // Makes the row selected if (nSelectedRow <= ((DataTable) dtgMain.DataSource).DefaultView.Count && nSelectedRow > -1) { dtgMain.Select(nSelectedRow); dtgMain.CurrentRowIndex = nSelectedRow; } else if (((DataTable) dtgMain.DataSource).DefaultView.Count != 0) { dtgMain.Select(0); } // Enabling or disabling the buttons according to record count. // And is because of previous disable state. tbbModify.Enabled = (((DataTable) dtgMain.DataSource).DefaultView.Count != 0); tbbInactivate.Enabled = (((DataTable) dtgMain.DataSource).DefaultView.Count != 0); tbbPasswordReset.Enabled = (((DataTable) dtgMain.DataSource).DefaultView.Count != 0); tbbLockedOut.Enabled = (((DataTable) dtgMain.DataSource).DefaultView.Count != 0); } catch (Exception ex) { // --- Log exception ExceptionManager.Publish(ex); // --- Display Exception ErrorHandler.DisplayError("Nem várt hiba lépett fel a lista frissítése során.", ex); } }
public UserContainer UserSelectFiltered(User filter) { // Check permission: Administrator PrincipalPermission permissionAdm = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permissionAdm.Demand(); TraceCallEnterEvent.Raise(); try { UserContainer result; DataSet entitySet = m_DataContext.ndihdUserSelectFiltered( filter.Right, filter.OrganisationRef, filter.LoginName, filter.FilterOnIsactive, filter.FilterOnLockedOut); result = new UserContainer(entitySet.Tables[0]); TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
public User UserSelectForAuthorization(DBString LoginNameVal) { TraceCallEnterEvent.Raise(); try { User result = null; DataSet entitySet = m_DataContext.ndihdUserSelectForAuthorization(LoginNameVal); if (entitySet.Tables[0].Rows.Count != 0) { DataRow row = entitySet.Tables[0].Rows[0]; result = new User(row["cLoginName"].ToString()); result.Name.Value = row["cName"]; result.OrganisationRef.Value = row["uOrganisationRef"]; result.OrganisationName.Value = row["cOrganisationName"]; result.Right.Value = row["cRight"]; result.IsActive = (bool) row["bIsActive"]; result.MustChangePassword = (bool) row["bMustChangePassword"]; result.StyleSheet.Value = row["cStyleSheet"]; } TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
private void FillUserDataGrid() { try { var orgId = DBGuid.Null; orgId.Value = dtgOrganisation.GetSelectedRowCell("ID"); // Set filter var filter = new User(DBString.Empty) { OrganisationRef = orgId, FilterOnIsactive = DBInt.Null, FilterOnLockedOut = 0 }; // Retrieving data from BusinessServices IUserService srv = ServiceFactory.GetUserService(); UserContainer allData = srv.UserSelectFiltered(filter); DataTable dt = allData.AllAsDatatable; dtgUser.DataSource = dt; } catch (Exception ex) { // --- Log exception ExceptionManager.Publish(ex); // --- Display Exception ErrorHandler.DisplayError("Hiba történt az adatok lekérdezése során.", ex); } }