AngularJS + PHP。登录面板

时间:2016-05-08 18:23:25

标签: javascript php angularjs

我的登录面板有很大的问题。我还在学习AngularJS。 你能用登录面板帮我吗?这是我的代码人。我不知道我现在应该做什么: api.php:

public function getLogin()
    {
           $sql = "SELECT login FROM users WHERE login='$username' AND password='$password'";

            return $this->db->fetchAll();
    }

$app->get('/login', function () use ($app, $DataProvider) {

    $login = $DataProvider->getLogin();

    return $app->json($login);
});

的login.html:

<div class="row">
    <div class="col-lg-10 col-sm-10 col-xs-12">
        <div class="flat-panel">
            <div class="flat-panel-header">
                <h3 class="flat-panel-heading">Panel logowania</h3>
            </div>
            <div class="flat-panel-body">
                <div class="form-group">
                <input type="text" class="form-control" ng-model="loginInfo.username" placeholder="Podaj login">
                </div>
                <div class="form-group">
                <input type="password" class="form-control" ng-model="loginInfo.password" placeholder="Podaj hasło">
                </div>
                <div class="form-group">
                <button ng-click="loginUser()" class="btn btn-primary">Zaloguj</button>
                </div>
            </div>
        </div>
    </div>
</div>

services.js:

app.factory('login', ['$http', function($http){
   var _getLogin = function (callback) {
        callback = callback||function(){};
        $http.get('/api.php/login')
            .success(function (data) {
                callback(data);
            });
    };
    return {
        getLogin: _getLogin
    };

app.js:

  app.controller("LoginController", function($scope, $http){
        $scope.loginInfo = {
            username: undefined,
            password: undefined
        }
            $scope.loginUser = function(){
                var data = {
                    username: $scope.loginInfo.username,
                    password: $scope.loginInfo.password
                }               
                };    
        })

2 个答案:

答案 0 :(得分:2)

对于角度,您需要基于令牌的身份验证。 What is token based authentication?
我从不使用silex,但我发现了这个 https://gonzalo123.com/2014/05/05/token-based-authentication-with-silex-applications/
另一种方法是正常登录表单,当用户登录时请参阅angular app,但是当您尝试创建移动应用程序时,这是不好的。

答案 1 :(得分:0)