public dynamic LoginUser(LoginCommand loginCommand) { var commandResult = _commandInvoker.Handle <LoginCommand, LoginCommandResult>(loginCommand); if (commandResult.Success) { var cookie = FormsAuthentication.CreateAuthCookie(commandResult.Author.Id); var response = Context.GetRedirect(loginCommand.ReturnUrl ?? "/admin"); response.AddCookie(cookie); return(response); } return(View["LoginPage", commandResult.GetErrors()]); }
public dynamic LoginUser(LoginCommand loginCommand) { if (!ModelValidationResult.IsValid) { return(View["LoginPage", new[] { "请正确输入Email和密码" }]); } var commandResult = _commandInvoker.Handle <LoginCommand, LoginCommandResult>(loginCommand); if (commandResult.Success) { var cookie = FormsAuthentication.CreateAuthCookie(commandResult.Author.Id); var response = Context.GetRedirect(loginCommand.ReturnUrl ?? "/mz-admin"); return(response.WithCookie(cookie)); } return(View["LoginPage", commandResult.GetErrors()]); }
public void registered_user_should_be_able_to_add_posts() { // Given Assert.Equal(0, _bootstrapper.Database.GetCollection <BlogPost>("BlogPosts").Count()); var authorDocument = new Author { Email = "*****@*****.**", DisplayName = "tester" }; _bootstrapper.Database.GetCollection <Author>("Authors").Insert(authorDocument); var authCookie = FormsAuthentication.CreateAuthCookie(authorDocument.Id); //when var browser = new Browser(_bootstrapper); var result = browser.Post("/admin/posts/new", with => { with.Cookie(authCookie.Name, authCookie.Value); with.HttpRequest(); with.FormValue("Title", "this is a test title"); with.FormValue("Content", "this is a test content"); with.FormValue("Tags", "test"); with.FormValue("PubDate", DateTime.Now.AddDays(-1).ToString(CultureInfo.InvariantCulture)); with.FormValue("Published", "true"); }); Assert.Equal(1, _bootstrapper.Database.GetCollection <BlogPost>("BlogPosts").Count()); var document = _bootstrapper.Database.GetCollection <BlogPost>("BlogPosts").FindOne(); Assert.Equal(PublishStatus.Published, document.Status); Assert.Equal(1, document.Tags.Length); Assert.Equal("this is a test title", document.Title); Assert.Equal("tester", document.AuthorDisplayName); }