Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. <link rel="import" href="../bower_components/polymer/polymer.html">
  2. <link rel="import" href="../bower_components/paper-button/paper-button.html">
  3. <link rel="import" href="../bower_components/paper-card/paper-card.html">
  4. <link rel="import" href="../bower_components/paper-input/paper-input.html">
  5. <link rel="import" href="../bower_components/paper-tooltip/paper-tooltip.html">
  6. <link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
  7. <link rel="import" href="../bower_components/iron-icons/iron-icons.html">
  8. <link rel="import" href="../bower_components/iron-icons/communication-icons.html">
  9. <link rel="import" href="../bower_components/paper-progress/paper-progress.html">
  10. <link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
  11. <link rel="import" href="shared-styles.html">
  12.  
  13. <!--
  14. `pe-login`
  15. Login page for Poke Erudite
  16.  
  17. @demo demo/index.html
  18. -->
  19.  
  20. <dom-module id="pe-login">
  21. <template>
  22. <style>
  23. :host {
  24. display: block;
  25. }
  26.  
  27. paper-card {
  28. width: 30%;
  29. text-align: left;
  30. }
  31.  
  32. paper-button[primary]:not([disabled]) {
  33. color: var(--primary-color);
  34. background: transparent;
  35. }
  36.  
  37. paper-icon-button:disabled {
  38. color: #000 !important;
  39. }
  40.  
  41. paper-button:disabled {
  42. background: var(--light-background-color);
  43. }
  44.  
  45. paper-button {
  46. padding: 2%;
  47. }
  48.  
  49. paper-progress {
  50. width: 100%;
  51. --paper-progress-active-color: var(--primary-color);
  52. }
  53.  
  54. #progressHidden {
  55. display: none;
  56. }
  57. </style>
  58.  
  59. <!--Put the iron-ajax element here-->
  60.  
  61. <iron-ajax id="loginAjax" method="POST" auto handle-as="json" last-response="loginResponse" on-response="loginCheck" on-error="loginError"></iron-ajax>
  62.  
  63.  
  64. <paper-tooltip delay="0" for="icon" position="top" offset="14">
  65. [[_message]] Password
  66. </paper-tooltip>
  67. <center>
  68. <paper-card heading="Sign In" elevation="1" animated-shadow>
  69. <div class="card-content">
  70. <paper-input id="userName" label="Username">
  71. <paper-icon-button disabled slot="prefix" icon="account-circle"></paper-icon-button>
  72. </paper-input>
  73. <paper-input id="userPassword" label="Password" type="[[_passputType]]">
  74.  
  75. <paper-icon-button slot="prefix" disabled icon="communication:vpn-key"></paper-icon-button>
  76.  
  77. <paper-icon-button slot="suffix" icon="[[_icon]]" id="icon" on-tap="setIcon"></paper-icon-button>
  78. </paper-input>
  79. </div>
  80. <div class="card-actions">
  81. <paper-button id="loginButton" primary on-tap="signIn">Sign In</paper-button>
  82. </div>
  83.  
  84. <paper-progress indeterminate id="progressHidden"></paper-progress>
  85.  
  86. </paper-card>
  87. </center>
  88.  
  89. </template>
  90.  
  91. <script>
  92. class PeLogin extends Polymer.Element {
  93. static get is() { return 'pe-login'; }
  94. static get properties() {
  95. return {
  96. _icon: {
  97. type: String,
  98. value: 'visibility',
  99. notify: true
  100. },
  101. _message: {
  102. type: String,
  103. value: 'Show'
  104. },
  105. _passputType: {
  106. type: String,
  107. value: 'password'
  108. }
  109. };
  110. }
  111.  
  112. // Here go all the other handler function
  113. setIcon() {
  114. if (this._icon == 'visibility') {
  115. this._message = 'Hide';
  116. this._icon = 'visibility-off';
  117. this._passputType = 'text';
  118. } else {
  119. this._message = 'Show';
  120. this._icon = 'visibility';
  121. this._passputType = 'password';
  122. }
  123. }
  124.  
  125. loginCheck(event) {
  126. var res;
  127. // Declare all the variables
  128. var button, progress, inputs, ajax, res;
  129.  
  130. // Set their values
  131. button = this.$.loginButton;
  132. progress = this.$.progressHidden;
  133. inputs = {
  134. name: this.$.userName,
  135. password: this.$.userPassword
  136. };
  137. ajax = this.$.loginAjax;
  138.  
  139. res = event.detail.response;
  140.  
  141. if (res.verdict == 1) {
  142. console.log(
  143. " Username:" + res.username + ", n Password: " + res.password
  144. );
  145. }
  146. }
  147.  
  148. signIn() {
  149. // Declare all the variables
  150. var button, progress, inputs, ajax, res;
  151.  
  152. // Set their values
  153. button = this.$.loginButton;
  154. progress = this.$.progressHidden;
  155. inputs = {
  156. name: this.$.userName,
  157. password: this.$.userPassword
  158. };
  159. ajax = this.$.loginAjax;
  160.  
  161. ajax.body = JSON.stringify({
  162. 'username': inputs.name.value,
  163. 'password': inputs.password.value
  164. });
  165. ajax.url = 'http://localhost/php/login.php';
  166.  
  167. ajax.generateRequest();
  168.  
  169. button.disabled = !button.disabled;
  170. progress.id = '';
  171. inputs.name.disabled = !inputs.name.disabled;
  172. inputs.password.disabled = !inputs.password.disabled;
  173.  
  174. }
  175.  
  176. setCookie(cname, cvalue, exdays) {
  177. var d = new Date();
  178. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  179. var expires = "expires=" + d.toUTCString();
  180. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  181. }
  182.  
  183. }
  184.  
  185. window.customElements.define(PeLogin.is, PeLogin);
  186. </script>
  187. </dom-module>
  188.  
  189. <?php
  190. $username = trim($_POST['username']);
  191. $password = trim($_POST['password']);
  192.  
  193. echo json_encode(
  194. array(
  195. 'verdict' => 1,
  196. 'username' => $username,
  197. 'password' => sha1($password)
  198. )
  199. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement