Question

What would be the best way to retrieve the Username entered on a login form in dart polymer to be read in the next page to which it is redirected?

The login component is as below -

@CustomTag('alfresco-login-form')
class LoginFormComponent extends FormElement with Polymer, Observable {
  LoginFormComponent.created() : super.created();

  @observable String username = "";
  @observable String password = "";

  @observable Map loginData = toObservable({
    'username' : '',
    'password' : ''
  });


  @observable String serverResponse = '';
  HttpRequest request;

  void submitForm(Event e, var detail, Node target) {
    e.preventDefault(); // Don't do the default submit.

    request = new HttpRequest();

    request.onReadyStateChange.listen(onData); 

    // POST the data to the server.
    var url = 'http://127.0.0.1/alfresco/service/api/login';

    request.open("POST", url);
    request.send(_loginDataAsJsonData());
  }

  void onData(_) {
    if (request.readyState == HttpRequest.DONE &&
        request.status == 200) {
      // Data saved OK.
      serverResponse = 'Server Sez: ' + request.responseText;

      Map parsedMap = JSON.decode(request.responseText);

      var currentTicket = new Ticket(parsedMap["data"]["ticket"]);

      //keeps the back history button active
      //window.location.assign('dashboard.html');

      //doesn't keep the back history button active
      //doesn't put the originating page in the session history
      window.location.replace('dashboard.html');
    } else if (request.readyState == HttpRequest.DONE &&
        request.status == 0) {
      // Status is 0...most likely the server isn't running.
      serverResponse = 'No server';
    }
  }
  String _loginDataAsJsonData(){
    return JSON.encode(loginData);
  }
}

I need to have access to that loginData['username'] & parsedMap["data"]["ticket"] to be available in the page dashboard.html.

Was it helpful?

Solution

Not really an answer, but to long for a comment:

Your code shows how you send the credentials to the server. So my previous comment still fits. You can't just pass variables to a new page. When a page is loaded this is like a application restart. You can pass values in the URL you redirect to, as cookies if both pages are loaded from the same domain or you can just reload them from the server where you stored them previously. To know that the new page is was requested by the same user you have to use some session handling (like the previously mentioned session cookie). This has nothing to do with Dart or Polymer this is more about how the web works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top