コード例 #1
0
 protected void txtServer_Load(object sender, EventArgs e)
 {
     try
     {
         if (!Page.IsPostBack)
         {
             UserContext context = (UserContext)Session["UserContext"];
             if (context != null)
             {
                 TroposCS.LogOff(context);
             }
             HttpCookie LoginCookie = Request.Cookies["TroposLogin"];
             if (LoginCookie != null)
             {
                 txtServer.Text     = LoginCookie.Values["Server"];
                 txtDatabase.Text   = LoginCookie.Values["Database"];
                 txtIdentity.Text   = LoginCookie.Values["Identity"];
                 txtBusiness.Text   = LoginCookie.Values["Business"];
                 chkManager.Checked = bool.Parse(LoginCookie.Values["Manager"]);
                 string WindowsAuth = LoginCookie.Values["WindowsAuth"];
                 if (WindowsAuth != null && chkWindowsAuth.Visible)
                 {
                     chkWindowsAuth.Checked = bool.Parse(WindowsAuth);
                 }
                 ShowHideFields();
             }
         }
     }
     catch (Exception ex)
     {
         lblError.Text = ex.Message;
         return;
     }
 }
コード例 #2
0
        private DataTable GetSqlFieldChoices(UserContext context, string sqlStatement, string[] sqlParameters)
        {
            DataTable dt = new DataTable();

            dt.Locale = CultureInfo.InvariantCulture;
            dt.Columns.Add("Code", typeof(string));
            dt.Columns.Add("Description", typeof(string));

            if (!string.IsNullOrEmpty(sqlStatement))
            {
                var ds = TroposCS.ReadView(context, sqlStatement, sqlParameters);
                if (ds != null && ds.Tables.Count > 0)
                {
                    var t = ds.Tables[0];
                    for (int i = 0; i < t.Rows.Count; i++)
                    {
                        DataRow dr = dt.NewRow();
                        dr["Code"]        = t.Rows[i][0];
                        dr["Description"] = t.Rows[i][1];
                        dt.Rows.Add(dr);
                    }
                }
            }

            return(dt);
        }
コード例 #3
0
        protected void btnLogon_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.chkSaveSettings.Checked)
                {
                    HttpCookie LoginCookie = new HttpCookie("TroposLogin");
                    //LoginCookie.Path = Request.ApplicationPath;
                    LoginCookie.Values.Add("Server", txtServer.Text);
                    LoginCookie.Values.Add("Database", txtDatabase.Text);
                    LoginCookie.Values.Add("Identity", txtIdentity.Text);
                    LoginCookie.Values.Add("Business", txtBusiness.Text);
                    LoginCookie.Values.Add("Manager", chkManager.Checked.ToString());
                    LoginCookie.Values.Add("WindowsAuth", chkWindowsAuth.Checked.ToString());
                    LoginCookie.Expires = DateTime.Now.AddYears(1);;
                    Response.Cookies.Add(LoginCookie);
                }

                WindowsImpersonationContext Ctx = null;
                UserContext context;
                if (chkWindowsAuth.Checked)
                {
                    context = new UserContext(txtServer.Text, txtDatabase.Text, txtBusiness.Text);
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        WindowsIdentity WinId = (WindowsIdentity)HttpContext.Current.User.Identity;
                        Ctx = WinId.Impersonate();
                    }
                }
                else
                {
                    context = new UserContext(txtServer.Text, txtDatabase.Text, txtIdentity.Text, txtPassword.Text, txtBusiness.Text, chkManager.Checked);
                }

                //Store this applications url prefix for use when launching items from the menu
                context.ParentUrlPrefix = UrlHelper.UrlPrefix();

                bool attachedByMe = false;
                try
                {
                    context.Load(Session);
                    //This is a hack to load the resource management libraries for the 1st user to log in
                    if (!context.AttachedToTropos)
                    {
                        TroposCS.Attach(context);
                        attachedByMe = true;
                    }
                    TroposResourceProvider _trp = new TroposResourceProvider(context);
                    _trp.GetResource("TEST");
                }
                finally
                {
                    if (attachedByMe)
                    {
                        TroposCS.Detach(context);
                    }
                    if (Ctx != null)
                    {
                        Ctx.Undo();
                    }
                }

                // Create the user data
                string userDataString = string.Concat(txtServer.Text, "|"
                                                      , txtDatabase.Text, "|"
                                                      , txtIdentity.Text, "|"
                                                      , txtPassword.Text, "|"
                                                      , txtBusiness.Text, "|"
                                                      , chkManager.Checked.ToString(), "|"
                                                      , context.ParentUrlPrefix, "|"
                                                      , context.WindowsAuthentication.ToString());

                // Create the cookie that contains the forms authentication ticket
                HttpCookie authCookie = FormsAuthentication.GetAuthCookie(txtIdentity.Text, false);

                // Get the FormsAuthenticationTicket out of the encrypted cookie
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);

                // Create a new FormsAuthenticationTicket that includes our custom User Data
                FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userDataString);

                // Update the authCookie's Value to use the encrypted version of newTicket
                authCookie.Value = FormsAuthentication.Encrypt(newTicket);

                // Manually add the authCookie to the Cookies collection
                Response.Cookies.Add(authCookie);

                // Determine redirect URL and send user there
                string redirUrl = FormsAuthentication.GetRedirectUrl(txtIdentity.Text, false);
                Response.Redirect(redirUrl);
                //FormsAuthentication.RedirectFromLoginPage(this.UserContext.TroposIdentity, false);
            }
            catch (TroposDbUnexpectedErrorException)
            {
                TroposResourceProvider trp = new TroposResourceProvider(this.UserContext);
                lblError.Text = trp.GetResource("MSG_DB_ERROR");
            }
            catch (TroposDbTableExistsException)
            {
                TroposResourceProvider trp = new TroposResourceProvider(this.UserContext);
                lblError.Text = trp.GetResource("MSG_DB_ERROR");
            }
            catch (TroposDbPermissionsException)
            {
                TroposResourceProvider trp = new TroposResourceProvider(this.UserContext);
                lblError.Text = trp.GetResource("MSG_DB_PERMISSIONS");
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
                return;
            }
        }