示例#1
0
        public ActionResult MarkAsSpam(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            if (!story.CanMarkAsSpam(CurrentUser))
                            {
                                viewData = story.HasMarkedAsSpam(CurrentUser) ?
                                           new JsonViewData {
                                    errorMessage = "Ju¿ zaznaczy³eœ ten artyku³ jako spam."
                                } :
                                new JsonViewData {
                                    errorMessage = "Nie masz uprawnieñ do zaznaczania tego artyku³u jako spam."
                                };
                            }
                            else
                            {
                                _storyService.MarkAsSpam(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser, CurrentUserIPAddress);
                                unitOfWork.Commit();

                                viewData = new JsonViewData {
                                    isSuccessful = true
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("oznaczania artyku³u jako spam")
                    };
                }
            }

            return(Json(viewData));
        }
示例#2
0
        public ActionResult MarkAsOffended(string storyId, string commentId)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(storyId), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => storyId.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => string.IsNullOrEmpty(commentId), "Identyfikator komentarza nie mo¿e byæ pusty."),
                new Validation(() => commentId.ToGuid().IsEmpty(), "Niepoprawny identyfikator komentarza."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(storyId.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            IComment comment = story.FindComment(commentId.ToGuid());

                            if (comment == null)
                            {
                                viewData = new JsonViewData {
                                    errorMessage = "Podany komentarz nie istnieje."
                                };
                            }
                            else
                            {
                                _storyService.MarkAsOffended(comment, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);

                                unitOfWork.Commit();

                                viewData = new JsonViewData {
                                    isSuccessful = true
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("zaznaczania komentarza jako obraŸliwy")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult AddEvent(EventViewData model)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrWhiteSpace(model.EventLink.NullSafe()), "Link do wydarzenia nie może być pusty."),
                new Validation(() => string.IsNullOrWhiteSpace(model.EventName.NullSafe()), "Tytuł wydarzenia nie może być pusty."),
                new Validation(() => model.EventUserEmail.NullSafe().IsEmail() == false, "Nieprawidłowy adres e-mail."),
                new Validation(() => model.Id.ToGuid() != Guid.Empty, "Id wydarzenia nie może być podane"),
                new Validation(() => !model.EventEndDate.IsLaterThan(model.EventDate), "Nieprawidłowa data zakończenia wydarzenia.")
                );

            if (viewData == null)
            {
                try
                {
                    var eventApproveStatus = CurrentUser != null && CurrentUser.IsAdministrator() &&
                                             model.IsApproved;

                    if (eventApproveStatus)
                    {
                        model.GoogleEventId = _googleService.EventApproved(new CommingEvent(model.EventName, model.EventLink, model.GoogleEventId, model.EventDate, model.EventEndDate, model.EventCity, model.EventPlace, model.EventLead, model.IsOnline));
                    }

                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        var commingEvent = _factory.CreateCommingEvent(
                            model.EventUserEmail,
                            model.EventLink,
                            model.EventName,
                            model.GoogleEventId,
                            model.EventDate,
                            model.EventEndDate,
                            model.EventCity,
                            model.EventPlace,
                            model.EventLead,
                            eventApproveStatus,
                            model.IsOnline
                            );
                        _commingEventRepository.Add(commingEvent);

                        unitOfWork.Commit();
                        _aggregator.GetEvent <UpcommingEventEvent>()
                        .Publish(new UpcommingEventEventArgs(model.EventName, model.EventLink));
                        Log.Info("Event registered: {0}", commingEvent.EventName);

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    viewData = new JsonViewData
                    {
                        errorMessage = FormatStrings.UnknownError.FormatWith("dodawania wydarzenia")
                    };
                }
            }
            return(Json(viewData));
        }
示例#4
0
        public ActionResult Promote(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            if (!story.CanPromote(CurrentUser))
                            {
                                viewData = story.HasPromoted(CurrentUser) ?
                                           new JsonViewData {
                                    errorMessage = "Ju¿ wypromowa³eœ ten artyku³."
                                } :
                                new JsonViewData {
                                    errorMessage = "Nie mo¿esz promowaæ tego artyku³u."
                                };
                            }
                            else
                            {
                                _storyService.Promote(story, CurrentUser, CurrentUserIPAddress);
                                unitOfWork.Commit();

                                viewData = new JsonVoteViewData {
                                    isSuccessful = true, votes = story.VoteCount, text = GetText(story.VoteCount)
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("promowaniu artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
示例#5
0
        public ActionResult Publish()
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.IsAdministrator(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    _storyService.Publish();

                    viewData = new JsonViewData {
                        isSuccessful = true
                    };
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("publishing stories")
                    };
                }
            }

            return(Json(viewData));
        }
示例#6
0
        public ActionResult Publish()
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.IsAdministrator(), "Nie masz praw do wo³ywania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        _storyService.Publish();

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };

                        unitOfWork.Commit();
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("publikowania artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
示例#7
0
        public ActionResult Login(string userName, string password, bool?rememberMe)
        {
            var viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(userName.NullSafe()), "User name cannot be blank."),
                new Validation(() => string.IsNullOrEmpty(password.NullSafe()), "Password cannot be blank.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindByUserName(userName.Trim());

                        if (user != null)
                        {
                            viewData = Validate <JsonViewData>(
                                new Validation(() => user.IsLockedOut, "Your account is currently locked out. Please contact the support for this issue."),
                                new Validation(() => !user.IsActive, "Your account is not activated yet. Please click the activation link in the registration mail to activate your account."),
                                new Validation(() => user.IsOpenIDAccount(), "Specified user login is only valid for OpenID.")
                                );

                            if (viewData == null)
                            {
                                if (string.Compare(user.Password, password.Trim().Hash(), StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    user.LastActivityAt = SystemTime.Now();
                                    unitOfWork.Commit();

                                    FormsAuthentication.SetAuthCookie(userName, rememberMe ?? false);
                                    viewData = new JsonViewData {
                                        isSuccessful = true
                                    };

                                    Log.Info("User logged in: {0}", user.UserName);
                                }
                            }
                        }

                        if (viewData == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Invalid login credentials."
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("logging in")
                    };
                }
            }

            return(Json(viewData));
        }
示例#8
0
        public ActionResult Signup(string userName, string password, string email, string captcha)
        {
            int arg1 = int.Parse(ViewData["Arg1"].ToString());
            int arg2 = int.Parse(ViewData["Arg2"].ToString());

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(userName.NullSafe()), "Nazwa użytkownika nie może być pusta."),
                new Validation(() => userName.Trim().Length < MinimumLength, "Nazwa użytkownika nie może być krótsza niż {0} znaki.".FormatWith(MinimumLength)),
                new Validation(() => !UserNameExpression.IsMatch(userName), "Nazwa użytkownika może zawierać znaki i cyfry i zaczynać się literą. Dopuszczalne znaki specjalne: -,_."),
                new Validation(() => string.IsNullOrEmpty(password.NullSafe()), "Hasło nie może być puste."),
                new Validation(() => password.Trim().Length < MinimumLength, "Hasło nie może być krótsze niż {0} znaków.".FormatWith(MinimumLength)),
                new Validation(() => string.IsNullOrEmpty(email), "Adres e-mail nie może być pusty."),
                new Validation(() => !email.NullSafe().IsEmail(), "Niepoprawny adres e-mail."),
                new Validation(() => string.IsNullOrEmpty(captcha.NullSafe()), "Pole CAPTCHA nie może być puste"),
                new Validation(() => captcha.NullSafe() == (arg1 + arg2).ToString(), "Wartość pola CAPTCHA jest niepoprawna")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IUser user = _factory.CreateUser(userName.Trim(), email.Trim(), password.Trim());
                        UserRepository.Add(user);

                        unitOfWork.Commit();

                        string userId = user.Id.Shrink();

                        string url = string.Concat(Settings.RootUrl, Url.RouteUrl("Activate", new { id = userId }));

                        _emailSender.SendRegistrationInfo(email, userName, password, url);

                        Log.Info("Użytkownik zarejestrowany: {0}", user.UserName);

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };
                    }
                }
                catch (ArgumentException argument)
                {
                    viewData = new JsonViewData {
                        errorMessage = argument.Message
                    };
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("rejestracji")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult Login(string userName, string password, bool?rememberMe)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(userName.NullSafe()), "Nazwa użytkownika nie może być pusta."),
                new Validation(() => string.IsNullOrEmpty(password.NullSafe()), "Hasło nie może być puste.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindByUserName(userName.Trim());

                        if (user != null)
                        {
                            viewData = Validate <JsonViewData>(
                                new Validation(() => user.IsLockedOut, "Twoje konto jest aktualnie zablokowane. Skontaktuj się z pomocą aby rozwiązać ten problem."),
                                new Validation(() => !user.IsActive, "Twoje konto nie zostało jeszcze aktywowane. Posłóż się linkiem aktywacyjnym z wiadomości rejestracyjnej aby aktywować konto."),
                                new Validation(() => user.IsOpenIDAccount(), "Podany login jest poprawny tylko z OpenID.")
                                );

                            if (viewData == null)
                            {
                                if (string.Compare(user.Password, password.Trim().Hash(), StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    user.LastActivityAt = SystemTime.Now();
                                    unitOfWork.Commit();

                                    FormsAuthentication.SetAuthCookie(userName, rememberMe ?? false);
                                    viewData = new JsonViewData {
                                        isSuccessful = true
                                    };

                                    Log.Info("Użytkownik zalogowany: {0}", user.UserName);
                                }
                            }
                        }

                        if (viewData == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Niepoprawne dane logowania."
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("logowania")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult ForgotPassword(string email)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(email.NullSafe()), "Pole e-mail nie może być puste."),
                new Validation(() => !email.NullSafe().IsEmail(), "Niepoprawny adres e-mail.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindByEmail(email.Trim());

                        if (user == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Nie znaleziono użytkownika z podanym adresem e-mail."
                            };
                        }
                        else
                        {
                            try
                            {
                                string password = user.ResetPassword();

                                unitOfWork.Commit();

                                _emailSender.SendNewPassword(user.Email, user.UserName, password);

                                viewData = new JsonViewData {
                                    isSuccessful = true
                                };

                                Log.Info("Wygenerowany nowe hasło dla: {0}", user.UserName);
                            }
                            catch (InvalidOperationException invalidOperation)
                            {
                                viewData = new JsonViewData {
                                    errorMessage = invalidOperation.Message
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("resetowania hasła")
                    };
                }
            }

            return(Json(viewData));
        }
示例#11
0
        public ActionResult ForgotPassword(string email)
        {
            var viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(email.NullSafe()), "Email cannot be blank."),
                new Validation(() => !email.NullSafe().IsEmail(), "Invalid email address format.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindByEmail(email.Trim());

                        if (user == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Did not find any user with the specified email."
                            };
                        }
                        else
                        {
                            try
                            {
                                string password = user.ResetPassword();

                                unitOfWork.Commit();

                                _emailSender.SendNewPassword(user.Email, user.UserName, password);

                                viewData = new JsonViewData {
                                    isSuccessful = true
                                };

                                Log.Info("New password generated for: {0}", user.UserName);
                            }
                            catch (InvalidOperationException invalidOperation)
                            {
                                viewData = new JsonViewData {
                                    errorMessage = invalidOperation.Message
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("resetting password")
                    };
                }
            }

            return(Json(viewData));
        }
示例#12
0
        public ActionResult Approve(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            if (story.IsApproved())
                            {
                                viewData = new JsonViewData {
                                    errorMessage = "Podany artyku³ ju¿ zosta³ zatwierdzony jako spam."
                                };
                            }
                            else
                            {
                                _storyService.Approve(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);
                                unitOfWork.Commit();

                                viewData = new JsonViewData {
                                    isSuccessful = true
                                };
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("aprobowania artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
示例#13
0
        public ActionResult MarkAsSpam(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        if (!story.CanMarkAsSpam(CurrentUser))
                        {
                            viewData = story.HasMarkedAsSpam(CurrentUser) ?
                                       new JsonViewData {
                                errorMessage = "You have already marked this story as spam."
                            } :
                            new JsonViewData {
                                errorMessage = "You are not allowed to mark this story as spam."
                            };
                        }
                        else
                        {
                            _storyService.MarkAsSpam(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser, CurrentUserIPAddress);

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("marking story as spam")
                    };
                }
            }

            return(Json(viewData));
        }
示例#14
0
        public ActionResult Promote(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        if (!story.CanPromote(CurrentUser))
                        {
                            viewData = story.HasPromoted(CurrentUser) ?
                                       new JsonViewData {
                                errorMessage = "You have already promoted this story."
                            } :
                            new JsonViewData {
                                errorMessage = "You are not allowed to promote this story."
                            };
                        }
                        else
                        {
                            _storyService.Promote(story, CurrentUser, CurrentUserIPAddress);

                            viewData = new JsonVoteViewData {
                                isSuccessful = true, votes = story.VoteCount
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("promoting story")
                    };
                }
            }

            return(Json(viewData));
        }
