Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- here is my login controller
- //login controller
- .controller('LoginCtrl', function($scope, $state, Login, $ionicPopup) {
- $scope.login = function() {
- Login.login($scope.login).then(function (data) {
- if (Object.keys(data.data).length === 1) {
- var datao = angular.toJson(data.data);
- $scope.profile = datao;
- console.log($scope.profile);
- // var use = Object.keys(data.data[1]);
- // // $scope.profile.data.forEach(function(d) {
- // console.log(use);
- console.log(angular.isObject(datao));
- // });
- // $state.go('dashboard');
- } else {
- $ionicPopup.alert({
- title: "Login error!",
- template: "Incorrect email or password, please verify and try again.",
- okText: 'Ok',
- okType: 'button-positive'
- });
- }
- });
- };
- })
- and the php backend is
- <?php
- //deal with CORS
- if (isset($_SERVER['HTTP_ORIGIN'])) {
- header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 86400');
- }
- if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
- header("Access-Control-Allow-Methods: GET");
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
- header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
- exit(0);
- }
- //vars to connect to database
- $hostname = 'localhost';
- $username = 'root';
- $password = 'root';
- $database = 'prayer';
- //prepare PDO connection to DB
- $pdo = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
- switch ($_SERVER['REQUEST_METHOD']) {
- case 'GET':
- $user = mysql_real_escape_string($_REQUEST['user']);
- $pass = mysql_real_escape_string(md5($_REQUEST['pass']));
- $query_params = array(
- ':user' => $user,
- ':pass' => $pass
- );
- //run query
- $st = $pdo->prepare("SELECT * FROM userz where email=:user and password=:pass");
- $result = $st->execute($query_params);
- echo json_encode($st->fetchAll(PDO::FETCH_ASSOC));
- // $resulto = $st->fetchAll(PDO::FETCH_ASSOC);
- // $email = $resulto[0]['email'];
- // echo "$email";
- break;
- }
- ?>
- i need to be able to get the user email as $scope.profile gives following data
- [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