Advertisement
Guest User

Untitled

a guest
May 10th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <ion-view title="Login">
  2. <ion-content overflow-scroll="true" padding="true" class="has-header">
  3. <?php include '../lib/init.php'; ?>
  4. <form class="list validate" ng-submit="submit()">
  5. <input type="hidden" name="action" value="login">
  6. <ion-list>
  7. <label class="item item-input">
  8. <span class="input-label">Username</span>
  9. <input type="text" ng-model="username" name="username" placeholder="">
  10. </label>
  11. <label class="item item-input">
  12. <span class="input-label">Password</span>
  13. <input type="password" ng-model="password" name="password" placeholder="">
  14. </label>
  15. </ion-list>
  16. <div class="spacer" style="height: 40px;"></div>
  17. <button type="submit" id="login-button4" class="button button-royal button-block">Log in</button>
  18. <a ui-sref="register" id="login-button5" class="button button-royal button-block button-clear">Dont have an account?</a>
  19. <a ui-sref="forgotPassword" id="login-button6" class="button button-royal button-block button-clear">Forgot password?</a>
  20. </form>
  21. </ion-content>
  22. </ion-view>
  23.  
  24. .controller('loginCtrl', function($scope, $state, $stateParams, $ionicPopup, $timeout) {
  25.  
  26. //popup alert starts here
  27. $scope.showAlert = function(status,message) {
  28. var alertPopup = $ionicPopup.alert({
  29. title: status,
  30. template: message,
  31. });
  32. };
  33. //popup alert ends here
  34.  
  35.  
  36. $scope.submit = function() {
  37. if ($scope.username && $scope.password) {
  38. var url = 'my PHP file url';
  39. var username= $scope.username;
  40. var password= $scope.password;
  41.  
  42. $scope.list = [];
  43.  
  44.  
  45. var dataString = 'username='+ username + '&password=' + password;
  46. $scope.list.push(dataString);
  47. $scope.text = '';
  48.  
  49. $http({
  50. type: "POST",
  51. url: url,
  52. data: dataString,
  53. success: function(data) {
  54. try
  55. {
  56. alert(data);
  57. }
  58. catch(e)
  59. {
  60. alert(data);
  61. }
  62. }
  63. });
  64.  
  65.  
  66. }
  67. };
  68.  
  69. })
  70.  
  71. .state('login', {
  72. url: '/login.php',
  73. templateUrl: 'templates/login.php',
  74. controller: 'loginCtrl'
  75. })
  76.  
  77. <form class="list validate" ng-submit="submit(username, password)">
  78.  
  79. $scope.submit = function(usr, pw) {
  80. if(!usr || !pw) return;
  81.  
  82. //your stuff, not mine
  83. $scope.list = [];
  84. var dataString = 'username='+ usr + '&password=' + pw;
  85. $scope.text = '';
  86.  
  87. var payload = {
  88. username: usr,
  89. password: pw
  90. };
  91.  
  92. $http.post('path/to/php/file', payload).then(function(response) {
  93. //success
  94. alert(response.data);
  95. }).catch(function(response) {
  96. //an error occurred
  97. alert(response.data);
  98. });
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement