pythonindia / junction

Junction is a software to manage proposals, reviews, schedule, feedback during conference.
MIT License
192 stars 185 forks source link

Error on login on local setup #755

Closed miphilomath closed 1 year ago

miphilomath commented 1 year ago

Creating a new issue to track the bug/problem better. I will add the comments and discussions from other issues / PR for reference.

On attempting to login via home page, I am getting the following error.

image

Though If I login through admin site first, I am logged into the application with no error.

Is anyone else facing similar problem?

Originally posted by @ananyo2012 in https://github.com/pythonindia/junction/issues/750#issuecomment-1519475279

miphilomath commented 1 year ago

I created the user using ./manage.py createsuperuser and used that user to login into the application via homepage.

Error stacktrace: https://pastebin.com/Zus5Gb3k

Original comment: https://github.com/pythonindia/junction/issues/750#issuecomment-1520039599

miphilomath commented 1 year ago

My project setup uses a postgresql instance running locally. My .env file which is present in the same hierarchy as the .env.sample file is as follow. Also, my project is not reading the variables defined in my .env file, so I have set the default values to configure my database.

DEBUG=TRUE
POSTGRES_USER=junction
POSTGRES_PASSWORD=password
POSTGRES_DB=junction
HOST_NAME=localhost
PORT=5432
BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/0
SITE_URL=http://0.0.0.0:8888
SITE_NAME=junction
GOOGLE_ANALYTICS_ID=google_analytics_id
FACEBOOK_APP_ID=fb_app_id
EMAIL_HOST_USER=email_host_user
EMAIL_HOST_PASSWORD=email_host_pass
SECRET_KEY=secret_key
TWITTER_CONSUMER_KEY=twitter_consume_key
TWITTER_CONSUMER_SECRET=twitter_consume_secret
TWITTER_ACCESS_TOKEN_KEY=twitter_access_token
TWITTER_ACCESS_TOKEN_SECRET=twitter_access_token_secret
USE_ASYNC_FOR_EMAIL=boolean
miphilomath commented 1 year ago

I suspect that the issue is with SMTP configuration as @ananyo2012 suggested that SMTP needs to be configured for both OAuth and Email based login.

Adding to this, I have not configured SMTP in any way after cloning the project and used a dummy email address to create the user I am using to log in.

  1. Email address for the user causing the issue is hypothetical and do not exist. mohit.bansal@test.com.
  2. SMTP is not configured and is using the default values.

Original comment: https://github.com/pythonindia/junction/issues/750#issuecomment-1519477338

miphilomath commented 1 year ago

On further experimenting with my configurations, I found that the setting that is causing me the problem. ACCOUNT_EMAIL_VERIFICATION is set to mandatory which makes my local setup to try and establish a connection with my hypothetical email address for verification. Since neither SMTP is set nor email address exists, it is throwing the reported error.

On commenting the setting, I am able to log in with my hypothetical user on local setup

# ACCOUNT_EMAIL_VERIFICATION = "mandatory"

miphilomath commented 1 year ago

Tl;Dr

After setting up the project locally with an hypothetical user, log in fails with the reported error when login is attempted from the frontend login page. But the login is succeeded when logged in via admin panel.

SMTP configuration is required for login from the frontend login page. On using the setup with a hypothetical email address with no SMTP configuration, ACCOUNT_EMAIL_VERIFICATION = "mandatory" throws the reported error.

Commenting the above setting allows the local setup to test the application with no SMTP configuratoin

ananyo2012 commented 1 year ago

So I finally found the root cause of the issue. The DEFAULT_FROM_EMAIL is set as a tuple in the current app settings. It has to be a plain string for the send_email method to work correctly. I have fixed it in this commit to feature/upgrade-junction branch.

Also I found that smtp engines like gmail/sendgrid needs to have 2FA enabled and have the sender email verified in order for send_email to work properly. I have switched the smtp provider to sendgrid so that we can manage dedicated accounts from sending emails.