-->

Polymer 1.0: I need an example of a login button

2019-09-15 03:26发布

问题:

Question

Does anyone have a working example of code for a login button?


Detail:

I need it to be a <paper-button> that says, "Login with x." Where "x" is any one of the following: "Google", "Google Plus", "Facebook", "Linked In", "Yahoo", or "Twitter".

Obviously, the button also needs to "point to" or integrate with the respective service it mentions.

Also please note, <google-signin> described here doesn't work for me because I need to use my own button (for styling purposes). I don't want to use the <google-signin> button. I just need the functionality it provides. And more specifically, how to implement that functionality using my own <paper-button> element.


Code:

<paper-button>Login with Google</paper-button>
<paper-button>Login with Google Plus</paper-button>
<paper-button>Login with Facebook</paper-button>
<paper-button>Login with Linked-In</paper-button>
<paper-button>Login with Yahoo</paper-button>
<paper-button>Login with Twitter</paper-button>

回答1:

Element

<!--
@license
Copyright (c) 2015 Glenn Vandeuren. All rights reserved.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-button/paper-button.html">

<dom-module id="login-button">

  <style>
    :host {
      display: block;
      box-sizing: border-box;
    }
  </style>

  <template>
    <paper-button raised>Login using <span>[[service]]</span></paper-button>
  </template>

</dom-module>

<script>

  Polymer({

    is: 'login-button',

    properties: {
      service: String
    },

    listeners: {
      'tap': '_handleTap'
    },

    _handleTap: function () {
      this.fire('login', this.service);
    }

  });

</script>

Index

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
    <title>login-button Demo</title>
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
    <link rel="import" href="../login-button.html">
  </head>
  <body>

    <login-button service="google"></login-button>
    <login-button service="twitter"></login-button>

    <script>
      document.addEventListener('login', function(service) {
        // handleLogin();
        alert(service.detail);
      });
    </script>

  </body>
</html>


回答2:

On this question, Ian, posts this answer:

I ended up getting auth to work by adapting this example element by HackITtoday for my firebase urls.