Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow registering using oauth #356

Merged
merged 4 commits into from
Dec 5, 2023
Merged

allow registering using oauth #356

merged 4 commits into from
Dec 5, 2023

Conversation

winprn
Copy link
Collaborator

@winprn winprn commented Nov 29, 2023

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.

Please remove options that are not relevant
Type of change: new feature

What

This PR allow users to register using OAuth apps like: Google, Facebook,...

Why

To prevent spamming

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have explained the purpose of this PR.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the README/documentation
  • Any dependent changes have been merged and published in downstream modules
  • Informed of breaking changes, testing and migrations (if applicable).
  • Attached screenshots (if applicable).

By submitting this pull request, I confirm that my contribution is made under the terms of the AGPL-3.0 License.

dmoj/settings.py Outdated
@@ -742,3 +742,5 @@

ACE_DEFAULT_LIGHT_THEME = DMOJ_THEME_DEFAULT_ACE_THEME['light']
ACE_DEFAULT_DARK_THEME = DMOJ_THEME_DEFAULT_ACE_THEME['dark']
# Only allow OAuth login
OAUTH_ONLY = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to false

@@ -74,6 +76,9 @@ def get_context_data(self, **kwargs):
kwargs['TIMEZONE_MAP'] = settings.TIMEZONE_MAP
kwargs['password_validators'] = get_default_password_validators()
kwargs['tos_url'] = settings.TERMS_OF_SERVICE_URL
kwargs['oauth_only'] = settings.OAUTH_ONLY
print(kwargs['oauth_only'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment on lines 238 to 241
<span class="tos-section">
{{ (_('By registering, you agree to our [Terms & Conditions][0].') + '\n\n [0]: ' + tos_url)|markdown('default', strip_paragraphs=True) }}
</span>
{% endif %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should always show this regardless of register method

judge/forms.py Outdated
Comment on lines 443 to 452
class CustomAuthenticationForm(AuthenticationForm):
social_auth = SocialAuthForm()
def __init__(self, *args, **kwargs):
super(CustomAuthenticationForm, self).__init__(*args, **kwargs)
self.fields['username'].widget.attrs.update({'placeholder': _('Username')})
self.fields['password'].widget.attrs.update({'placeholder': _('Password')})

self.has_google_auth = self.social_auth.has_google_auth
self.has_facebook_auth = self.social_auth.has_facebook_auth
self.has_github_auth = self.social_auth.has_github_auth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it works or not but i think to reduce the duplication of this, we can use multiple inheritance.

class CustomAuthenticationForm(AuthenticationForm, SocialAuthForm)

Comment on lines 262 to 277
{% if social_auth.has_google_auth %}
<a href="{{ url('social:begin', "google-oauth2") }}?next={{ next }}" class="social google-icon">
<i class="fa fa-google-plus-square"></i>
</a>
{% endif %}
{% if social_auth.has_facebook_auth %}
<a href="{{ url('social:begin', "facebook") }}?next={{ next }}" class="social facebook-icon">
<i class="fa fa-facebook-square"></i>
</a>
{% endif %}
{% if social_auth.has_github_auth %}
<a href="{{ url('social:begin', "github-secure") }}?next={{ next }}" class="social github-icon">
<i class="fa fa-github-square"></i>
</a>
{% endif %}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhap make this a template, and include it on both registration & login form

Copy link
Contributor

@leduythuccs leduythuccs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@leduythuccs leduythuccs merged commit bccb0ed into master Dec 5, 2023
6 checks passed
@leduythuccs leduythuccs deleted the oauth-config branch December 5, 2023 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants