示例#1
0
        /// <summary>
        /// Bind the Data to the Page.
        /// </summary>
        private void BindData()
        {
            // page size options
            string[] sizes = { "10", "25", "50", "100" };

            foreach (string size in sizes)
            {
                PageSizeList.Items.Add(size);
            }

            // Search is not required for Settings Page
            HomeContext.HideSearch();

            try
            {
                // load
                WebSettings settings       = new WebSettings(web);
                string      pageSizeString = settings.PageSize.ToString();

                // page size
                foreach (ListItem item in PageSizeList.Items)
                {
                    if (item.Value == pageSizeString)
                    {
                        item.Selected = true;
                    }
                }
            }
            catch (SoapException ex)
            {
                if (!HandleException(ex))
                {
                    throw;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Do Login
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <param name="check">Perform browser checks.</param>
        private void DoLogin(string username, string password, bool check)
        {
            // client information
            log.Info(Context, "Client Information: {0}, {1}, {2}",
                     username, Context.Request.UserHostName,
                     Context.Request.UserAgent);

            // expires for new cookies
            DateTime expires = DateTime.Now + TimeSpan.FromDays(30);

            // check for cookies
            if (check)
            {
                HttpCookie testCookie = Request.Cookies["test"];
                if (testCookie == null)
                {
                    Message.Text = "LOGIN.NOCOOKIES";

                    // log access
                    log.Info(Context, "Login Failed: Browser Cookies Disabled");

                    return;
                }
            }

            // check for running scripts
            // NOTE: check the value for iChain
            if (check)
            {
                string noscript = Request.Form.Get("noscript");
                if ((noscript != null) && (noscript == "true"))
                {
                    Message.Text = "LOGIN.NOSCRIPT";

                    // log access
                    log.Info(Context, "Login Failed: Browser Scripts Disabled");

                    return;
                }
            }

            try
            {
                // connection
                iFolderWeb weblogin = new iFolderWeb();

                // update web url
                // always use the original path from the WSDL file
                string url = Environment.GetEnvironmentVariable("SimiasUrl");
                if (url == null)
                {
                    url = System.Configuration.ConfigurationSettings.AppSettings.Get("SimiasUrl");
                }

#if TESTING
                url = "http://localhost:8086";
#endif

                UriBuilder loginUrl = new UriBuilder(url);
                loginUrl.Path = (new Uri(weblogin.Url)).PathAndQuery;
                weblogin.Url  = loginUrl.Uri.ToString();

                UTF8Encoding utf8Name = new UTF8Encoding();
                byte[]       encodedCredsByteArray = utf8Name.GetBytes(username);
                string       iFolderUserBase64     = Convert.ToBase64String(encodedCredsByteArray);

                encodedCredsByteArray = utf8Name.GetBytes(password);
                string iFolderPassBase64 = Convert.ToBase64String(encodedCredsByteArray);



                // credentials
                weblogin.PreAuthenticate = true;
                weblogin.Credentials     = new NetworkCredential(iFolderUserBase64, iFolderPassBase64);

                // cookies
                weblogin.CookieContainer = new CookieContainer();
                //Initial Login
                iFolderUser loginuser = null;;
                try
                {
                    loginuser = weblogin.GetAuthenticatedUser();
                }
                catch (WebException ex)
                {
                    log.Info(Context, ex, "Login Failed");
                    string ccode = LanguageList.SelectedValue == null ? "en" : LanguageList.SelectedValue;
                    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(ccode);
                    if (!HandleException(ex))
                    {
                        throw;
                    }
                    return;
                }
                catch (Exception e)
                {
                    //for now give a general message
                    log.Info(Context, e, "Login Failed");
                    string ccode = LanguageList.SelectedValue == null ? "en" : LanguageList.SelectedValue;
                    Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(ccode);
                    Message.Text = "LOGIN.UNAUTHORIZED";
                    return;
                }


                url = weblogin.GetHomeServerForUser(loginuser.UserName, password);

                iFolderWeb web = new iFolderWeb();

                UriBuilder webUrl = new UriBuilder(url);
                webUrl.Path = (new Uri(web.Url)).PathAndQuery;

                web.Url = webUrl.Uri.ToString();

                string multibyteserver = weblogin.GetServerStatus();

                // credentials
                web.PreAuthenticate = true;
                if (multibyteserver == "no")
                {
                    web.Credentials = new NetworkCredential(username, password);
                }
                else
                {
                    web.Credentials = new NetworkCredential(iFolderUserBase64, iFolderPassBase64);
                }

                // cookies
                web.CookieContainer = new CookieContainer();

                // user, system, and server
                iFolderUser user = null;
                try
                {
                    user = web.GetAuthenticatedUser();
                }
                catch (WebException ex)
                {
                    log.Info(Context, ex, "Login Failed");
                    if (!HandleException(ex))
                    {
                        throw;
                    }
                    return;
                }
                catch (Exception e)
                {
                    //for now give a general message
                    log.Info(Context, e, "Login Failed");
                    Message.Text = "LOGIN.UNAUTHORIZED";
                    return;
                }

                Session["Connection"] = web;
                Session["User"]       = user;
                iFolderSystem system = web.GetSystem();
                Session["System"] = system;
                iFolderServer server = web.GetHomeServer();
                Session["Server"] = server;

                encodedCredsByteArray = utf8Name.GetBytes(user.UserName);
                iFolderUserBase64     = Convert.ToBase64String(encodedCredsByteArray);

                // new username cookie for 30 days
                Response.Cookies.Remove("username");
                Response.Cookies["username"].Value   = (multibyteserver == "no") ? user.UserName : iFolderUserBase64;
                Response.Cookies["username"].Expires = expires;
                Response.Cookies["username"].Path    = "/ifolder/";
                Session["Language"] = "en";
                string code = "en";
                // ui language
                if (LanguageList.SelectedValue == null || LanguageList.SelectedValue == String.Empty)
                {
                    /// Case when single sign on happens without the login page so no language selected
                    if ((Request.UserLanguages != null) && (Request.UserLanguages.Length > 0))
                    {
                        code = Request.UserLanguages[0];
                        if (!(code.StartsWith("zh") || code.StartsWith("pt")))
                        {
                            code = code.Substring(0, 2);
                        }
                        Session["Language"] = code;
                    }
                }
                else
                {
                    /// Normal login so select from the list
                    code = LanguageList.SelectedValue;
                    Session["Language"] = LanguageList.SelectedValue;
                }

                // settings
                WebSettings settings = new WebSettings(web);
                Session["Settings"] = settings;

                Response.Cookies["language"].Value   = code;
                Response.Cookies["language"].Expires = expires;
                Response.Cookies["language"].Path    = "/ifolder/";

                // log access
                log.Info(Context, "Login Successful");

                // redirect
                FormsAuthentication.RedirectFromLoginPage(user.UserName, false);
            }
            catch (WebException ex)
            {
                // log access
                log.Info(Context, ex, "Login Failed");

                if (!HandleException(ex))
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                // log access
                log.Info(Context, ex, "Login Failed");

                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Save Button Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                // load
                WebSettings settings = new WebSettings(web);

                // page size
                settings.PageSize = int.Parse(PageSizeList.SelectedValue);

                // save
                settings.Save(web);

                Session["Settings"] = settings;

                if (ChangePassword.Checked == true)
                {
                    if (CurrentPasswordText.Text.Trim() == "" || NewPasswordText.Text.Trim() == "" || VerifyNewPasswordText.Text.Trim() == "")
                    {
                        Message.Text = GetString("EMPTY_PASSWORD");
                        return;
                    }
                    if (NewPasswordText.Text.Trim() != VerifyNewPasswordText.Text.Trim())
                    {
                        Message.Text = GetString("PASSWORDS_NOT_MATCH");
                        return;
                    }
                    if (CurrentPasswordText.Text.Trim() == NewPasswordText.Text.Trim())
                    {
                        Message.Text = GetString("SAMEOLDPASSWORD");
                        return;
                    }

                    int status = web.ChangePassword(CurrentPasswordText.Text.Trim(), NewPasswordText.Text.Trim());
                    if (status != 0)
                    {
                        string FailedStatus = GetString("PASSWORDCHANGEFAILED");
                        switch (status)
                        {
                        case 1:
                            FailedStatus += GetString("INCORRECTOLDPASSWORD");
                            break;

                        case 2:
                            FailedStatus += GetString("FAILEDTORESETPASSWORD");
                            break;

                        case 3:
                            FailedStatus += GetString("LOGINDISABLED");
                            break;

                        case 4:
                            FailedStatus += GetString("USERACCOUNTEXPIRED");
                            break;

                        case 5:
                            FailedStatus += GetString("CANNOTCHANGEPASSWORD");
                            break;

                        case 6:
                            FailedStatus += GetString("LOGINPASSWORDEXPIRED");
                            break;

                        case 7:
                            FailedStatus += GetString("PASSWORDMINLENGTH");
                            break;

                        case 8:
                            FailedStatus += GetString("USERNOTFOUNDINSIMIAS");
                            break;

                        default:
                            FailedStatus += GetString("CHANGE.UNKNOWN");
                            break;
                        }
                        Message.Text = FailedStatus;
                        return;
                    }
                    else
                    {
                        OnPasswordChanged("true");
                    }
                }
            }
            catch (SoapException ex)
            {
                if (!HandleException(ex))
                {
                    throw;
                }
            }

            // return
            CancelButton_Click(sender, e);
        }