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

Show Robotoff questions to non-logged users, with a prompt to sign-up or login #3158

Closed
Tracked by #5708 ...
teolemon opened this issue Mar 29, 2020 · 7 comments
Closed
Tracked by #5708 ...
Assignees
Labels
✨ Feature Features or enhancements to Open Food Facts server 🎨 Mockup available A mockup has been created for this feature. Please however interact before implementing. 🎯 P1 candidate 🎯 P1 pathway-to-contribution Product Page 🛣️ Road to scores Ensuring getting the Nutri-Score and Eco-Score is easy for users, and takes 1 or 2 minutes max. 🤖 Robotoff ⭐ top issue Top issue. 👍 Top 10 Issue!

Comments

@teolemon
Copy link
Member

teolemon commented Mar 29, 2020

What

Show Robotoff questions to non-logged users, with a prompt to sign-up or login.
Code pointer (original PR by @hangy) : https://github.com/openfoodfacts/openfoodfacts-server/pull/1705/files

Part of

Mockup

image

@teolemon teolemon added ✨ Feature Features or enhancements to Open Food Facts server 🤖 Robotoff Product Page labels Mar 29, 2020
@github-actions github-actions bot closed this as completed Jul 6, 2020
@openfoodfacts openfoodfacts deleted a comment from github-actions bot Jul 9, 2020
@teolemon
Copy link
Member Author

teolemon commented Jul 9, 2020

@hangy @VaiTon @raphael0202 added a mockup of an improved web experience for Robotoff that would enable to convert part of the 1,4 million monthly visitors into contributors

@teolemon teolemon added the 🎨 Mockup available A mockup has been created for this feature. Please however interact before implementing. label Jul 9, 2020
@teolemon teolemon pinned this issue Oct 31, 2020
@teolemon
Copy link
Member Author

teolemon commented Nov 9, 2020

Pseudo-code

on_button_click():
  if is_logged_in:
    save_answer(answer, barcode,user)
  else:
    success = show_login_modal(answer, barcode)
    if success:
      save_answer(answer, barcode, user)
    else:
      show_login_modal(answer, barcode, error)

@syl10100 syl10100 unpinned this issue Jan 23, 2021
@teolemon
Copy link
Member Author

teolemon commented Apr 27, 2021

Relevant integration points:
Javascript that displays Robotoff:

class RobotoffAsker extends HTMLElement {

User signup:

ProductOpener::Users::process_user_form($type, $user_ref);

Template for user signup: user_form2.tt.html

@CharlesNepote
Copy link
Member

The call to Robotoff questions is only available for registered users. Before rewrriting JS code we have to display it for every users:

[% IF (user_id.defined) && (robotoff_url.defined) && (robotoff_url.length > 0) %]

- [% IF (user_id.defined) && (robotoff_url.defined) && (robotoff_url.length > 0) %]
+ [% IF (robotoff_url.defined) && (robotoff_url.length > 0) %]

Then test if user is connected or not. We can start with a simple check to the HTML id logged_in_user_id as we are doing in Power User Script.

    /**
     * getConnectedUserID: returns user id of the current connected user
     *
     * @param    none
     * @returns  {String} user id; Example: "charlesnepote"
     */
    function getConnectedUserID() {
        // Extract connected user_id by reading <span id="user_id">charlesnepote</span>
        var user_name = $("#logged_in_user_id").text();
        console.log("getConnectedUserID() > user_name: "); console.log(user_name);
        return user_name;
    }

If the user is not connected, then display form in a modal.

  1. If the user already has an account

  2. If the user doesn't have an account
    user.pl does not have a callback to get back to the product.

TO BE COMPLETED

    /**
     * displayLoginForm
     *
     * @param    callback?
     * @returns  none
     */
    function displayLoginForm() {
        // Display form
        // TODO: manage i18n
        const form =
              `<form method="post" action="/cgi/session.pl">
                  <label>Nom d'utilisateur ou adresse e-mail :
                     <input type="text" name="user_id" autocomplete="username" required>
                  </label>
                  <label>Mot de passe
                     <input type="password" name="password" autocomplete="current-password" required>
                  </label>
                  <label>
                     <input type="checkbox" name="remember_me" checked>
                     Se souvenir de moi
                  </label>
                  <input type="submit" name=".submit" value="Se connecter" class="button small">
              </form>`;
        showPowerUserInfo(form); // open a new modal

        // TODO: if the user needs to create a user account

        document.getElementById('property').addEventListener('submit', function(e){
            e.preventDefault();

            // If the user validate the user login form
            const userLoginURL = "https://world.openfoodfacts.org/" + "/cgi/session.pl";
            const user = document.getElementsByName("user_id");
            const password = document.getElementsByName("password");
            fetch(userLoginURL, {
                // Adding method type
                method: "POST",
                // Adding body or contents to send
                body: `user=${user}&password=${password}`
            })
            // Converting to JSON
                .then(response.json())
            // Test if status is 200
                .then(response => {
                console.log(response);
            });
        });
    }

@alexgarel
Copy link
Member

With google fellowship, anonymous contribution to robotoff questions was implemented.

So we can no use it, and, of course, we can still encourage users to create an account, but it can simply redirect to the account creation page.

We have yet to implement the client side features:

@alexgarel
Copy link
Member

We can close this issue, you can test it on openfoodfacts.net

@raphael0202
Copy link
Contributor

I've just tried it on dev instance, the vote is indeed registered on Robotoff dev 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature Features or enhancements to Open Food Facts server 🎨 Mockup available A mockup has been created for this feature. Please however interact before implementing. 🎯 P1 candidate 🎯 P1 pathway-to-contribution Product Page 🛣️ Road to scores Ensuring getting the Nutri-Score and Eco-Score is easy for users, and takes 1 or 2 minutes max. 🤖 Robotoff ⭐ top issue Top issue. 👍 Top 10 Issue!
Projects
Status: 🏗 In progress
Development

No branches or pull requests

5 participants