2016-03-26 15 views
0

Şu anda AngularJS çerçevesini kullanarak bir giriş işlevi oluşturmaya çalışıyorum. Giriş işlevi oluşturmayı denedim, ancak başka bir ifadeyi çalıştırmayı denedim. Bu problemi nasıl çözebilirim biliyor muyum?AngularJS: Giriş işlevi PHP kodunda çalışmıyor

.controller('LoginController', 
      [ 
       '$scope', 
       'dataService', 
       '$location', 
       '$window', 
       '$rootScope', 
       function ($scope, dataService, $location, $window, $rootScope){ 
        $scope.check_login = function($event,userID,passwd){ 
         if(userID && passwd){ 
          dataService.login(userID,passwd).then(
           function (response){ 
            if(response.result.status=='ok'){ 
             $scope.user = response.user; 
             $rootScope.$broadcast("passuser", $scope.user); 
            }else{ 
             $scope.message = response.result.message; 

            } 
           }, 

           function (err) { 
            $scope.status = 'unable to connect to data' + err; 
           } 
          ); 

          $scope.reloadRoute = function() { 
           $location.path('/#'); 
           //$window.location.reload() 
          }//end of reload route fnction 
         } 
        }//end of function check_login 
       } 
      ] 
     );//end of login controller 

Bu: Bu benim controller.js kod

this.login = function (userID, passwd) { 
      var defer = $q.defer(), 
      data = { 
       //action: 'loginRob', 
       userid: userID, 
       password: passwd 
      }; 

      $http({ 
       method: 'POST', 
       url: loginUrl, 
       params: data, 
       cache: true, 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'} 

      }). // notice the dot to start the chain to success() 
      success(function (response) { 
       defer.resolve({ 
        data: response.status, // create data property with value from response 
        result: response, 
        user: response.username 
       }); 
       console.log(response); 
      }). // another dot to chain to error() 
      error(function (err) { 
       defer.reject(err); 
      }); 
      // the call to getCourses returns this promise which is fulfilled 
      // by the .get method .success or .failure 
      return defer.promise; 
     }; 

geçerli: Bu benim services.js kodu

$params = json_decode(file_get_contents('php://input'),true); 

if(!isset($_SESSION)){ 
    session_start(); 
} 

include "classes/filmService.class.php"; 
$db = pdoDB::getConnection(); 
header("Content-Type: application/json"); 

if(isset($params['userid']) && isset($params['password'])){ 

    $userid = $params['userid'] ; 
    $password = $params['password']; 
    $service = new FilmService(); 
    $result = $service->loginRob($userid,$password); 
    echo $result; 
}else{ 
    echo '{"status": "fail", "message": "Please enter email & password la!!."}'; 
} 

geçerli:

Bu benim login.php kodudur giriş için kayıt kodu:

function getLoginRecord($sql, $elementName = "ResultSet", $params = null) { 
    $stmt  = parent::getRecordSet($sql, $params); 
    $recordSet = $stmt->fetchAll(PDO::FETCH_ASSOC); 
    $nRecords = count($recordSet); 
    $loginSuccess = ""; 
    if ($nRecords == 0) { 
     $status = 'error'; 
     $message = json_encode("Invalid username or password"); 
     $result = '[]'; 
     $loginSuccess="{\"status\": \"$status\", \"message\":$message}"; 
    } 
    else { 
     $status = 'ok'; 
     $message = json_encode("Success"); 
     //$userName=json_encode($recordSet[0]['username']); 
     $result = json_encode($recordSet); 
     // $session = Session::getInstance(); 
     // $session->setProperty('user', $recordSet[0]['username']); 
     // $session->setProperty('user_email', $recordSet[0]['email']); 
     $loginSuccess="{\"status\": \"$status\", \"message\":$message }"; 
    } 
    return $loginSuccess; 
} 

Bu konuda bana yardımcı olacak birisi varsa gerçekten minnettarım. Şimdiden teşekkürler.

+0

Konsolda herhangi bir hata var mı? Bağımlılıkları doğru bir şekilde mi enjekte ettiniz? –

+0

hiçbir hata @AlonEitan sadece 'echo' {"durum": "başarısız", "ileti" gösteriliyor: "Lütfen e-posta ve şifre girin!"} '; 'Konsolda bir kez); ' – anonymous5671

+0

Lütfen bu cevaba bir göz atın http://stackoverflow.com/questions/25937775/file-get-contentsphp-input-with-application-x-www-form-urlencoded –

cevap

0

$http yolunda bazı sorunlar ayarlanmıştır.

, GET not POST için olan $http yapılandırmasında kullanıyorsunuz. data için POST

için ayarlanması gerekiyor ContentType'ı kodlanmış, ancak php'nizde json olarak almaya çalışacak biçimde değiştiriyorsunuz.

$http.post(loginUrl, data). // notice the dot to start the chain to success() 
     success(function (response) { 
      defer.resolve({ 
       data: response.status, // create data property with value from response 
       result: response, 
       user: response.username 
      }); 
      console.log(response); 
     }). // another dot to chain to error() 
     error(function (err) { 
      defer.reject(err); 
     }); 

Sonra php hala yoksa: Form kodlanmış olarak göndermek istediğiniz o zaman sayısız değişiklikler yapılması gerekiyor

Şimdilik

yüzden geçmeyi deneyin json veri olarak göndermenizi sağlar Doğru yanıt alın, verilerin gerçekten gönderilip gönderilmediğini görmek için bazı çok basit hata ayıklama işlemleri yapmanız gerekir.

+0

değişikliği bir sözdizimi hatası var ama şimdi oturum açma doğrulama çalışmıyor – anonymous5671

+0

Hangi doğrulama? Hiç gösterilmiyor – charlietfl

+0

Eh şimdi gerçekten tamamen yeni bir soru yaratıyorsunuz ve buna eklenmemeli. Size orijinal soruyu çözmek için bir çözüm sundum ve uygun bir sorun bildirimi içeren doğrulama konusunda yeni bir tane başlatmalısınız. – charlietfl