将值从登录表单传递到仪表板 [英] Passing values from login form to dashboard

查看:141
本文介绍了将值从登录表单传递到仪表板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在dart聚合物的登录表单中检索用户名的最佳方式是什么,以便在重定向的下一页中读取?

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?

登录组件如下 -

@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);
  }
}



我需要访问该loginData ['username ']&

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

推荐答案

不是真正的答案,但要留言:

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

您的代码显示了如何将凭据发送到服务器。所以我以前的评论仍然适合。你不能只是将变量传递给一个新的页面。加载页面时,这就像应用程序重新启动。您可以将重定向到的网址中的值作为Cookie,如果这两个网页都从同一个网域加载,或者您只需从之前存储它们的服务器重新加载它们。要知道新页面是由同一个用户请求的,你必须使用一些会话处理(如前面提到的会话cookie)。这与Dart或Polymer无关这更多是关于网络如何工作。

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.

这篇关于将值从登录表单传递到仪表板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