-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default to false
judge/views/register.py
Outdated
@@ -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']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
<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 %} |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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)
{% 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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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.By submitting this pull request, I confirm that my contribution is made under the terms of the AGPL-3.0 License.