示例#15
0
        public ActionResult Submit(string url, string title, string category, string description, string tags)
        {
            string captchaChallenge = null;
            string captchaResponse  = null;
            bool   captchaEnabled   = !CurrentUser.ShouldHideCaptcha();

            if (captchaEnabled)
            {
                captchaChallenge = HttpContext.Request.Form[CaptchaValidator.ChallengeInputName];
                captchaResponse  = HttpContext.Request.Form[CaptchaValidator.ResponseInputName];
            }

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaChallenge), "Captcha challenge cannot be blank."),
                new Validation(() => captchaEnabled && string.IsNullOrEmpty(captchaResponse), "Captcha verification words cannot be blank."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => captchaEnabled && !CaptchaValidator.Validate(CurrentUserIPAddress, captchaChallenge, captchaResponse), "Captcha verification words are incorrect.")
                );

            if (viewData == null)
            {
                try
                {
                    StoryCreateResult result = _storyService.Create(
                        CurrentUser,
                        url.NullSafe(),
                        title.NullSafe(),
                        category.NullSafe(),
                        description.NullSafe(),
                        tags.NullSafe(),
                        CurrentUserIPAddress,
                        HttpContext.Request.UserAgent,
                        ((HttpContext.Request.UrlReferrer != null) ? HttpContext.Request.UrlReferrer.ToString() : null),
                        HttpContext.Request.ServerVariables,
                        story => string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName }))
                        );

                    viewData = new JsonCreateViewData
                    {
                        isSuccessful = string.IsNullOrEmpty(result.ErrorMessage),
                        errorMessage = result.ErrorMessage,
                        url          = result.DetailUrl
                    };
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("submitting story")
                    };
                }
            }

            return(Json(viewData));
        }
