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
                }               
                };    
        })
1
  • Do you using php framework? Commented May 8, 2016 at 19:47

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

this second way is better for me, but i stay in one point now. Idk how can i write correctly this.
Create route with form, submit form check login and after submit reditect to route where is up, example /dashboard /admin
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.