Ejemplo n.º 1
0
        /// <summary>
        /// Localizes the page and set user's login from cookies.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            Logger.Log("Session started", LogLevel.Info);
            Localize();

            if (IsPostBack || IsCallback)
            {
                return;
            }

            ASPxTextBox  UserName           = (ASPxTextBox)LoginControl.FindControl("UserName");
            ASPxTextBox  Password           = (ASPxTextBox)LoginControl.FindControl("Password");
            ASPxCheckBox RememberMeCheckBox = (ASPxCheckBox)LoginControl.FindControl("RememberMeCheckBox");

            if (Request.Cookies["username"] != null)
            {
                UserName.Text = Request.Cookies["username"].Value;
                RememberMeCheckBox.Checked = true;
                Password.Focus();
            }
            else
            {
                RememberMeCheckBox.Checked = false;
                UserName.Focus();
            }
        }
Ejemplo n.º 2
0
        protected void LogIn(object sender, AuthenticateEventArgs e)
        {
            try
            {
                //Session.Clear();
                if (string.IsNullOrEmpty(LoginControl.UserName) || string.IsNullOrEmpty(LoginControl.Password))
                {
                    LoginControl.FailureText = Server.HtmlEncode(GetLocalizedString("PxWebLoginMissingUserOrPassw"));
                    return;
                }
                if (Membership.ValidateUser(LoginControl.UserName, LoginControl.Password))
                {
                    FormsAuthentication.RedirectFromLoginPage(LoginControl.UserName, false);
                    Button showLoginSectionBtn    = (Button)LoginControl.FindControl("ShowLoginSection");
                    var    showLoginSectionHolder = (Label)LoginControl.FindControl("ShowLoginSectionHolder");
                    Label  loggedInAsLabel        = (Label)LoginControl.FindControl("LoggedInAs");
                    loggedInAsLabel.Text        = "Logget inn som " + LoginControl.UserName;
                    showLoginSectionHolder.Text = "show";

                    string currentUrl = Request.RawUrl;
                    Response.Redirect(currentUrl);
                }
                else
                {
                    LoginControl.FailureText = Server.HtmlEncode(GetLocalizedString("PxWebWrongLogin"));
                }
            }

            catch (Exception ex)
            {
                _logger.Error("Failed to Login. Username " + LoginControl.UserName + "Error:" + ex.Message);
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Show success or error messages depends on password reminding.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ForgotCallbackPanel_Callback(object source, CallbackEventArgsBase e)
        {
            try
            {
                //FIXME: this is testing code for feed import, you could remove it when app in live
                //CommonParser<CanonChannelMonitor> export = ImportFactory.GetParser(
                //                   Canon.Data.Enums.ChannelTypeEnum.XML,
                //                   23,
                //                   @"d:\Memos\Projects\Canon\CanonMonitor\CanonWebApp\Uploaded\21_2009-08-19.xml",
                //                   Server.MapPath("Uploaded"), string.Empty);
                //export.Logger = WebVariables.Logger;
                //if (!export.ExportToDb()) return;

                //SimpleXmlParser parser = new SimpleXmlParser(new System.IO.FileInfo(@"d:\Memos\Projects\Canon\CanonMonitor\CanonWebApp\Uploaded\21_2009-08-19.xml"));
                //List<Dictionary<string, string>> parsed = parser.Parse();
                //return;

                if (String.Equals(e.Parameter, "Remind", StringComparison.CurrentCultureIgnoreCase))
                {
                    ASPxTextBox  EmailTextBox      = (ASPxTextBox)LoginControl.FindControl("ForgotPopupControl").FindControl("ForgotCallbackPanel").FindControl("EmailTextBox");
                    HtmlTableRow SuccessMessageDiv = (HtmlTableRow)LoginControl.FindControl("ForgotPopupControl").FindControl("ForgotCallbackPanel").FindControl("SuccessMessageDiv");
                    HtmlTableRow ErrorMessageDiv   = (HtmlTableRow)LoginControl.FindControl("ForgotPopupControl").FindControl("ForgotCallbackPanel").FindControl("ErrorMessageDiv");

                    bool isSent = Business.User.SendRemindPasswordEmail(EmailTextBox.Text);

                    SuccessMessageDiv.Visible = isSent;
                    ErrorMessageDiv.Visible   = !isSent;
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), LogLevel.Fatal);
            }
        }
Ejemplo n.º 4
0
        protected void SetFields()
        {
            Button showLoginSectionBtn    = (Button)LoginControl.FindControl("ShowLoginSection");
            var    loggedInSection        = LoginControl.FindControl("LoggedInDiv");
            var    logInSection           = LoginControl.FindControl("LoginSection");
            var    showLoginSectionHolder = (Label)LoginControl.FindControl("ShowLoginSectionHolder");
            Label  loggedInAsLabel        = (Label)LoginControl.FindControl("LoggedInAs");
            Label  UserNameLabel          = (Label)LoginControl.FindControl("lblUserName");
            Label  PasswordLabel          = (Label)LoginControl.FindControl("lblPassword");

            UserNameLabel.Text = Server.HtmlEncode(GetLocalizedString("PxWebUsername"));
            PasswordLabel.Text = Server.HtmlEncode(GetLocalizedString("PxWebPassword"));
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                showLoginSectionBtn.Text = Server.HtmlEncode(GetLocalizedString("PxWebLogin"));
                loggedInSection.Visible  = false;
                if (showLoginSectionHolder.Text == "show")
                {
                    logInSection.Visible = false;
                }
                else
                {
                    logInSection.Visible = true;
                    Button loginBtn = (Button)LoginControl.FindControl("Login");
                    loginBtn.Text = Server.HtmlEncode(GetLocalizedString("PxWebLogin"));
                }
            }
            else
            {
                showLoginSectionBtn.Text = Server.HtmlEncode(GetLocalizedString("PxWebLogout"));
                loggedInSection.Visible  = true;
                logInSection.Visible     = false;
                loggedInAsLabel.Text     = Server.HtmlEncode(GetLocalizedString("PxWebLoggedIn")) + " " + HttpContext.Current.User.Identity.Name;
            }
        }
Ejemplo n.º 5
0
        protected void LogOut()
        {
            try
            {
                Button showLoginSectionBtn = (Button)LoginControl.FindControl("ShowLoginSection");
                FormsAuthentication.SignOut();
                Session.Clear();
                Response.Redirect("~/" + PxUrl.PX_START + "/" + PxUrlObj.Language + "/");
            }

            catch (Exception ex)
            {
                _logger.Error("Failed to Logout. Username " + LoginControl.UserName + "Error:" + ex.Message);
                throw;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Localizes text depending on selected language.
        /// </summary>
        private void Localize()
        {
            ASPxTextBox UserName = (ASPxTextBox)LoginControl.FindControl("UserName");
            ASPxTextBox Password = (ASPxTextBox)LoginControl.FindControl("Password");

            UserName.ValidationSettings.RequiredField.ErrorText = Utilities.GetResourceString("Validators", "UserNameRequiredValidator");
            Password.ValidationSettings.RequiredField.ErrorText = Utilities.GetResourceString("Validators", "PasswordRequiredValidator");

            ASPxPopupControl ForgotPopupControl = (ASPxPopupControl)LoginControl.FindControl("ForgotPopupControl");

            ForgotPopupControl.HeaderText = Utilities.GetResourceString("Headers", "RemindPassword");

            ASPxTextBox EmailTextBox = (ASPxTextBox)LoginControl.FindControl("ForgotPopupControl").FindControl("ForgotCallbackPanel").FindControl("EmailTextBox");

            EmailTextBox.ValidationSettings.RequiredField.ErrorText     = Utilities.GetResourceString("Validators", "EmailRequiredValidator");
            EmailTextBox.ValidationSettings.RegularExpression.ErrorText = Utilities.GetResourceString("Validators", "EmailFormatValidator");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Save cookies and set current language.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LoginControl_LoggedIn(object sender, EventArgs e)
        {
            // Set cookies
            bool   isRememberMeChecked = ((ASPxCheckBox)LoginControl.FindControl("RememberMeCheckBox")).Checked;
            string username            = ((ASPxTextBox)LoginControl.FindControl("UserName")).Text;

            if (isRememberMeChecked)
            {
                HttpCookie cookie = new HttpCookie("username", username);
                cookie.Expires = DateTime.Now.AddYears(1);
                Response.Cookies.Add(cookie);
            }
            else
            {
                // Set cookies expired
                if (Request.Cookies["username"] != null)
                {
                    Response.Cookies["username"].Expires = DateTime.Now;
                }
            }
        }
Ejemplo n.º 8
0
        protected void LoginExpand(object sender, EventArgs e)
        {
            var    showLoginSectionHolder = (Label)LoginControl.FindControl("ShowLoginSectionHolder");
            var    showLoginSectionBtn    = (Button)sender;
            Button loginBtn = (Button)LoginControl.FindControl("Login");

            if (showLoginSectionBtn.Text == Server.HtmlEncode(GetLocalizedString("PxWebLogout")))
            {
                LogOut();
            }
            else
            {
                this.Page.Form.DefaultFocus = LoginControl.UserName;
                if (showLoginSectionHolder.Text == "show")
                {
                    showLoginSectionHolder.Text = "hide";
                }
                else
                {
                    showLoginSectionHolder.Text = "show";
                }
            }
            SetFields();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Show error lable and clear password.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void LoginControl_LoginError(object sender, EventArgs e)
 {
     LoginErrorLabel.Visible = true;
     ((ASPxTextBox)LoginControl.FindControl("Password")).Text = String.Empty;
 }
Ejemplo n.º 10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     LoginControl.FindControl("RememberMe").Visible = false;
 }