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

Add UI page for social login #483

Open
wants to merge 23 commits into
base: development
Choose a base branch
from

Conversation

HungNgien
Copy link
Contributor

@HungNgien HungNgien commented Dec 19, 2024

Add UI page to allow toggle on/off sign-in options
image

image

Summary by Sourcery

Add a new UI page for managing social login settings, allowing administrators to toggle sign-in options for various providers. Integrate 'django-allauth' to support social authentication with providers like Google, GitHub, and MediaWiki. Enhance the system with OAuth2 application management capabilities, including creation and deletion. Update tests to accommodate the new social login URLs.

New Features:

  • Introduce a new UI page for managing social login settings, allowing administrators to enable or disable sign-in options for different providers.

Enhancements:

  • Add support for OAuth2 applications, including creation and deletion functionalities, to facilitate social login integration.

Build:

  • Integrate the 'django-allauth' library to support social authentication, including providers like Google, GitHub, and MediaWiki.

Documentation:

  • Add user-facing documentation for the new social login settings page, explaining how to enable or disable login providers.

Tests:

  • Update test infrastructure to ignore social URLs from django-allauth, as they do not support namespace.

Summary by Sourcery

Add a UI page for managing social login settings, allowing administrators to enable or disable different providers.

New Features:

  • Added a new user interface for enabling and disabling social login providers.

Tests:

  • Updated tests to exclude social login URLs.

Copy link

sourcery-ai bot commented Dec 19, 2024

Reviewer's Guide by Sourcery

This pull request implements a new UI page for managing social login settings. It integrates the django-allauth library to enable social authentication with providers such as Google, GitHub, and MediaWiki. The new page allows administrators to toggle the sign-in options for each provider. OAuth2 application management capabilities are also added, including the ability to create and delete applications. The existing login page is updated to include buttons for the enabled social login providers. Tests are updated to handle the new social login URLs.

Sequence diagram for social login flow

sequenceDiagram
    actor User
    participant Login Page
    participant SocialLoginView
    participant OAuth Provider
    participant Adapter

    User->>Login Page: Access login page
    Login Page->>SocialLoginView: Get enabled providers
    SocialLoginView-->>Login Page: Return enabled providers
    Login Page-->>User: Display login options

    User->>Login Page: Click social login button
    Login Page->>OAuth Provider: Redirect to provider login
    OAuth Provider-->>Adapter: Return with auth token
    Adapter->>SocialLoginView: Process authentication
    SocialLoginView-->>User: Redirect to dashboard
Loading

Class diagram for social authentication components

classDiagram
    class SocialLoginView {
        +template_name: string
        +LOGIN_PROVIDERS: dict
        +VALID_STATES: set
        +get_context_data()
        +post(request)
        +get_success_url()
    }

    class LoginState {
        <<enumeration>>
        ENABLE
        DISABLE
    }

    class CustomSocialAccountAdapter {
        +on_authentication_error()
    }

    class GlobalSettingsObject {
        +settings: dict
    }

    SocialLoginView --> LoginState
    SocialLoginView --> GlobalSettingsObject

    note for CustomSocialAccountAdapter "Handles social auth errors"
    note for SocialLoginView "Manages provider settings"
Loading

State diagram for social login provider status

stateDiagram-v2
    [*] --> Disabled
    Disabled --> Enabled: Admin enables
    Enabled --> Disabled: Admin disables

    state Enabled {
        [*] --> AvailableOnLogin
        AvailableOnLogin --> ProcessingAuth
        ProcessingAuth --> LoginSuccess
        ProcessingAuth --> LoginError
    }

    note right of Enabled: Provider appears on login page
    note right of Disabled: Provider hidden from login page
Loading

File-Level Changes

Change Details Files
Add a new UI page for social login settings
  • Implement the SocialLoginView to manage social login settings.
  • Create a template for the social login settings page.
  • Add a URL route for the social login settings page.
  • Add a navigation link to the social login settings page.
src/pretix/plugins/socialauth/views.py
src/pretix/plugins/socialauth/templates/socialauth/social_auth_settings.html
src/pretix/plugins/socialauth/urls.py
src/pretix/plugins/socialauth/signals.py
Integrate django-allauth for social authentication
  • Implement functions for handling OAuth login and return redirects.
  • Configure the django-allauth adapter.
  • Remove the existing backend configuration.
src/pretix/plugins/socialauth/views.py
src/pretix/plugins/socialauth/apps.py
src/pretix/plugins/socialauth/adapter.py
src/pretix/plugins/socialauth/backends.py
Update the login page to include social login buttons
  • Add social login buttons to the login page template.
  • Fetch and pass the enabled login providers to the login page context.
src/pretix/control/templates/pretixcontrol/auth/login.html
src/pretix/control/views/auth.py
Update tests to accommodate new social login URLs
  • Remove an existing URL route that is no longer needed.
src/pretix/control/urls.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@mariobehling
Copy link
Member

Always add screenshots of changes when making a PR, please!

@HungNgien
Copy link
Contributor Author

Always add screenshots of changes when making a PR, please!

Sorry, I was just preparing the draft pr, I'm resolving some conflicts.

@HungNgien HungNgien requested a review from odkhang December 19, 2024 08:50
@HungNgien HungNgien marked this pull request as ready for review December 20, 2024 02:42
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @HungNgien - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The oauth_return view should provide better error handling and user feedback instead of silently redirecting on failure. Consider adding error messages that help users understand and resolve authentication issues.
  • Consider implementing rate limiting for the social login endpoints to prevent potential abuse of the authentication system.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.



def oauth_login(request, provider):
base_url = adapter.get_provider(request, provider).get_login_url(request)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Preserve existing query parameters when constructing OAuth login URL

The current implementation overwrites any existing query parameters in base_url. Should merge new parameters with existing ones to avoid breaking providers that require specific parameters.

@mariobehling
Copy link
Member

Please make button "Login with Email" for the default option and when the user clicks the button expand the view and show standard login as below.
Screenshot from 2024-12-20 05-54-35

@mariobehling
Copy link
Member

So, at first it should look something like that

397286361-d9395597-2fd4-4025-875d-924c2f78ce3a

@HungNgien
Copy link
Contributor Author

image
image
@mariobehling, does it match your idea? Click the button "Login with email" will expand or hide the login form

@mariobehling
Copy link
Member

Thanks, yes, looks good.

Please correct spelling mistakes on settings pages - Mediawiki, Github, Google.

Can you confirm Internationalization works here? Please translate to Vietnamese as a sample language.

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.

3 participants