Show private content to specific users in Django - python

I'm building a very simple website where a user authenticates and accesses a personal page from where they can download their paychecks. I've already implemented the login view, that redirects the user to the profile page. Now in the profile page, I need to add a list of paychecks to download. In order to do that, I need to take them from a static sub-directory with the same name as the user:
static/paychecks/username
I've been reading about serving static files, but I can't figure out how to do this specifically. Any help will be much appreciated.

Related

How to add facebook login to Python Django Project?

I want to build a Django application where I have a simple button "login using Facebook" and it redirects you to the Facebook page allowing to log in with facebook username and password . When user clicks "login" . It should redirect me to my already defined url where i can display the user's public information from his profile. How this can be achieved ??
Just like 4shared.com allows to login with Facebook . I want something like that but i only want to display its public information of the user.
You should take a look at some of the existing OAuth libraries for django. I'm using allauth, and I can definitely recommend it, even though the documentation is a bit lacking.
Here's a tutorial that helped me a lot when I was starting out:
http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/
As to how to display the Facebook user's public information, you should consult the Facebook Graph API

Use of Stripe payment gateway in django

I have installed dj-strpe module and register one user without any difficulty i.e., by submitting the form at /payments/ and here dj-stripe register the current user to stripe.com . But what if I want to send card information with the user and want to use it later , However I register the card by following instructions https://stripe.com/docs/tutorials/forms .
But I think this module must contain all this forms already but I don't found any thing in documentation to use them (how ever I find out urls and forms in this module) . So please tell me how I can use those forms in my project , is there any specific tags or urls to submit the forms.
For one instance I used this url /payments/history/ but I didn't show any thing in browser however I have checked the browser console and in response there is some html but browser is blank.
I hope I have explained my question. Any help will be appreciated.

Accessing Facebook Profile URLs

The goal here, given a user facebook profile url, access and open the profile page. Some simple python code:
from urllib2 import urlopen
url = "http://www.facebook.com/username"
page = urlopen(url)
The problem is that for some "username" this causes HTTP ERROR 404. I noticed this error only happening when the path includes a name rather than the "profile.php?id=XXX" format.
Notice that we only have the url here and not the user id.
UPDATE:
This turned out to happen also for some of the "profile.php?id=XXX" and other username formats.
This is a privacy feature of Facebook. Users have the ability to hide their profile page so that only logged in users can view their page. Accessing the page with /profile.php?id=XXX or with /username makes no difference. You must be logged-in in order to view the HTML page.
In your context, you'd have to first log in to a valid Facebook account before requesting the page and you should no longer receive the 404's.
One way to check this is on the graph API, graph.facebook.com/USERNAME will return a link property in the resulting JSON if they have a public page, and it will be omitted on private pages.
Not every Facebook account is accessible as FIRST.LAST, so you won't be able to reliably do this.
There is currently no guarantee that an account is accessible with a vanity name.
Works perfectly fine as long as the username exists.
Are you trying to open the page in a Web Browser or access the HTML source generated by the page?
If the latter, have you thought of using the Facebook Graph API to achieve whatever it is that you are doing? This will be much faster and the API is all documented. Plus the page's HTML source could change at any point in time, whereas the Graph API will not.
Edit
You could use the Graph API without having to even create an application to get the user ID, but going to http://graph.facebook.com/username and parsing the JSON response. You can then access the profile HTML using http://www.facebook.com/profile.php?id=userId

Crawler in python

I have a website (my college website) for which each student has a username/password to login into his account. The website consists of many files uploaded in different formats. I want to programmatically enter my credentials and login to my account and download all files that have been uploaded in the site.
Is there any python module that would authenticate html form and provide access to the pages and then allow downloading files present in those pages?
I would look at http://scrapy.org. It's python based crawler/scraper that you can customize to perform any workflow you want. Here's an example of how user authentication is handled: http://doc.scrapy.org/topics/request-response.html?highlight=username#request-usage-examples

Cross-domain Ajax POST and user verification

I'm working on app which saves things from many cross domains via Ajax POST method to my server/app. I need to find a solution how to send a POST and verify if the user who sent it is already signed on my site and than save it to the database.
I am pretty sure that I need Chrome, Firefox extension to do it, because I need to embed my js on every page my users surf on. The thing is I don't know where to start and how should it work. I could set up proxy to make JSON POST work, but I don't know how to verify if the user is signed on my site.
Should I get cookies of my users from browser via Chrome API and sent it in the POST and authenticate the cookie/session in Django? What do you suggest?
Thank you for your help. I appreciate every hint.
When the user logons at http://yourserver.com, you can set a permanent cookie to identify him. (see SESSION_EXPIRE_AT_BROWSER_CLOSE and COOKIE_AGE variables in django)
Then, when he embeds any JS from another site from yourserver.com domain, the cookies are automatically sent for this domain, and you can check on your django side for the cookie existence and validity and give the good JS.
Because of crossdomain issues, you should better use form POST as an alternative as AJAX as it is not security restricted. You can then play with iframes and javascript to make both domains communicates.
To embed the JS in another website, you can use a browser extension, or a simple bookmarklet, which will load your code in the current page when the user clicks it from any webpage.
My 2 cents;

Categories