Пример #1
0
        /// <summary> Constructor for a new instance of the Home_MySobekViewer class </summary>
        /// <param name="CurrentMode"> Mode / navigation information for the current request (including interface code) </param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Logon_MySobekViewer(SobekCM_Navigation_Object CurrentMode, Custom_Tracer Tracer)
            : base(null)
        {
            Tracer.Add_Trace("Logon_MySobekViewer.Constructor", String.Empty);

            this.CurrentMode = CurrentMode;

            errorMessage = String.Empty;

            // If this is a postback, check to see if the user is valid
            if (currentMode.isPostBack)
            {
                string possible_username = String.Empty;
                string possible_password = String.Empty;
                bool   remember_me       = false;

                string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
                foreach (string thisKey in getKeys)
                {
                    switch (thisKey)
                    {
                    case "logon_username":
                        possible_username = HttpContext.Current.Request.Form[thisKey].Trim();
                        break;

                    case "logon_password":
                        possible_password = HttpContext.Current.Request.Form[thisKey].Trim();
                        break;

                    case "rememberme":
                        if (HttpContext.Current.Request.Form[thisKey].Trim() == "rememberme")
                        {
                            remember_me = true;
                        }
                        break;
                    }
                }

                if ((!String.IsNullOrEmpty(possible_password)) && (!String.IsNullOrEmpty(possible_username)))
                {
                    user = SobekCM_Database.Get_User(possible_username, possible_password, Tracer);
                    if (user != null)
                    {
                        // The user was valid here, so save this user information
                        HttpContext.Current.Session["user"] = user;

                        // Should we remember this user via cookies?
                        if (remember_me)
                        {
                            HttpCookie userCookie = new HttpCookie("SobekUser");
                            userCookie.Values["userid"]        = user.UserID.ToString();
                            userCookie.Values["security_hash"] = user.Security_Hash(HttpContext.Current.Request.UserHostAddress);
                            userCookie.Expires = DateTime.Now.AddDays(14);
                            HttpContext.Current.Response.Cookies.Add(userCookie);
                        }

                        // Forward back to their original URL (unless the original URL was this logon page)
                        string raw_url = HttpContext.Current.Items["Original_URL"].ToString();
                        if (raw_url.ToLower().IndexOf("my/logon") > 0)
                        {
                            currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                            currentMode.Redirect();
                        }
                        else
                        {
                            HttpContext.Current.Response.Redirect(raw_url, false);
                            HttpContext.Current.ApplicationInstance.CompleteRequest();
                            currentMode.Request_Completed = true;
                        }
                    }
                    else
                    {
                        errorMessage = "Invalid user/password entered";
                    }
                }
            }
        }
        /// <summary> Constructor for a new instance of the Preferences_MySobekViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="CurrentMode"> Mode / navigation information for the current request</param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        public Preferences_MySobekViewer(User_Object User, SobekCM_Navigation_Object CurrentMode, Custom_Tracer Tracer) : base(User)
        {
            Tracer.Add_Trace("Preferences_MySobekViewer.Constructor", String.Empty);

            currentMode      = CurrentMode;
            validationErrors = new List <string>();

            // Set the text to use for each value (since we use if for the validation errors as well)
            mySobekText = "my" + currentMode.SobekCM_Instance_Abbreviation;

            // Get the labels to use, by language
            accountInfoLabel       = "Account Information";
            userNameLabel          = "UserName";
            personalInfoLabel      = "Personal Information";
            familyNamesLabel       = "Last/Family Name(s)";
            givenNamesLabel        = "First/Given Name(s)";
            nicknameLabel          = "Nickname";
            emailLabel             = "Email";
            emailStatsLabel        = "Send me monthly usage statistics for my items";
            affilitionInfoLabel    = "Current Affiliation Information";
            organizationLabel      = "Organization/University";
            collegeLabel           = "College";
            departmentLabel        = "Department";
            unitLabel              = "Unit";
            selfSubmittalPrefLabel = "Self-Submittal Preferences";
            sendEmailLabel         = "Send me an email when I submit new items";
            templateLabel          = "Template";
            projectLabel           = "Default Metadata";
            defaultRightsLabel     = "Default Rights";
            rightsExplanationLabel = "(These are the default rights you give for sharing, repurposing, or remixing your item to other users. You can set this with each new item you submit, but this will be the default that appears.)";
            rightsInstructionLabel = "You may also select a <a title=\"Explanation of different creative commons licenses.\" href=\"http://creativecommons.org/about/licenses/\">Creative Commons License</a> option below.";
            otherPreferencesLabel  = "Other Preferences";
            languageLabel          = "Language";
            passwordLabel          = "Password";
            confirmPasswordLabel   = "Confirm Password";
            col1Width              = "15px";
            col2Width              = "100px";
            col3Width              = "605px";

            if (currentMode.Language == Web_Language_Enum.French)
            {
                accountInfoLabel       = "Informations sur le Compte";
                userNameLabel          = "Nom du Compte";
                personalInfoLabel      = "Des Renseignements Personnels";
                familyNamesLabel       = "Nom de Famille";
                givenNamesLabel        = "Prénoms";
                nicknameLabel          = "Pseudo";
                emailLabel             = "Email";
                affilitionInfoLabel    = "Information Affiliation Actuel";
                organizationLabel      = "Organisation / Université";
                collegeLabel           = "Collège";
                departmentLabel        = "Département";
                unitLabel              = "Unité";
                selfSubmittalPrefLabel = "Préférences Auto-Soumission";
                sendEmailLabel         = "Envoyez-moi un email lorsque je présente les nouveaux éléments";
                templateLabel          = "Modèle";
                projectLabel           = "Métadonnées par Défaut";
                defaultRightsLabel     = "Droits par Défaut";
                rightsExplanationLabel = "(Ce sont les droits par défaut que vous donnez de partager, d'adapter, ou remixer votre article à d'autres utilisateurs. Vous pouvez fixer cette valeur à chaque nouvel élément que vous soumettez, mais ce sera la valeur par défaut qui s'affiche.)";
                rightsInstructionLabel = "Vous pouvez également sélectionner une option <a title=\"Explication des différentes licences Creative Commons.\" href=\"http://creativecommons.org/about/licenses/\">Creative Commons License</a> ci-dessous.";
                otherPreferencesLabel  = "Autres Préférences";
                languageLabel          = "Langue";
                passwordLabel          = "Mot de Passe";
                confirmPasswordLabel   = "Confirmer Mot de Passe";
                col1Width              = "10px";
                col2Width              = "220px";
                col3Width              = "490px";
            }

            if (currentMode.Language == Web_Language_Enum.Spanish)
            {
                accountInfoLabel       = "Información de la Cuenta";
                userNameLabel          = "Nombre de la Cuenta";
                personalInfoLabel      = "Información Personal";
                familyNamesLabel       = "Familia Nombre";
                givenNamesLabel        = "Nombre de Pila";
                nicknameLabel          = "Nickname";
                emailLabel             = "Correo Electrónico";
                affilitionInfoLabel    = "Información de la Afiliación Actual";
                organizationLabel      = "Organización/Universidad";
                collegeLabel           = "Colegio";
                departmentLabel        = "Departamento";
                unitLabel              = "Unidad";
                selfSubmittalPrefLabel = "Preferencias de Presentación Auto-";
                sendEmailLabel         = "Enviadme un correo electrónico cuando se presento nuevos temas";
                templateLabel          = "Plantilla";
                projectLabel           = "Metadatos Predeterminado";
                defaultRightsLabel     = "Derechos por Defecto";
                rightsExplanationLabel = "(Estos son los derechos por defecto le dan para compartir, reutilización, o remezclando el tema a otros usuarios. Puede establecer esto con cada artículo nuevo que presentar, pero esto será el valor por defecto que aparece.)";
                rightsInstructionLabel = "También puede seleccionar una opción de  <a title=\"Explicación de las diferentes licencias Creative Commons\" href=\"http://creativecommons.org/about/licenses/\">Creative Commons License</a> a continuación.";
                otherPreferencesLabel  = "Otras preferencias";
                languageLabel          = "Idioma";
                passwordLabel          = "Contraseña";
                confirmPasswordLabel   = "Confirmar Contraseña";
                col1Width              = "10px";
                col2Width              = "220px";
                col3Width              = "490px";
            }

            // Is this for registration
            registration = (HttpContext.Current.Session["user"] == null);
            if (registration)
            {
                user = new User_Object();
            }


            // Set some default first
            send_usages_emails = true;
            family_name        = String.Empty;
            given_name         = String.Empty;
            nickname           = String.Empty;
            email          = String.Empty;
            organization   = String.Empty;
            college        = String.Empty;
            department     = String.Empty;
            unit           = String.Empty;
            template       = String.Empty;
            project        = String.Empty;
            username       = String.Empty;
            password       = String.Empty;
            password2      = String.Empty;
            ufid           = String.Empty;
            language       = String.Empty;
            default_rights = String.Empty;

            // Handle post back
            if (currentMode.isPostBack)
            {
                // Loop through and get the dataa
                string[] getKeys = HttpContext.Current.Request.Form.AllKeys;
                foreach (string thisKey in getKeys)
                {
                    switch (thisKey)
                    {
                    case "prefUserName":
                        username = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "password_enter":
                        password = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "password_confirm":
                        password2 = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefUfid":
                        ufid = HttpContext.Current.Request.Form[thisKey].Trim().Replace("-", "");
                        break;

                    case "prefFamilyName":
                        family_name = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefGivenName":
                        given_name = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefNickName":
                        nickname = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefEmail":
                        email = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefOrganization":
                        organization = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefCollege":
                        college = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefDepartment":
                        department = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefUnit":
                        unit = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefLanguage":
                        string language_temp = HttpContext.Current.Request.Form[thisKey];
                        if (language_temp == "es")
                        {
                            language = "Español";
                        }
                        if (language_temp == "fr")
                        {
                            language = "Français";
                        }
                        break;

                    case "prefTemplate":
                        template = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefProject":
                        project = HttpContext.Current.Request.Form[thisKey];
                        break;

                    case "prefAllowSubmit":
                        string submit_value = HttpContext.Current.Request.Form[thisKey];
                        if (submit_value == "allowsubmit")
                        {
                            desire_to_upload = true;
                        }
                        break;

                    case "prefSendEmail":
                        string submit_value2 = HttpContext.Current.Request.Form[thisKey];
                        send_email_on_submission = submit_value2 == "sendemail";
                        break;

                    case "prefEmailStats":
                        string submit_value3 = HttpContext.Current.Request.Form[thisKey];
                        send_usages_emails = submit_value3 == "sendemail";
                        break;

                    case "prefRights":
                        default_rights = HttpContext.Current.Request.Form[thisKey];
                        break;
                    }
                }

                if (registration)
                {
                    if (username.Trim().Length == 0)
                    {
                        validationErrors.Add("Username is a required field");
                    }
                    else if (username.Trim().Length < 8)
                    {
                        validationErrors.Add("Username must be at least eight digits");
                    }
                    if ((password.Trim().Length == 0) || (password2.Trim().Length == 0))
                    {
                        validationErrors.Add("Select and confirm a password");
                    }
                    if (password.Trim() != password2.Trim())
                    {
                        validationErrors.Add("Passwords do not match");
                    }
                    else if (password.Length < 8)
                    {
                        validationErrors.Add("Password must be at least eight digits");
                    }
                    if (ufid.Trim().Length > 0)
                    {
                        if (ufid.Trim().Length != 8)
                        {
                            validationErrors.Add("UFIDs are always eight digits");
                        }
                        else
                        {
                            int ufid_convert_test;
                            if (!Int32.TryParse(ufid, out ufid_convert_test))
                            {
                                validationErrors.Add("UFIDs are always numeric");
                            }
                        }
                    }
                }

                // Validate the basic data is okay
                if (family_name.Trim().Length == 0)
                {
                    validationErrors.Add("Family name is a required field");
                }
                if (given_name.Trim().Length == 0)
                {
                    validationErrors.Add("Given name is a required field");
                }
                if ((email.Trim().Length == 0) || (email.IndexOf("@") < 0))
                {
                    validationErrors.Add("A valid email is required");
                }
                if (default_rights.Trim().Length > 1000)
                {
                    validationErrors.Add("Rights statement truncated to 1000 characters.");
                    default_rights = default_rights.Substring(0, 1000);
                }

                if ((registration) && (validationErrors.Count == 0))
                {
                    bool email_exists;
                    bool username_exists;
                    SobekCM_Database.UserName_Exists(username, email, out username_exists, out email_exists, Tracer);
                    if (email_exists)
                    {
                        validationErrors.Add("An account for that email address already exists.");
                    }
                    else if (username_exists)
                    {
                        validationErrors.Add("That username is taken.  Please choose another.");
                    }
                }

                if (validationErrors.Count == 0)
                {
                    user.College      = college.Trim();
                    user.Department   = department.Trim();
                    user.Email        = email.Trim();
                    user.Family_Name  = family_name.Trim();
                    user.Given_Name   = given_name.Trim();
                    user.Nickname     = nickname.Trim();
                    user.Organization = organization.Trim();
                    user.Unit         = unit.Trim();
                    user.Set_Default_Template(template.Trim());
                    // See if the project is different, if this is not registration
                    if ((!registration) && (user.Default_Metadata_Sets[0] != project.Trim()))
                    {
                        // Determine the in process directory for this
                        string user_in_process_directory = SobekCM_Library_Settings.In_Process_Submission_Location + "\\" + user.UserName;
                        if (user.ShibbID.Trim().Length > 0)
                        {
                            user_in_process_directory = SobekCM_Library_Settings.In_Process_Submission_Location + "\\" + user.ShibbID;
                        }
                        if (Directory.Exists(user_in_process_directory))
                        {
                            if (File.Exists(user_in_process_directory + "\\TEMP000001_00001.mets"))
                            {
                                File.Delete(user_in_process_directory + "\\TEMP000001_00001.mets");
                            }
                        }
                    }
                    user.Set_Current_Default_Metadata(project.Trim());
                    user.Preferred_Language       = language;
                    user.Default_Rights           = default_rights;
                    user.Send_Email_On_Submission = send_email_on_submission;
                    user.Receive_Stats_Emails     = send_usages_emails;

                    if (registration)
                    {
                        user.Can_Submit = false;
                        user.Send_Email_On_Submission = true;
                        user.ShibbID  = ufid;
                        user.UserName = username;
                        user.UserID   = -1;

                        // Save this new user
                        SobekCM_Database.Save_User(user, password, user.Authentication_Type, Tracer);

                        // Retrieve the user from the database
                        user = SobekCM_Database.Get_User(username, password, Tracer);

                        // Special code in case this is the very first user
                        if (user.UserID == 1)
                        {
                            // Add each template and project
                            DataSet       projectTemplateSet = SobekCM_Database.Get_All_Template_DefaultMetadatas(Tracer);
                            List <string> templates          = (from DataRow thisTemplate in projectTemplateSet.Tables[1].Rows select thisTemplate["TemplateCode"].ToString()).ToList();
                            List <string> projects           = (from DataRow thisProject in projectTemplateSet.Tables[0].Rows select thisProject["MetadataCode"].ToString()).ToList();

                            // Save the updates to this admin user
                            SobekCM_Database.Save_User(user, password, User_Authentication_Type_Enum.Sobek, Tracer);
                            SobekCM_Database.Update_SobekCM_User(user.UserID, true, true, true, true, true, true, true, "edit_internal", "editmarc_internal", true, true, true, Tracer);
                            SobekCM_Database.Update_SobekCM_User_DefaultMetadata(user.UserID, new ReadOnlyCollection <string>(projects), Tracer);
                            SobekCM_Database.Update_SobekCM_User_Templates(user.UserID, new ReadOnlyCollection <string>(templates), Tracer);

                            // Retrieve the user information again
                            user = SobekCM_Database.Get_User(username, password, Tracer);
                        }

                        user.Is_Just_Registered             = true;
                        HttpContext.Current.Session["user"] = user;

                        // If they want to be able to contribue, send an email
                        if (desire_to_upload)
                        {
                            SobekCM_Database.Send_Database_Email(SobekCM_Library_Settings.System_Email, "Submittal rights requested by " + user.Full_Name, "New user requested ability to submit new items.<br /><br /><blockquote>Name: " + user.Full_Name + "<br />Email: " + user.Email + "<br />Organization: " + user.Organization + "<br />User ID: " + user.UserID + "</blockquote>", true, false, -1, -1);
                        }

                        // Email the user their registation information
                        if (desire_to_upload)
                        {
                            SobekCM_Database.Send_Database_Email(email, "Welcome to " + mySobekText, "<strong>Thank you for registering for " + mySobekText + "</strong><br /><br />You can access this directly through the following link: <a href=\"" + currentMode.Base_URL + "/my\">" + currentMode.Base_URL + "/my</a><br /><br />Full Name: " + user.Full_Name + "<br />User Name: " + user.UserName + "<br /><br />You will receive an email when your request to submit items has been processed.", true, false, -1, -1);
                        }
                        else
                        {
                            SobekCM_Database.Send_Database_Email(email, "Welcome to " + mySobekText, "<strong>Thank you for registering for " + mySobekText + "</strong><br /><br />You can access this directly through the following link: <a href=\"" + currentMode.Base_URL + "/my\">" + currentMode.Base_URL + "/my</a><br /><br />Full Name: " + user.Full_Name + "<br />User Name: " + user.UserName, true, false, -1, -1);
                        }

                        // Now, forward back to the My Sobek home page
                        currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;

                        // If this is the first user to register (who would have been set to admin), send to the
                        // system-wide settings screen
                        if (user.UserID == 1)
                        {
                            currentMode.Mode       = Display_Mode_Enum.Administrative;
                            currentMode.Admin_Type = Admin_Type_Enum.Settings;
                        }
                        currentMode.Redirect();
                    }
                    else
                    {
                        HttpContext.Current.Session["user"] = user;
                        SobekCM_Database.Save_User(user, String.Empty, user.Authentication_Type, Tracer);

                        // Now, forward back to the My Sobek home page
                        currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                        currentMode.Redirect();
                    }
                }
            }
            else
            {
                family_name              = user.Family_Name;
                given_name               = user.Given_Name;
                nickname                 = user.Nickname;
                email                    = user.Email;
                organization             = user.Organization;
                college                  = user.College;
                department               = user.Department;
                unit                     = user.Unit;
                username                 = user.UserName;
                ufid                     = user.ShibbID;
                language                 = user.Preferred_Language;
                send_email_on_submission = user.Send_Email_On_Submission;
                default_rights           = user.Default_Rights;
            }
        }