For example, a verification email info page. Anybody can currently visit www.mysite.com/verified and see the thank you message. Is there any way I can use conditionals to stop people from being able to view this page?
Thanks.
In the controller you should render the correct template for authorized/unauthorized, utilizing the verification url id.
In the pug template, you could theoretically render or not render the template by simply using an if-statement on the entire template, but I personally wouldn't go about it this way.
- if (allowUser)
.body
.myhtml
- else
.body
.notallowed
Related
If i have somesite.com/thisiswhatiwant, how can I transform that into a variable and process it, without using get vars? What should I google in the first place?
The idea is to create a dynamic page structure where that part of the url will populate variables in the page and be used to return dynamic page specific queries.
Is there a framework I can use that has a way to handle this easily?
If I use javascript for this, how should I handle it to not return any 404 errors but rather just pull a templating page and then use that part of the url for developing of the page?
Thank you!
Here is how you parse the path of a url in PHP
$url = "http://somesite.com/thisiswhatiwant";
var_dump(parse_url($url, PHP_URL_PATH));
If i have somesite.com/thisiswhatiwant, how can I transform that into a variable and process it, without using get vars? What should I google in the first place?
That's simply getting the current URL and parsing it. (Which are pretty well covered in the linked questions).
You do need to get the server to execute the PHP first. This question about the front controller pattern explains that.
If I use javascript for this, how should I handle it to not return any 404 errors but rather just pull a templating page and then use that part of the url for developing of the page?
Assuming you mean client-side JavaScript: You can't.
JavaScript runs in the context of a webpage.
Get page from server
Parse HTML document
Run JavaScript that page says to run
If you 404 at step 1 then everything stops and no JS runs.
The correct terminology is vanity URLs. They are static urls that behave like dynamic urls. Dynamic urls are urls with queries which is not what we want here.
This tutorial will help.
The solution is trough the .htaccess rules as i expected.
The rest is basic php/db queries.
I still do not know of a web app framework that makes this trivial to implement, but there must be.
Here is the tutorial
http://culttt.com/2011/11/16/how-to-make-vanity-urls-using-php-htaccess-and-mysql/
I need to place code on every page of my app in index.html (Google Analytics tracking code). The issue is that some of the code needs to pull values from an Angular service. I'm wondering what the best practice is for doing this?
I was thinking to have run block that uses an injected service to get the value. I could then set a constant that I would have access to in index.html. I'm not sure if that's possible or not.
Any ideas? Thanks.
I'm not sure I understand exactly what you are trying to do, but it sounds like its as simple as retrieving a value from a service and binding it to a tag on your page.
In your controller:
$scope.yourConstant = yourInjectedService.getValue();
Then in your index.html:
<span>{{ yourConstant }}</span>
or:
<span ng-bind='yourConstant'></span>
IF I've misunderstood please try to clarify your scenario.
I have a SPA webapp that calls a webservice to gather 'X' amount of json objects ~(1 - 30+). I then use this data for multiple changing slides (all data is not displayed in the 1st slide).
I am using Node/Express/Angular/Jade.
How should I stage these slides when I gather the original data from the webservice (can only call the service once because $ constraints)? I would like the back button/urls to work as well. So, should I completely render out the data and use client side JS to hide/show the dom elements based on button clicks (incorporating messy hash bangs and JS methods to track location/flow). Or is there a sexier more efficient way? Should I store my data in the cache and pull from it (using my angularjs ng-view, note: changing my ng-view will be a pain... it would be ideal to have a ng-view within a ng-view in this particular situation, even though that doesnt exist) based on the slide? Or is there another way?
Thank you for your help, let me know if you need further explanation.
For mapping URLs to your angularjs pages, I would suggest using ui-router. You may or may not need ui-router for this particular problem. But, generally, it will help tremendously in organizing the structure of your site.
For the other questions:
I would store your results (which was retrieved from the service) in a $rootScope variable. The page index of your slides will be a parameter in your URL. Based on the value of this parameter, your controller can decide which page content it will display.
Imagine I'm on:
http://example.com/
I click in a link containing a hashbang fragment identifier, let's say:
http://example.com/#!/login
I would like it to show the login form without reloading the page. How is this done?
Have a look at jQuery Ajax to find out how to load new content without refreshing the page, then maybe move on to BackboneJS and use its routers to get the hash thing working.
Edit:
Here's a tutorial, I'm not going to write one for you. But it comes down to having a server side which is able to provide the needed content for you (a log in form), whether it does so asynchronously or synchronously is besides the point. Then using a Backbone Router which will read the hash bang and call the right JavaScript function based on this hash bang, this JavaScript function should live inside a Backbone Controller, and it should handle the instantiating of a new Backbone View and adding it to the DOM. The Backbone View could be added to a predefined Backbone Region, and could be loading an UnderscoreJS template to make things even easier.
If you would like a much simpler solution you should take a look at another concise answer here: Handle URL anchor change event in js. In summary, you periodically check window.location.hash for changes and run your javascript to bring up the login content.
I'm looking to capture and save the state of a page (Django template + backend) after the user makes some modifications (through JQuery) to the appearance of the page. Now that I've gotten hold of the innerHTML using a JS variable, I need to send it over to the Django view that will do the saving. How do I call this Django view and pass it the JS variable?
P.S: First ever question on stackoverflow, please let me know if the question isn't clear or is improperly formatted.
Handiest way to get started is to first make a proper form and a django view that reacts to it ("request.post"). The form should have fields for whatever you're changing in the page.
Next up, submit that form's variables from your page with jquery.ajax.
So the idea is to isolate the various problems:
What should be the form parameters?
Get a view running that makes the actual changes.
Get the javascript working.