Пример #1
0
        public ActionResult EmailPassword(string email)
        {
            User user = busUser.LoadUserByEmail(email);

            if (user == null)
            {
                // always confirm - otherwise link gets spammed
                ErrorDisplay.ShowMessage("We've sent password recovery info to: " + busUser.Entity.Email);
            }
            //ErrorDisplay.ShowError(
            //        "Email address doesn't exist. Please make sure you have typed the address correctly");
            else
            {
                // Always create a new random password
                string password = StringUtils.NewStringId();
                user.Password = App.EncodePassword(password, user.Id);
                busUser.Save();

                if (AppWebUtils.SendEmail(App.Configuration.ApplicationTitle + " Email Information",
                                          "Your CodePaste account password is: " + password + "\r\n\r\n" +
                                          "You can log on at: " + WebUtils.GetFullApplicationPath() + "\r\n\r\n" +
                                          "Please log in, view your profile and then change your password to something you can more easily remember.",
                                          busUser.Entity.Email,
                                          true))
                {
                    ErrorDisplay.ShowMessage("We've sent password recovery info to: " + busUser.Entity.Email);
                }
                else
                {
                    ErrorDisplay.ShowError("Emailing of password failed.");
                }
            }

            return(View(ViewModel));
        }
Пример #2
0
        public ActionResult Configuration()
        {
            ConfigurationViewModel model = new ConfigurationViewModel();

            model.DebugModeList = AppWebUtils.GetSelectListFromEnum(typeof(DebugModes), App.Configuration.DebugMode.ToString());

            return(View(model));
        }
