Handling Django Registrations for Duplicate Entries - django-views

Question PART 1:
Project => App => forms.py
![User Creation Form using default Django Structure]
Project => App => urls.py
![URL Routes defined in urls.py of Django App]
Project => App => views.py
![User Authentication using default Django Structure]
Instead of using SQLite, I am using MongoDB Database and the entries are being stored in the auth_user table but I wanna get rid of duplicate entries (i.e. same username/email). If the user enters a same username/email, the page gives a DatabaseError Exception which I believe is handled by Django itself.
Question PART 2:
Project => settings.py
![Have included MessageTags into settings.py]
Also how to give specific redirect locations to messages in Django !? Once the user completes registration, the success message is displayed and he is redirected to the login page to access the dashboard and other features. But when the user logs in successfully, he is redirected to the dashboard but the Success Message is being displayed when he logs out (in the logout page).
Approach PART 1:
Can I, using try catch, handle the exception and allow the user to change the entered values to something unique and get his details saved into the database !?
Approach PART 2:
Sometimes the messages are appearing onto different pages than specified pages while using render/redirect for views.py functions(i.e routes). I tried redirecting each message to specific routes but I guess it overwrites to the last render/redirect route.
Regards,
Joe.

Related

What is the difference between "'pages.apps.PagesConfig'" and "pages"?

It seems there are two ways to register a Django app (say, pages) in INSTALLED_APPS (in file 'settings.py'):
INSTALLED_APPS = [
pages, #option 1
pages.apps.PagesConfig, #option 2
]
Both seem to work with simple apps. But are there any differences between pages.apps.PagesConfig and pages?
Per user #riterix on Reddit who responded to my inquiry:
"The second one gives you the ability to load custom things... Like signals,...
For example you want to load some settings from db after accounts app load when a user logged in through signals.
NB : We used the second method in our project to load currency, metrics,... As a sessions variables based on the user country after he successfully logged in."

How to use Social-Auth-Django-App with Facebook's https://m.me/

I tried using hyperlink and supplied it with my actual Facebook Username and it's working. But the problem is my actual Facebook Username is different from the Username provided by Social-Auth-App-Django. So I tried User ID instead but it's not working either.
By the way what I'm trying to do is an online shopping website and when a user clicks the hyperlink, he/she will be redirected to the seller's Facebook Messenger account to start a conversation.
This is the first line of code that I tried which is working.
Send Message to Seller
And this is the code I used using Social-Auth-App's provided data:
Send Message to Seller
And I also tried this:
Send Message to Seller
Any idea how I can use Facebook's m.me/ using the provided data by Social-Auth-App-Django? Or if you can suggest me other ways other than m.me/ I will greatly appreciate it. Thank you very much!
First Go To Setting.py And Put This Code End Of All Codes:
AUTHENTICATION_BACKENDS = [
'social_core.backends.facebook.FacebookOAuth2',
]
Second Go To FaceBook Developer In This Address :
https://developers.facebook.com
And Make One Account There.
After go To My Apps And Then Click On Create App And Then Put Your Website Name ((Attention...If You Use Your Local Host You Need To Put One Domain Name For Your Local Ip)) And Your Email And Click On Create App ID And In Your Dashboard Looking For Facebook Login And Click On Set Up .
And Then In First Step In Web Window Put Your WebSite Name For Local Host For Example Put mysite.com:8000/ And Click On Save And Other Options Just Cross .
Now In Your Dashboard On The Left Side Click On Setting And Then Basic If You See Your APP ID And Your APP SECRET Put This Two In Your Settings.py After That Last Code .
SOCIAL_AUTH_FACEBOOK_KEY = 'Put Your App Id Code Here'
SOCIAL_AUTH_FACEBOOK_SECRET = 'Put Your App Secret Code Here'
If You Want To Take User's Email Also You Can You This As Well .
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
Now In You Dashboard Go To Settings And After Go To Basic An In Field App Domains Put Your Website Name Also Go To Settings After Advanced And Put Website Name In Domain Manager With CLick On Add a Domain .
Now Again In Dashboar Go In Products+ Part And Click On Facrbook Login After Settings And Check These Option Be Active(Yes) :
• Client OAuth Login
• Web OAuth Login
• Enforce HTTPS
• Embedded Browser OAuth Login
And IN This Form Your Are Now Also Go In This Field Valid OAuth Redirect URIs And Put This URL :
exapmle.com/social-auth/complete/facebook/
And Put Your Button In Your Website Page That Have This Login Auth :
<li>
Sign in with Facebook
</li>

authenticate with different table in django and not User

hello I have created a table register_Recruiter which has email and password as two of its column. Now to authenticate, from front end ( React) I am sending a post request containing email and password.But I am not able to do that.I tried looking for tutorials but no luck. Do help!!
PS: new to django -rest-framework
This is more connected with Django itself. I guess, you need to add your new table into Django settings AUTH_USER_MODEL=YOUR_NEW_USER_TABLE

Odoo website, Creating a signup page for external users

How can I create a signup page in odoo website. The auth_signup module seems to do the job (according to their description). I don't know how to utilize it.
In the signup page there shouldn't be database selector
Where should I store the user data(including password); res.users or res.partner
you can turn off db listing w/ some params in in odoo.cfg conf
db_name = mydb
list_db = False
dbfilter = mydb
auth_signup takes care of the registration, you don't need to do anything. A res.user will be created as well as a partner related to it.
The pwd is stored in the user.
User Signup is a standard feature provided by Odoo, and it seems that you already found it.
The database selector shows because you have several PostgresSSQL databases.
The easiest way is to set a filter that limits it to the one you want:
start the server with the option --dbfilter=^MYDB$, where MYDBis the database name.
User data is stored both in res.userand res.partner: the user specific data, such as login and password, are stored in res.user. Other data, such as the Name is stored in a related res.partner record.

Getting unlogged after a redirect in django

I have 2 Django projects :
project_redirect, which is running on http://localhost.com:8005
project_logged_in, which is running on http://localhost.com:8000 (I'm authenticated in this one)
When I try to do a redirect from project_redirect to a view that requires authentication in my project_logged_in, I get unlogged in project_logged_in (checked that with request.user.is_authenticated() in the first line of the view).
my redirect view is as sample as :
def test_redirect_view(request):
return HttpResponseRedirect('http://localhost.com:8000/login_required_view/')
Why would this happen?
Your session cookie is being shared by both projects as they are using the same domain.
Try setting SESSION_COOKIE_NAME in both projects to something unique.