示例#16
0
        public ActionResult MarkAsOffended(string storyId, string commentId)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(storyId), "Story identifier cannot be blank."),
                new Validation(() => storyId.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => string.IsNullOrEmpty(commentId), "Comment identifier cannot be blank."),
                new Validation(() => commentId.ToGuid().IsEmpty(), "Invalid comment identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(storyId.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        IComment comment = story.FindComment(commentId.ToGuid());

                        if (comment == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Specified comment does not exist."
                            };
                        }
                        else
                        {
                            _storyService.MarkAsOffended(comment, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("marking comment as offended")
                    };
                }
            }

            return(Json(viewData));
        }
示例#17
0
        private ActionResult LockOrUnlock(string id, bool unlock)
        {
            var viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "User Id cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid user identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.IsAdministrator(),
                               "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindById(id.ToGuid());

                        if (user == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Specified user no longer exist."
                            };
                        }
                        else
                        {
                            if (unlock)
                            {
                                user.Unlock();
                            }
                            else
                            {
                                user.Lock();
                            }

                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("{0} the user".FormatWith(unlock ? "unlocking" : "locking"))
                    };
                }
            }

            return(Json(viewData));
        }
        private ActionResult LockOrUnlock(string id, bool unlock)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator użytkownika nie może być pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator użytkownika."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany."),
                new Validation(() => !CurrentUser.IsAdministrator(), "Nie masz uprawnień do wywoływania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindById(id.ToGuid());

                        if (user == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany użytkownik nie istnieje."
                            };
                        }
                        else
                        {
                            if (unlock)
                            {
                                user.Unlock();
                            }
                            else
                            {
                                user.Lock();
                            }

                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("{0} użytkownika".FormatWith(unlock ? "odblokowywanie" : "blokowanie"))
                    };
                }
            }

            return(Json(viewData));
        }
