Example #1
0
        public void Contact_Should_Return_Error_When_Blank_Name_Is_Passed()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("*****@*****.**", string.Empty, new string('x', 16))).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Nazwa nie może być pusta.", viewData.errorMessage);
        }
Example #2
0
        public void Contact_Should_Return_Error_When_Blank_Email_Is_Passed()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact(string.Empty, new string('x', 4), new string('x', 16))).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Pole e-mail nie może być puste.", viewData.errorMessage);
        }
Example #3
0
        public void Contact_Should_Return_Error_When_Invalid_Email_Is_Passed()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("xxx", new string('x', 4), new string('x', 16))).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Niepoprawny adres e-mail.", viewData.errorMessage);
        }
Example #4
0
        public void Contact_Should_Return_Error_When_Message_Is_Less_Than_Sixteen_Character()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("*****@*****.**", "xxxx", new string('x', 15))).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Wiadomość nie może być krótsza niż 16 znaków.", viewData.errorMessage);
        }
Example #5
0
        public void Contact_Should_Return_Error_When_Name_Is_Less_Than_Four_Character()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("*****@*****.**", "xxx", new string('x', 16))).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Nazwa nie może być krótsza niż 4 znaki.", viewData.errorMessage);
        }
        public void Contact_Should_Return_Error_When_Message_Is_Less_Than_Sixteen_Character()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("*****@*****.**", "xxxx", new string('x', 15))).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Message cannot be less than 16 character.", viewData.errorMessage);
        }
        public void Contact_Should_Return_Error_When_Blank_Message_Is_Passed()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("*****@*****.**", new string('x', 4), string.Empty)).Data;

            Assert.False(viewData.isSuccessful);
            Assert.Equal("Message cannot be blank.", viewData.errorMessage);
        }
        public ActionResult CreateUserByFb(string data)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(data.NullSafe()), "Nie udało nam się uzyskać Twoich danych z serwisu Facebook, spróbuj ponownie.")
                );


            if (viewData == null)
            {
                try
                {
                    var fbUserViewData = new JavaScriptSerializer().Deserialize <FbUserDataView>(data);
                    fbUserViewData = AssignViewData <FbUserDataView>(fbUserViewData);

                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = _userRepository.FindByFbId(fbUserViewData.Id);

                        if (user == null)
                        {
                            var email = fbUserViewData.Email;
                            if (string.IsNullOrEmpty(email))
                            {
                                email = fbUserViewData.Id + "@facebook.dotnetomaniak.pl";
                            }
                            user = _factory.CreateUser(fbUserViewData.Name, email, null);

                            user.FbId = fbUserViewData.Id;
                            unitOfWork.Commit();

                            user.FbId           = fbUserViewData.Id;
                            user.LastActivityAt = SystemTime.Now();
                            UserRepository.Add(user);

                            _eventAggregator.GetEvent <UserActivateEvent>().Publish(new UserActivateEventArgs(user));

                            unitOfWork.Commit();
                            viewData = LogUserByFb(viewData, unitOfWork, user);
                        }
                        else
                        {
                            return(Json(new { isSuccessful = false, errorMessage = "Użytkownik o podanym koncie Facebook'a istnieje już na dotnetomaniak.pl." }));
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("logowania")
                    };
                }
            }

            return(Json(new { isSuccessful = true, redirectUrl = Url.Action("Published", "Story", null, "http") }));
        }
        //[AcceptVerbs(HttpVerbs.Post), Compress]
        public ActionResult LogByFbData(string data)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(data.NullSafe()), "Nie udało nam się uzyskać Twoich danych z serwisu Facebook, spróbuj ponownie.")
                );

            if (viewData == null)
            {
                try
                {
                    var fbUserViewData = new JavaScriptSerializer().Deserialize <FbUserDataView>(data);
                    fbUserViewData = AssignViewData <FbUserDataView>(fbUserViewData);

                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        var user = _userRepository.FindByFbId(fbUserViewData.Id);

                        if (user != null)
                        {
                            viewData = LogUserByFb(viewData, unitOfWork, user);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(fbUserViewData.Email))
                            {
                                user = _userRepository.FindByEmail(fbUserViewData.Email);
                            }

                            if (user != null)
                            {
                                viewData = LogUserByFb(viewData, unitOfWork, user);

                                user.FbId = fbUserViewData.Id;
                                unitOfWork.Commit();
                            }
                            else
                            {
                                return(Json(new { redirectUrl = Url.Action("FbLog", "Facebook", null, "http"), isSuccessful = true, isRedirect = true }));
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("logowania")
                    };
                }
            }
            return(Json(viewData));
        }
Example #10
0
        public ActionResult SynchronizeWithFb(string data, string userName)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(data.NullSafe()), "Nie udało nam się uzyskać Twoich danych z serwisu Facebook, spróbuj ponownie.")
                );

            if (viewData == null)
            {
                try
                {
                    var fbUserViewData = new JavaScriptSerializer().Deserialize <FbUserDataView>(data);
                    fbUserViewData = AssignViewData <FbUserDataView>(fbUserViewData);

                    using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                    {
                        IUser user = _userRepository.FindByFbId(fbUserViewData.Id);

                        if (user == null)
                        {
                            user = _userRepository.FindByUserName(HttpContext.User.Identity.Name);

                            user.FbId = fbUserViewData.Id;
                            unitOfWork.Commit();
                        }
                        else
                        {
                            return(Json(new { isSuccessful = false, errorMessage = "Użytkownik o podanym koncie Facebook'a istnieje już na dotnetomaniak.pl." }));
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("synchronizowania")
                    };
                }
            }

            return(Json(new { isSuccessful = true, message = "Zsynchronizowano Twoje konto z kontem Facebooka." }));
        }
Example #11
0
        private JsonViewData LogUserByFb(JsonViewData viewData, IUnitOfWork unitOfWork, DomainObjects.IUser user)
        {
            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.")
                );

            if (user != null)
            {
                user.LastActivityAt = SystemTime.Now();
                unitOfWork.Commit();

                FormsAuthentication.SetAuthCookie(user.UserName, true);
                viewData = new JsonViewData {
                    isSuccessful = true
                };

                Log.Info("Użytkownik zalogowany: {0}", user.UserName);
            }
            return(viewData);
        }
Example #12
0
        public void Contact_Should_Send_Email()
        {
            JsonViewData viewData = (JsonViewData)((JsonResult)_controller.Contact("*****@*****.**", new string('x', 4), new string('x', 16))).Data;

            Assert.True(viewData.isSuccessful);
        }