Ejemplo n.º 1
0
        public bool DoLogin()
        {
            string LoginError = "";
            bool   RetVal     = Utility.DoLogin(txtLoginUser.Text, txtLoginPassword.Text, this, ref LoginError, ajxMainAjaxPanel);

            if (!RetVal)
            {
                labError.Text = LoginError;
            }
            else
            {
                labError.Text = "";
            }
            InitializePageContent();
            return(RetVal);
        }
Ejemplo n.º 2
0
        public static bool DoLogin(string User, string Password, Page Page, ref string Error, object AjaxPanel, bool ShouldRedirect)
        {
            User     = User.ToUpper();
            Password = Password.ToUpper();
            try
            {
                if (GMembershipProvider.Default.ValidateUser(User, Password))
                {
                    FormsAuthentication.SetAuthCookie(User, false);

                    // Cria uma identificação (temporária)
                    FormsIdentity id = new FormsIdentity(new FormsAuthenticationTicket(User, false, 20));

                    // Anexa a identidade ao HttpContext atual para,temporariamente, o user ficar setado como autenticado
                    HttpContext.Current.User = new GenericPrincipal(id, new string[] { });

                    string       RefreshControlsID = HttpContext.Current.Request.QueryString["RefreshControlID"];
                    string       Url         = HttpContext.Current.Request.QueryString["url"];
                    bool         CloseWindow = HttpContext.Current.Request.QueryString["CloseWindow"] == "true";
                    RadAjaxPanel Ajax        = null;
                    if (AjaxPanel != null && AjaxPanel is RadAjaxPanel)
                    {
                        Ajax = (RadAjaxPanel)AjaxPanel;
                    }
                    if ((RefreshControlsID == "" || RefreshControlsID == null) && Page.Request["RefreshControlsIDHidden"] != null)
                    {
                        RefreshControlsID = Page.Request["RefreshControlsIDHidden"];
                    }
                    if ((Url == "" || Url == null) && Page.Request["PageToRedirectHidden"] != null)
                    {
                        Url = Page.Request["PageToRedirectHidden"];
                    }
                    if (RefreshControlsID != "" && RefreshControlsID != null)
                    {
                        if (AjaxPanel == null)
                        {
                            Page.ClientScript.RegisterStartupScript(Page.GetType(), "Refresh", "<script>getParentPage().RefreshNavigationControl('" + RefreshControlsID + "','" + Url + "');</script>");
                        }
                        else
                        {
                            Ajax.ResponseScripts.Add("getParentPage().RefreshNavigationControl('" + RefreshControlsID + "','" + Url + "');");
                        }
                    }
                    else if (ShouldRedirect)
                    {
                        if (Url != "" && Url != null)
                        {
                            Url = Base64.Decode(Url);
                            if (AjaxPanel == null)
                            {
                                Page.ClientScript.RegisterStartupScript(Page.GetType(), "PageToRedirect", "<script>document.location.href = '" + Url + "';</script>");
                            }
                            else
                            {
                                Ajax.ResponseScripts.Add("document.location.href = '" + Url + "';");
                            }
                        }
                    }

                    if (AjaxPanel != null)
                    {
                        Ajax.ResponseScripts.Add("try{OnLoginSucceded();}catch(ex){}");
                        Ajax.ResponseScripts.Add("document.forms[0].RefreshControlsIDHidden.value = \"\";");
                        Ajax.ResponseScripts.Add("document.forms[0].PageToRedirectHidden.value = \"\";");
                        if (CloseWindow)
                        {
                            Ajax.ResponseScripts.Add("try{getParentPage().GetRadWindowManager().GetActiveWindow().Close();}catch(ex){}");
                        }
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Succeded", "<script>OnLoginSucceded();</script>");
                        if (CloseWindow)
                        {
                            Page.ClientScript.RegisterStartupScript(Page.GetType(), "CloseWindow", "<script>try{getParentPage().GetRadWindowManager().GetActiveWindow().Close();}catch(ex){}</script>");
                        }
                    }
                    return(true);
                }
                else
                {
                    if (User != User.Trim() || Password != Password.Trim())
                    {
                        return(Utility.DoLogin(User.Trim(), Password.Trim(), Page, ref Error, AjaxPanel, ShouldRedirect));
                    }
                    Error = "Usuário ou senha inválido(s)!";
                }
            }
            catch (Exception ex)
            {
                Error = "Erro interno ao efetuar login! <a href = \"javascript:return false;\"  onclick = \"alert('" + ex.Message.ToString().Replace("'", "").Replace("\"", "") + "',0, 'Erro ao realizar login');\" > Ver mais </a>";
            }
            return(false);
        }