0

I have very big problem with login panel. I am still learning AngularJS. Can you help me with login panel? Here is my code guys. I don't know what I should do now: 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
                }               
                };    
        })
YasserKaddour
  • 880
  • 11
  • 23
Giacomo
  • 341
  • 2
  • 8
  • 25

2 Answers2

2

For angular you need token based authentication. What is token based authentication?
I never use silex but I found this
https://gonzalo123.com/2014/05/05/token-based-authentication-with-silex-applications/
Another method is normal login form and when user login in see angular app, but this is bad when you try create mobile app.

Community
  • 1
  • 1
seti
  • 341
  • 1
  • 7
  • 19
  • this second way is better for me, but i stay in one point now. Idk how can i write correctly this. – Giacomo May 08 '16 at 20:23
  • Create route with form, submit form check login and after submit reditect to route where is up, example /dashboard /admin – seti May 08 '16 at 20:43
0

Take a look at for example this:

https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps

I recommend jwt auth it's very nice!

Jamie
  • 10,302
  • 32
  • 103
  • 186