Exemplo n.º 1
0
        public bool UpdateUser(UserBO User, OrganizationBO OrgBO)
        {
            bool success = false;

            switch (User.Operation)
            {
            case OperationMode.UpdatePassword:
                string password = string.Empty;

                if (User.ResetPassword)
                {
                    password           = User.PasswordHash;
                    User.ResetPassword = false;
                }
                else
                {
                    PasswordGenerator passGen = new PasswordGenerator();
                    password           = passGen.Generate();
                    User.ResetPassword = true;
                }


                string         KeyForUserPasswordSalt = ReadSalt();
                PasswordHasher PasswordHasher         = new Web.Enter.Common.Security.PasswordHasher(KeyForUserPasswordSalt);
                string         salt = PasswordHasher.CreateSalt(User.UserName);

                User.PasswordHash = PasswordHasher.HashPassword(salt, password);
                success           = UserDao.UpdateUserPassword(User);

                if (success)
                {
                    List <string> EmailList = new List <string>();
                    EmailList.Add(User.UserName);
                    Email email = new Email()
                    {
                        To       = EmailList,
                        Password = password
                    };

                    if (User.ResetPassword)
                    {
                        success = SendEmail(email, EmailCombinationEnum.ResetPassword);
                    }
                    else
                    {
                        success = SendEmail(email, EmailCombinationEnum.PasswordChanged);
                    }
                }
                return(success);

            case OperationMode.UpdateUserInfo:
                success = UserDao.UpdateUserInfo(User, OrgBO);
                return(success);

            default:
                break;
            }
            return(false);
        }
        public UserBO GetUser(UserBO User)
        {
            UserBO         UserResponseBO;
            string         KeyForUserPasswordSalt = ReadSalt();
            PasswordHasher PasswordHasher         = new Web.Enter.Common.Security.PasswordHasher(KeyForUserPasswordSalt);
            string         salt = PasswordHasher.CreateSalt(User.UserName);

            User.PasswordHash = PasswordHasher.HashPassword(salt, User.PasswordHash);

            UserResponseBO = UserDao.GetUser(User);
            if (UserResponseBO != null)
            {
                UserResponseBO.UserHighestRole = UserDao.GetUserHighestRole(UserResponseBO.UserId);
            }

            return(UserResponseBO);
        }
