Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <dom-module id="login-form">
  2. <style>
  3. paper-material {
  4. width:300px;
  5. height:205px;
  6. padding:15px;
  7. margin:20px;
  8. }
  9.  
  10. h1 {
  11. margin: 0;
  12. font-size: 22px;
  13. }
  14.  
  15. paper-button {
  16. margin-top:15px;
  17. float:right;
  18. background-color:#CFF09E;
  19. }
  20. </style>
  21. <template>
  22. <paper-material elevation="1">
  23. <h1>Login</h1>
  24. <paper-input type="text" label="Email" value="{{email::input}}"></paper-input>
  25. <paper-input type="password" label="Password" value="{{password::input}}"></paper-input>
  26. <paper-button raised on-click="tryLogin">Login</paper-button>
  27. </paper-material>
  28. <iron-ajax
  29. id="ajax"
  30. method="POST"
  31. url="../functions/login.php"
  32. handle-as="json"
  33. on-response="loginResponse">
  34. </iron-ajax>
  35. </template>
  36. <script>
  37. Polymer({
  38. is: 'login-form',
  39. properties: {
  40. 'email': {
  41. type: String,
  42. value: null
  43. },
  44. 'password': {
  45. type: String,
  46. value: null
  47. }
  48. },
  49. tryLogin: function(e){
  50. var datalist='email='+decodeURIComponent(this.email)+'&password='+encodeURIComponent(this.password);
  51. console.log(datalist);
  52. this.$.ajax.body=datalist;
  53. this.$.ajax.generateRequest();
  54. },
  55. loginResponse: function(r){
  56. console.log(r.detail.response);
  57. if (r.detail.response.success==1) {
  58. console.log('+1');
  59. } else {
  60. console.log('-1');
  61. }
  62. }
  63. });
  64. </script>
  65.  
  66. <?php
  67. session_start();
  68. require_once '../database/connect.php';
  69. header('content-type: application/json');
  70.  
  71. $login_user = $this->db->prepare("SELECT * FROM user WHERE email = :email");
  72.  
  73. $login_user->execute(array(':email' => $email));
  74.  
  75. $find_user_row = $login_user->fetch(PDO::FETCH_ASSOC);
  76.  
  77. if($login_user->rowCount() > 0){
  78. if(password_verify($password, $find_user_row['password'])){
  79. $_SESSION['fname'] = $find_user_row['fname'];
  80. $_SESSION['lname'] = $find_user_row['lname'];
  81. $_SESSION['session_user_id'] = $find_user_row['user_id'];
  82. $_SESSION['admin'] = $find_user_row['admin'];
  83. $_SESSION['isloggedin'] = true;
  84. echo json_encode(array('success'=> 1, 'userId' => $find_user_row['user_id'], 'email' => $find_user_row['email']));
  85. } else {
  86. return(array('error' => 'error'));
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement