Git Product home page Git Product logo

angularjs-yii2-part-2-authentication's Introduction

AngularJS and Yii2 Part 2: Authentication

If you're planning on running these on your server don't forget to:

php composer.phar install

and initialize the environment

php init

The tutorial is located here Neat Tutorials

angularjs-yii2-part-2-authentication's People

Contributors

aheart avatar neattutorials avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angularjs-yii2-part-2-authentication's Issues

Angularjs files missing

Hi,
I just cloned your repository,
Yii main directory vendor always missing,
also angularjs files missing too.
Can you see into this issue please.

You are requesting with an invalid credential.

Hi,

Can anybody help me ... I am getting 401 error. The error response is:
{"name":"Unauthorized","message":"You are requesting with an invalid credential.","code":0,"status":401,"type":"yii\web\UnauthorizedHttpException"}

I am using same code and after login it returning me access_token but after login it redirect me to login with 401 Error

I debug with code step by step and finally i got this:

In "yii\filters\auth\HttpBearerAuth" class "authenticate" method is returning me null ... I print value for "$request->getHeaders()->get('Authorization')" and its return me blank.

can anybody know this why?

Thanks

Get null user after login success

I login success but can not get user info in actionDashboard()
'username' => Yii::$app->user->identity->username,
'access_token' => Yii::$app->user->identity->getAuthKey(),

and error: the server responded with a status of 403 (Forbidden)

The validation error not thrown in login UI

I follow the tutorial and when i am going to login without filling credentials it returns error message in array(exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "contact") . It's fine, but it do not show me message below the text field.

Below is my code:

Controller.js

controllers.controller('LoginController', ['$scope', '$http', '$window', '$location',
    function($scope, $http, $window, $location) {
        $scope.login = function () {
            $scope.submitted = true;
            $scope.error = {};
            $http.post('api/login', $scope.userModel).success(
                function (data) {
                    $window.sessionStorage.access_token = data.access_token;
                    $location.path('/dashboard').replace();
            }).error(
                function (data) {
                    angular.forEach(data, function (error) {
                        $scope.error[error.field] = error.message;
                    });
                }
            );
        };
    }
]);

ApiController.php

public function actionLogin()
        {
            $model = new LoginForm();

            if ($model->load(Yii::$app->getRequest()->getBodyParams(), '') && $model->login()) {
                return ['access_token' => Yii::$app->user->identity->getAuthKey()];
            } else {
                $model->validate();
                return $model;
            }
        }

login.html

<form ng-submit="login()" name="loginForm" id="login-form" method="post" role="form" >
            <div ng-class="{ 'has-success': !error['username'] && submitted,
                'has-error': error['username'] && submitted }"
                 class="form-group field-loginform-username required">
                <label class="control-label" for="loginform-username">Username(demo)</label>
                <input ng-model="userModel.username" type="text" id="loginform-username" class="form-control">
                <p class="help-block help-block-error">{{ error['username'] }}</p>
            </div>

            <div ng-class="{ 'has-success': !error['password'] && submitted,
                'has-error': error['password'] && submitted }"
                 class="form-group field-loginform-password required">
                <label class="control-label" for="loginform-password">Password(demo)</label>
                <input ng-model="userModel.password" type="password" id="loginform-password" class="form-control">
                <p class="help-block help-block-error">{{ error['password'] }}</p>
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-primary" name="login-button">Login</button>
            </div>

        </form>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.