Advertisement
Guest User

angular

a guest
Nov 15th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. -- here is my login controller
  2. //login controller
  3. .controller('LoginCtrl', function($scope, $state, Login, $ionicPopup) {
  4. $scope.login = function() {
  5. Login.login($scope.login).then(function (data) {
  6. if (Object.keys(data.data).length === 1) {
  7. var datao = angular.toJson(data.data);
  8.  
  9. $scope.profile = datao;
  10.  
  11.  
  12. console.log($scope.profile);
  13.  
  14.  
  15. // var use = Object.keys(data.data[1]);
  16. // // $scope.profile.data.forEach(function(d) {
  17. // console.log(use);
  18. console.log(angular.isObject(datao));
  19. // });
  20.  
  21. // $state.go('dashboard');
  22. } else {
  23. $ionicPopup.alert({
  24. title: "Login error!",
  25. template: "Incorrect email or password, please verify and try again.",
  26. okText: 'Ok',
  27. okType: 'button-positive'
  28. });
  29. }
  30. });
  31. };
  32. })
  33.  
  34. and the php backend is
  35. <?php
  36. //deal with CORS
  37. if (isset($_SERVER['HTTP_ORIGIN'])) {
  38. header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  39. header('Access-Control-Allow-Credentials: true');
  40. header('Access-Control-Max-Age: 86400');
  41. }
  42.  
  43. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  44.  
  45. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
  46. header("Access-Control-Allow-Methods: GET");
  47.  
  48. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
  49. header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  50. exit(0);
  51. }
  52. //vars to connect to database
  53. $hostname = 'localhost';
  54. $username = 'root';
  55. $password = 'root';
  56. $database = 'prayer';
  57. //prepare PDO connection to DB
  58. $pdo = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
  59. switch ($_SERVER['REQUEST_METHOD']) {
  60. case 'GET':
  61. $user = mysql_real_escape_string($_REQUEST['user']);
  62. $pass = mysql_real_escape_string(md5($_REQUEST['pass']));
  63. $query_params = array(
  64. ':user' => $user,
  65. ':pass' => $pass
  66. );
  67. //run query
  68. $st = $pdo->prepare("SELECT * FROM userz where email=:user and password=:pass");
  69. $result = $st->execute($query_params);
  70. echo json_encode($st->fetchAll(PDO::FETCH_ASSOC));
  71.  
  72. // $resulto = $st->fetchAll(PDO::FETCH_ASSOC);
  73. // $email = $resulto[0]['email'];
  74. // echo "$email";
  75. break;
  76. }
  77. ?>
  78.  
  79. i need to be able to get the user email as $scope.profile gives following data
  80. [Log] [{"id":"5","username":"ozombo","reputation":"ceo","activate":"8425","followercount":"3","praycount":"0","donetour":"0","fb_id":"0","fullname":"Adebambo Oyelaja","church":"RCCG ","photo":"1417451697.jpg","twtr_id":"0","screen_name":"","email":"oyexs911@yahoo.com","bio":"Geek, Father, Husband","country":"Nigeria","state":"Lagos","followscount":"0","account":"","password":"5cf1bc1b9a2ada1ae9e29079aae1aefa","signup_date":"1413305984","signupdevice":"web","keycode":"5fc868f0767b0c164341a9e8e35edbe4","last_login":"1436519269","city":"Palmgroove","campaign":"","bday":"29-09-1988","gender":"Male","approved":"0","donewelcome":"0","phonenumber":"07017993683","secure":"private","churchid":"1","views":"68","marital":"Married"}] (controllers.js, line 76)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement