Exemplo n.º 1
0
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                UserSystem usrsys = new UserSystem();
                Session["CurrentUser"] = usrsys.LogIn(txtLogin.Text, txtPassword.Text);
                if (GlobalFunctions.IsLocalUrl(Request.QueryString["ReturnUrl"]))
                {
                    Response.Redirect(String.Format("~/{0}", Request.QueryString["ReturnUrl"]), true);
                }
                else
                {
                    Response.Redirect("~/", false);
                }
            }
            catch (System.Data.SqlClient.SqlException sqle)
            {
                lblError.Text    = "Wystąpił nieoczekiwany błąd. (SQL)";
                lblError.Visible = true;
            }
            catch (UserException ue)
            {
                string ErrorMssg = "";
                switch (ue.Type)
                {
                case UserException.UserExceptionType.IncorrectPassword:
                    ErrorMssg = "Niepoprawne hasło.";
                    break;

                case UserException.UserExceptionType.Unknown:
                    ErrorMssg = "Wystąpił nieoczekiwany błąd.";
                    break;

                case UserException.UserExceptionType.UserNotFound:
                    ErrorMssg = "Nie ma takiego użytkownika.";
                    break;

                default:
                    ErrorMssg = "Wystąpił nieoczekiwany błąd.";
                    break;
                }
                lblError.Text    = ErrorMssg;
                lblError.Visible = true;
            }
        }