示例#19
0
        public ActionResult Signup(string userName, string password, string email)
        {
            var viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(userName.NullSafe()), "User name cannot be blank."),
                new Validation(() => userName.Trim().Length < MinimumLength, "User name cannot be less than {0} character.".FormatWith(MinimumLength)),
                new Validation(() => !UserNameExpression.IsMatch(userName), "User name must be alphanumeric characters which starts with alphabet and can only contains special characters dash and underscore."),
                new Validation(() => string.IsNullOrEmpty(password.NullSafe()), "Password cannot be blank."),
                new Validation(() => password.Trim().Length < MinimumLength, "Password cannot be less than {0} character.".FormatWith(MinimumLength)),
                new Validation(() => string.IsNullOrEmpty(email), "Email cannot be blank."),
                new Validation(() => !email.NullSafe().IsEmail(), "Invalid email address format.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = _factory.CreateUser(userName.Trim(), email.Trim(), password.Trim());
                        UserRepository.Add(user);

                        unitOfWork.Commit();

                        string userId = user.Id.Shrink();

                        string url = string.Concat(Settings.RootUrl, Url.RouteUrl("Activate", new { id = userId }));

                        _emailSender.SendRegistrationInfo(email, userName, password, url);

                        Log.Info("User registered: {0}", user.UserName);

                        viewData = new JsonViewData {
                            isSuccessful = true
                        };
                    }
                }
                catch (ArgumentException argument)
                {
                    viewData = new JsonViewData {
                        errorMessage = argument.Message
                    };
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("signing up")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult GetEvent(string id)
        {
            id = id.NullSafe();
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator wydarzenia nie może być pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawne id wydarzenia."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do woływania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    ICommingEvent commingEvent = _commingEventRepository.FindById(id.ToGuid()); // findById do zaimplementowania

                    if (commingEvent == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Podane wydarzenie nie istnieje."
                        };
                    }
                    else
                    {
                        return(Json(
                                   new
                        {
                            eventId = commingEvent.Id.Shrink(),
                            eventLink = commingEvent.EventLink,
                            eventName = commingEvent.EventName,
                            eventDate = commingEvent.EventDate.ToString("dd-MM-yyyy HH:mm"),
                            eventEndDate = commingEvent.EventEndDate?.ToString("dd-MM-yyyy HH:mm"),
                            eventCity = commingEvent.EventCity,
                            eventPlace = commingEvent.EventPlace,
                            eventLead = commingEvent.EventLead,
                            eventUserEmail = commingEvent.Email,
                            isApproved = commingEvent.IsApproved,
                            isOnline = commingEvent.IsOnline
                        }
                                   ));
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("pobierania wydarzenia")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult DeleteEvent(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wołania tej metody."),
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator reklamy nie może być pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator wydarzenia."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        ICommingEvent commingEvent = _commingEventRepository.FindById(id.ToGuid());

                        if (commingEvent == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Wydarzenie nie istnieje."
                            };
                        }
                        else
                        {
                            _commingEventRepository.Remove(commingEvent);
                            unitOfWork.Commit();

                            if (!string.IsNullOrEmpty(commingEvent.GoogleEventId))
                            {
                                _googleService.DeleteEvent(commingEvent.GoogleEventId);
                            }

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData
                    {
                        errorMessage = FormatStrings.UnknownError.FormatWith("usuwania wydarzenia")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult GetAd(string id)
        {
            id = id.NullSafe();
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator reklamy nie może być pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny reklamy artykułu."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do woływania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    IRecommendation recommendation = _recommendationRepository.FindById(id.ToGuid());

                    if (recommendation == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Podana rekalama nie istnieje."
                        };
                    }
                    else
                    {
                        return(Json(
                                   new
                        {
                            id = recommendation.Id.Shrink(),
                            recommendationLink = recommendation.RecommendationLink,
                            recommendationTitle = recommendation.RecommendationTitle,
                            imageLink = recommendation.ImageLink,
                            imageTitle = recommendation.ImageTitle,
                            startTime = recommendation.StartTime.ToString("yyyy-MM-dd"),
                            endTime = recommendation.EndTime.ToString("yyyy-MM-dd"),
                            position = recommendation.Position,
                            email = recommendation.Email,
                            notificationIsSent = recommendation.NotificationIsSent,
                            isBanner = recommendation.IsBanner
                        }
                                   ));
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("pobierania reklamy")
                    };
                }
            }

            return(Json(viewData));
        }
示例#23
0
        public ActionResult Approve(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        if (story.IsApproved())
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Specified story has been already approved."
                            };
                        }
                        else
                        {
                            _storyService.Approve(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("approving story")
                    };
                }
            }

            return(Json(viewData));
        }
