Giter Site home page Giter Site logo

Comments (3)

me-no-dev avatar me-no-dev commented on June 23, 2024

request->requestAuthentication(); on authenticated user will clear the authentication from the browser

from espasyncwebserver.

AcuarioCat avatar AcuarioCat commented on June 23, 2024

Works thanks 👍

from espasyncwebserver.

GeorgeFlorian avatar GeorgeFlorian commented on June 23, 2024

How does it work ?
How can you turn this OFF ?
I have a LOGIN and a SKIP button inside a HTML page.

This is the LOGIN:

  server.on("/register", HTTP_POST, [](AsyncWebServerRequest * request){
    int params = request->params();
    String values_user[2];
    for(int i=0;i<params;i++){
      AsyncWebParameter* p = request->getParam(i);
      if(p->isPost()){
          logOutput((String)"POST[" + p->name().c_str() + "]: " + p->value().c_str() + "\n");            
          values_user[i] = p->value();            
        } else {
            logOutput((String)"GET[" + p->name().c_str() + "]: " + p->value().c_str() + "\n");
          }
    } // for(int i=0;i<params;i++)
    
    if(values_user[0] != NULL && values_user[0].length() != 0 &&
      values_user[1] != NULL && values_user[1].length() != 0) {
          File userWrite = SPIFFS.open("/user.txt", FILE_WRITE);
          if(!userWrite) logOutput((String)"ERROR_INSIDE_POST ! Couldn't open file to write USER credentials !");
          userWrite.println(values_user[0]);  // Username
          userWrite.println(values_user[1]);  // Password
          userWrite.close();
          logOutput("Username and password saved !");
          
          request->redirect("/config");
          // digitalWrite(LED, LOW);
    } else request->redirect("/register");  
  });

And this is the SKIP:

  server.on("/button", HTTP_POST, [](AsyncWebServerRequest * request){
    int params = request->params();
    String values_button = "";
    for(int i=0;i<params;i++){
      AsyncWebParameter* p = request->getParam(i);
      if(p->isPost()){
          logOutput((String)"POST[" + p->name().c_str() + "]: " + p->value().c_str() + "\n");            
          values_button = p->value();            
        } else {
            logOutput((String)"GET[" + p->name().c_str() + "]: " + p->value().c_str() + "\n");
          }
    } // for(int i=0;i<params;i++)
    values_button.trim();
    if(values_button == "Skip") {
      request->requestAuthentication(); // this doesn't change a thing
    }
    request->redirect("/config");    
  }); 

This is the "/config" :

  server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request){  
    if(!request->authenticate(http_username, http_password))
      return request->requestAuthentication();            
    request->send(SPIFFS, "/STA_configPage.html", "text/html");
  });

If I press SKIP it redirects me to config but still asks for a username and password.

from espasyncwebserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.