Group Invitations - culinary-code/algemeen GitHub Wiki

Group Invitations

For this project we initially implemented invitations by mail. The backend includes related code, such as the EmailService, which utilizes SMTP for sending emails. Below is a step-by-step guide to set up this functionality:

Setup SMTP

  1. Start by creating a new Gmail.
  2. Go to: Manage Account → Security → Enable 2-step verification
  3. Go to: Settings → All settings → Forwarding and POP/IMAP → Enable IMAP

enableIMAP

  1. Search “App-passwords”

appPassword

  1. Insert a name for your password

appPassword2

  1. Copy your generated app-password

  2. Now you can use this email and app password for your smtp mail-server

public EmailService(IOptions<EmailServiceOptions> options)
    {
        var emailServiceOptions = options.Value; 
        _smtpClient = emailServiceOptions.SmtpClient; // smtp.gmail.com
        _smtpUsername = emailServiceOptions.SmtpUserName; // <your-email>
        _smtpPassword = emailServiceOptions.SmtpPassword; // <your-app-password>
    }

After completing the invitation logic, we discovered that Azure blocks SMTP. This restriction is in place to prevent abuse, such as spam emails. While this was initially frustrating, we had to find an alternative solution. We decided to implement link-sharing instead.

To achieve this, we utilized the Flutter package 'share_plus'. This allowed us to replace the link that was previously embedded in an email button with a shareable link. The link can now be directly shared via other applications or copied to the clipboard.

Handling Invitations in the App:

  • Managing Deep Links to Redirect Users to the App:
    • For Android: Add the following to your AndroidManifest.xml to link to your app.
 <!-- Deep Linking Intent Filter -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <!-- Handle accept-invitation links -->
                <data android:scheme="https" android:host="culinarycode.com" android:pathPrefix="/accept-invitation"/>
            </intent-filter>
  • Managing Deep Links to Redirect Users to the App:
    • For iOS: Add the corresponding configuration to your Runner/Info.plist.
<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.culinarycode</string>
            </array>
        </dict>
    </array>
  • When logged in, the user is immediately redirected to the invitation screen. If the user is not logged in, it is important to store the invitation token so it remains accessible after logging in.

  • To store this token, we used SharedPreferences, which provides an easy way to store data temporarily without requiring encryption. Once the invitation is accepted, the token is deleted from SharedPreferences to prevent unnecessary data retention.

⚠️ **GitHub.com Fallback** ⚠️