示例#24
0
        public ActionResult GetStory(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Specified story does not exist."
                        };
                    }
                    else
                    {
                        return(Json(
                                   new
                        {
                            id = story.Id.Shrink(),
                            name = story.UniqueName,
                            createdAt = story.CreatedAt.ToString("G", Constants.CurrentCulture),
                            title = story.Title,
                            description = story.HtmlDescription,
                            category = story.BelongsTo.UniqueName,
                            tags = string.Join(", ", story.Tags.Select(t => t.Name).ToArray())
                        }
                                   ));
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("getting story")
                    };
                }
            }

            return(Json(viewData));
        }
示例#25
0
        public ActionResult GetStory(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ywania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindById(id.ToGuid());

                    if (story == null)
                    {
                        viewData = new JsonViewData {
                            errorMessage = "Podany artyku³ nie istnieje."
                        };
                    }
                    else
                    {
                        return(Json(
                                   new
                        {
                            id = story.Id.Shrink(),
                            name = story.UniqueName,
                            createdAt = story.CreatedAt.ToString("G", Constants.CurrentCulture),
                            title = story.Title,
                            description = story.HtmlDescription,
                            category = story.BelongsTo.UniqueName,
                            tags = string.Join(", ", story.Tags.Select(t => t.Name).ToArray())
                        }
                                   ));
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("pobierania artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
示例#26
0
        public ActionResult Update(string id, string name, DateTime createdAt, string title, string category, string description, string tags)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."),
                new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            _storyService.Update(story, name.NullSafe(), createdAt, title.NullSafe(), category.NullSafe(), description.NullSafe(), tags.NullSafe());

                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("edycji artyku³u")
                    };
                }
            }

            return(Json(viewData));
        }
示例#27
0
        public ActionResult ConfirmSpam(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."),
                new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."),
                new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."),
                new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            _storyService.Spam(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser);
                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("zatwierdzania artyku³u jako spam")
                    };
                }
            }

            return(Json(viewData));
        }
        public ActionResult ChangeRole(string id, string role)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator użytkownika nie może być pusty."),
                new Validation(() => string.IsNullOrEmpty(role), "Rola nie może być pusta."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator użytkownika."),
                new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteś zalogowany."),
                new Validation(() => !CurrentUser.IsAdministrator(), "Nie masz uprawnień do wywoływania tej metody.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = UserRepository.FindById(id.ToGuid());

                        if (user == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany użytkownik nie istnieje."
                            };
                        }
                        else
                        {
                            user.Role = role.ToEnum(user.Role);
                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("zmiany roli")
                    };
                }
            }

            return(Json(viewData));
        }
示例#29
0
        public ActionResult Retrieve(string url)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(url), "Url nie mo¿e byæ pusty."),
                new Validation(() => !url.IsWebUrl(), "Niepoprawny format Url.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindByUrl(url);

                    if (story != null)
                    {
                        string existingUrl = Url.RouteUrl("Detail", new { name = story.UniqueName });

                        viewData = new JsonContentViewData {
                            alreadyExists = true, existingUrl = existingUrl
                        };
                    }
                    else
                    {
                        StoryContent content = _contentService.Get(url);

                        viewData = (content == StoryContent.Empty) ?
                                   new JsonViewData {
                            errorMessage = "Podany Url nie istnieje."
                        } :
                        new JsonContentViewData {
                            isSuccessful = true, title = content.Title.HtmlDecode(), description = content.Description.HtmlDecode()
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("pobierania strony.")
                    };
                }
            }

            return(Json(viewData));
        }
示例#30
0
        public ActionResult Click(string id)
        {
            id = id.NullSafe();

            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."),
                new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikatory artyku³u.")
                );

            if (viewData == null)
            {
                try
                {
                    using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                    {
                        IStory story = _storyRepository.FindById(id.ToGuid());

                        if (story == null)
                        {
                            viewData = new JsonViewData {
                                errorMessage = "Podany artyku³ nie istnieje."
                            };
                        }
                        else
                        {
                            _storyService.View(story, CurrentUser, CurrentUserIPAddress);
                            unitOfWork.Commit();

                            viewData = new JsonViewData {
                                isSuccessful = true
                            };
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("klikania")
                    };
                }
            }

            return(Json(viewData));
        }