Пример #3
0
        /// <summary>
        /// Makes user account inactive, sets a new validator
        /// and then emails the user.
        /// Assume busUser.Entity is set.
        /// </summary>
        private void SetAccountForEmailValidation()
        {
            busUser.SetUserForEmailValidation();
            busUser.Save();

            var msg = string.Format(
                @"In order to validate your email address for CodePaste.net, please click or paste the
following link into your browser's address bar: 

{0}

Once you click the link you're ready to create new
code pastes with your account on the CodePaste.net site.

Sincerely,

The CodePaste.net Team
", WebUtils.ResolveServerUrl("~/Account/ValidateEmail/" + busUser.Entity.Validator));

            AppWebUtils.SendEmail("Codepaste.net Email Validation",
                                  msg, busUser.Entity.Email, true);
        }
Пример #4
0
        public ActionResult Search(FormCollection formVars)
        {
            ListSnippetViewModel model = new ListSnippetViewModel(this);

            model.AppUserState = this.AppUserState;
            model.ErrorDisplay = this.ErrorDisplay;
            model.PageTitle    = "Search Code Snippets";

            model.SearchOrderItems = AppWebUtils.GetSelectListFromEnum(typeof(SearchOrderTypes), "Entered");

            using (busCodeSnippet busSnippet = new busCodeSnippet())
            {
                model.Controller = this;
                model.busSnippet = busSnippet;

                model.Parameters = new CodeSnippetSearchParameters();

                this.TryUpdateModel(model.Parameters);

                var snippetList      = busSnippet.GetSearchList(model.Parameters);
                int snippetListCount = 0;
                if (snippetList != null)
                {
                    snippetListCount = snippetList.Count();
                }

                if (formVars.Count > 0)
                {
                    if (snippetList == null)
                    {
                        this.ErrorDisplay.ShowError("Please provide at least one search criterion.");
                    }
                    else if (snippetListCount < 1)
                    {
                        this.ErrorDisplay.ShowError("No matches found for your search criteria.");
                    }
                }

                if (snippetList != null)
                {
                    model.Paging           = new PagingDetails();
                    model.Paging.PageCount = (int)Math.Ceiling(Convert.ToDecimal(snippetListCount) / Convert.ToDecimal(model.Paging.PageSize));

                    int.TryParse(Request.Params["page"] ?? "1", out model.Paging.Page);

                    if (model.Paging.Page > 0 && snippetListCount > model.Paging.PageSize)
                    {
                        snippetList = snippetList.Skip((model.Paging.Page - 1) * model.Paging.PageSize)
                                      .Take(model.Paging.PageSize);
                    }
                    model.SnippetList = snippetList.ToList();
                }
                else
                {
                    model.SnippetList = new List <CodeSnippetListItem>();
                }


                ActionResult result = this.ApiResult(model.SnippetList);
                if (result != null)
                {
                    return(result);
                }
            }

            return(View("Search", model));
        }
Пример #5
0
        protected void Application_Error()
        {
            try
            {
                Exception serverException = Server.GetLastError();

                //WebErrorHandler errorHandler;

                //// Try to log the inner Exception since that's what
                //// contains the 'real' error.
                //if (serverException.InnerException != null)
                //    serverException = serverException.InnerException;

                //errorHandler = new WebErrorHandler(serverException);

                //// MUST clear out any previous response in case error occurred in a view
                //// that already started rendering
                //Response.Clear();


                // Log the error if specified
                if (LogManagerConfiguration.Current.LogErrors)
                {
                    //errorHandler.Parse();

                    //try
                    //{
                    WebLogEntry entry = new WebLogEntry(serverException, this.Context);
                    //entry.Details = errorHandler.ToString();

                    LogManager.Current.WriteEntry(entry);
                    //}
                    //catch {  /* Log Error shouldn't kill the error handler */ }
                }

                // Retrieve the detailed String information of the Error
                string ErrorDetail = ""; //errorHandler.ToString();

                // Optionally email it to the Admin contacts set up in WebStoreConfig
                if (!string.IsNullOrEmpty(AppSecurity.Configuration.ErrorEmailAddress))
                {
                    AppWebUtils.SendAdminEmail(AppSecurity.Configuration.ApplicationTitle + "Error: " + Request.RawUrl, ErrorDetail, "",
                                               AppSecurity.Configuration.ErrorEmailAddress);
                }


                // Debug modes handle different error display mechanisms
                // Default  - default ASP.Net - depends on web.config settings
                // Developer  - display a generic application error message with no error info
                // User  - display a detailed error message with full error info independent of web.config setting
                if (AppSecurity.Configuration.DebugMode == DebugModes.DeveloperErrorMessage)
                {
                    Server.ClearError();
                    Response.TrySkipIisCustomErrors = true;
                    ErrorController.ShowErrorPage("Application Error", "<div class='codedisplay'><pre id='Code'>" + HttpUtility.HtmlEncode(ErrorDetail) + "</pre></div>");
                    return;
                }

                else if (AppSecurity.Configuration.DebugMode == DebugModes.ApplicationErrorMessage)
                {
                    string StockMessage =
                        "The Server Administrator has been notified and the error logged.<p>" +
                        "Please continue by either clicking the back button or by returning to the home page.</p>" +
                        "<p><b><a href='" + Request.ApplicationPath + "'>Click here to continue...</a></b></p>";

                    // Handle some stock errors that may require special error pages
                    HttpException httpException = serverException as HttpException;
                    if (httpException != null)
                    {
                        int HttpCode = httpException.GetHttpCode();
                        Server.ClearError();

                        if (HttpCode == 404) // Page Not Found
                        {
                            Response.StatusCode = 404;
                            ErrorController.ShowErrorPage("Page not found",
                                                          "You've accessed an invalid page on this Web server. " +
                                                          StockMessage, null);
                            return;
                        }
                        if (HttpCode == 401) // Access Denied
                        {
                            Response.StatusCode = 401;
                            ErrorController.ShowErrorPage("Access Denied",
                                                          "You've accessed a resource that requires a valid login. " +
                                                          StockMessage);
                            return;
                        }
                    }

                    // Display a generic error message
                    Server.ClearError();
                    Response.StatusCode = 500;

                    Response.TrySkipIisCustomErrors = true;

                    ErrorController.ShowErrorPage("Application Error",
                                                  "We're sorry, but an unhandled error occurred on the server. " +
                                                  StockMessage);

                    return;
                }

                return;
            }
            catch (Exception ex)
            {
                // Failure in the attempt to report failure - try to email
                if (!string.IsNullOrEmpty(AppSecurity.Configuration.ErrorEmailAddress))
                {
                    AppWebUtils.SendAdminEmail(AppSecurity.Configuration.ApplicationTitle + "Error: " + Request.RawUrl,
                                               "Application_Error failed!\r\n\r\n" +
                                               ex.ToString(), "", AppSecurity.Configuration.ErrorEmailAddress);
                }

                // and display an error message
                Server.ClearError();
                Response.StatusCode             = 500;
                Response.TrySkipIisCustomErrors = true;

                ErrorController.ShowErrorPage("Application Error Handler Failed",
                                              "The application Error Handler failed with an exception." +
                                              (AppSecurity.Configuration.DebugMode == DebugModes.DeveloperErrorMessage ? "<pre>" + ex.ToString() + "</pre>" : ""), null);
            }
        }