Exemplo n.º 3
0
        public void InsertOrganizationInfo(OrganizationBO OrganizationBO, UserBO UserBO)
        {
            bool success;

            OrganizationBO.OrganizationKey = Epi.Web.Enter.Common.Security.Cryptography.Encrypt(OrganizationBO.OrganizationKey);
            InsertCombination InsertStatus = new InsertCombination();
            // Check if the user Exists
            var    User         = this.OrganizationDao.GetUserByEmail(UserBO);
            string tempPassword = string.Empty;

            if (User != null)
            {
                if (string.IsNullOrEmpty(User.EmailAddress))
                {
                    UserBO.ResetPassword = true;
                    success = this.OrganizationDao.InsertOrganization(OrganizationBO, UserBO);
                }

                else
                {
                    success = this.OrganizationDao.InsertOrganization(OrganizationBO, User.UserId, UserBO.Role);
                }
                if (success)
                {
                    InsertStatus = InsertCombination.ExistingUserNewOrg;
                }
            }
            else
            {
                string         KeyForUserPasswordSalt = SecurityAppSettings.GetStringValue(SecurityAppSettings.Key.KeyForUserPasswordSalt);
                PasswordHasher PasswordHasher         = new Web.Enter.Common.Security.PasswordHasher(KeyForUserPasswordSalt);
                string         salt = PasswordHasher.CreateSalt(UserBO.EmailAddress);
                UserBO.ResetPassword = true;
                PasswordGenerator PassGen = new PasswordGenerator();
                tempPassword        = PassGen.Generate();
                UserBO.PasswordHash = PasswordHasher.HashPassword(salt, tempPassword);// "PassWord1");

                success = this.OrganizationDao.InsertOrganization(OrganizationBO, UserBO);
                if (success)
                {
                    InsertStatus = InsertCombination.NewUserNewOrg;
                }
            }
            var OrgKey = Epi.Web.Enter.Common.Security.Cryptography.Decrypt(OrganizationBO.OrganizationKey);

            if (success && InsertStatus != InsertCombination.None)
            {
                Email email = new Email();

                StringBuilder Body = new StringBuilder();
                if (InsertStatus == InsertCombination.ExistingUserNewOrg)
                {
                    Body.Append("Your account has now been created for organization - " + OrganizationBO.Organization + ".\n");
                    Body.Append("\nOrganization Key: " + OrgKey);
                    Body.Append("\n\nPlease click the link below to launch Epi Info™ Cloud Data Capture. \n" + AppSettings.GetStringValue(AppSettings.Key.BaseURL) + "\n\nThank you.");
                }
                else
                {
                    Body.Append("Welcome to Epi Info™ Cloud Data Capture. \nYour account has now been created for oganization - " + OrganizationBO.Organization + ".");
                    if (AppSettings.GetStringValue(AppSettings.Key.WindowAuthentication).ToUpper() == "NO")
                    {
                        Body.Append("\n\nEmail: " + UserBO.EmailAddress + "\nPassword: "******"\nOrganization Key: " + OrgKey);
                    Body.Append("\n\nPlease click the link below to launch the Epi Info™ Cloud Data Capture and log in with your email and temporary password. You will then be asked to create a new password. \n" + AppSettings.GetStringValue(AppSettings.Key.BaseURL));
                    //Add email and temporary password for new user.
                }

                //Body.Append("\n" + AppSettings.GetStringValue(AppSettings.Key.BaseURL));

                if (InsertStatus == InsertCombination.NewUserNewOrg)
                {
                    Body.Append("\n\nPlease follow the steps below in order to start publishing forms to the web using Epi Info™ 7.");
                    Body.Append("\n\tStep 1: Download and install the latest version of Epi Info™ 7 from:" + AppSettings.GetStringValue(AppSettings.Key.EpiInfoDownloadURL));
                    Body.Append("\n\tStep 2: On the Main Menu, click on “Tools” and select “Options”");
                    Body.Append("\n\tStep 3: On the Options dialog, click on the “Cloud Data Capture” Tab.");
                    Body.Append("\n\tStep 4: On the Cloud Data Capture tab, enter the following information.");

                    Body.Append("\n\t\t-Endpoint Address:" + AppSettings.GetStringValue(AppSettings.Key.EndpointAddress) + "\n\t\t-Connect using Windows Authentication:  " + AppSettings.GetStringValue(AppSettings.Key.WindowAuthentication));
                    Body.Append("\n\t\t-Binding Protocol:" + AppSettings.GetStringValue(AppSettings.Key.BindingProtocol));

                    Body.Append("\n\tStep 5:Click “OK’ button.");
                    Body.Append("\nOrganization key provided here is to be used in Epi Info™ 7 during publish process.");
                    Body.Append("\n\nPlease contact the system administrator for any questions.");
                }


                email.Body = Body.ToString();
                email.To   = new List <string>();
                email.To.Add(UserBO.EmailAddress);

                success = SendEmail(email, EmailCombinationEnum.InsertOrganization);
            }
        }
        public bool SetUserInfo(UserBO UserBO, OrganizationBO OrgBO)
        {
            //UserBO ExistingUser; //= GetUser(UserBO);
            //ExistingUser = UserDao.GetUserByEmail(UserBO);
            //ExistingUser.Role = UserDao.GetUserHighestRole(ExistingUser.UserId);

            bool success;

            if (UserBO.UserName == null)
            {
                string         KeyForUserPasswordSalt = ReadSalt();
                PasswordHasher PasswordHasher         = new Web.Enter.Common.Security.PasswordHasher(KeyForUserPasswordSalt);
                string         salt = PasswordHasher.CreateSalt(UserBO.EmailAddress);
                UserBO.ResetPassword = true;
                PasswordGenerator PassGen      = new PasswordGenerator();
                string            tempPassword = PassGen.Generate();
                UserBO.PasswordHash = PasswordHasher.HashPassword(salt, tempPassword);// "PassWord1");
                //UserBO.PasswordHash = PasswordHasher.HashPassword(salt, "PassWord1");
                success = UserDao.InsertUser(UserBO, OrgBO);
                StringBuilder Body   = new StringBuilder();
                var           OrgKey = Epi.Web.Enter.Common.Security.Cryptography.Decrypt(OrgBO.OrganizationKey);
                if (success)
                {
                    Email email = new Email();
                    Body.Append("Welcome to Epi Info™ Cloud Data Capture. \nYour account has now been created for organization - " + OrgBO.Organization + ".");

                    if (System.Configuration.ConfigurationManager.AppSettings["WINDOW_AUTHENTICATION"].ToUpper() == "NO")
                    {
                        Body.Append("\n\nEmail: " + UserBO.EmailAddress + "\nPassword: "******"\nOrganization Key: " + OrgKey);
                    Body.Append("\n\nPlease click the link below to launch the Epi Info™ Cloud Data Capture and log in with your email and temporary password. You will then be asked to create a new password. \n" + ConfigurationManager.AppSettings["BaseURL"]);
                    //Add email and temporary password for new user.



                    Body.Append("\n\nPlease follow the steps below in order to start publishing forms to the web using Epi Info™ 7.");
                    Body.Append("\n\tStep 1: Download and install the latest version of Epi Info™ 7 from:" + ConfigurationManager.AppSettings["EPI_INFO_DOWNLOAD_URL"]);
                    Body.Append("\n\tStep 2: On the Main Menu, click on “Tools” and select “Options”");
                    Body.Append("\n\tStep 3: On the Options dialog, click on the “Cloud Data Capture” Tab.");
                    Body.Append("\n\tStep 4: On the Cloud Data Capture tab, enter the following information.");

                    Body.Append("\n\t\t-Endpoint Address:" + ConfigurationManager.AppSettings["ENDPOINT_ADDRESS"] + "\n\t\t-Connect using Windows Authentication:  " + ConfigurationManager.AppSettings["WINDOW_AUTHENTICATION"]);
                    Body.Append("\n\t\t-Binding Protocol:" + ConfigurationManager.AppSettings["BINDING_PROTOCOL"]);

                    Body.Append("\n\tStep 5:Click “OK’ button.");
                    Body.Append("\nOrganization key provided here is to be used in Epi Info™ 7 during publish process.");
                    Body.Append("\n\nPlease contact the system administrator for any questions.");

                    email.To = new List <string>();
                    email.To.Add(UserBO.EmailAddress);
                    email.Body = Body.ToString();
                    success    = SendEmail(email, Constant.EmailCombinationEnum.InsertUser);
                }
            }
            else
            {
                //UserBO.Role = UserBO.Role;
                //UserBO.IsActive = UserBO.IsActive;
                success = UserDao.UpdateUserOrganization(UserBO, OrgBO);
                if (success)
                {
                    Email email = new Email();

                    StringBuilder Body = new StringBuilder();

                    Body.Append("Welcome to Epi Info™ Cloud Data Capture. \nYour account has now been created for organization - " + OrgBO.Organization + ".");
                    // var OrgKey = OrgBO.OrganizationKey;
                    var OrgKey = Epi.Web.Enter.Common.Security.Cryptography.Decrypt(OrgBO.OrganizationKey);
                    Body.Append("\n\nOrganization Key: " + OrgKey);
                    Body.Append("\n\nPlease click the link below to launch Epi Info™ Cloud Data Capture. \n" + ConfigurationManager.AppSettings["BaseURL"] + "\n\nThank you.");
                    email.Body = Body.ToString();
                    email.To   = new List <string>();
                    email.To.Add(UserBO.EmailAddress);

                    success = SendEmail(email, Constant.EmailCombinationEnum.InsertUser);
                }
            }



            return(success);
        }