D
D
des1roer2016-03-29 06:32:40
Yii
des1roer, 2016-03-29 06:32:40

Yii 2 authorization by IP?

How to make authorization by IP?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2016-03-29
@des1roer

did you find something on upwork? So there you still need to cover the application with tests.
LoginForm.php

/**
     * Logs in a user using the provided username and password.
     * @return boolean whether the user is logged in successfully
     */
    public function login()
    {

        return Yii::$app->user->login($this->getUser(Yii::$app->request->userIP));

    }

    /**
     * Finds user by 
     *
     * @return User|null
     */
    public function getUser()
    {
        if ($this->_user === false) {
            $this->_user = User::findByIp(Yii::$app->request->userIP);
        }

        return $this->_user;
    }

user.php
public static function findByIp($ip)
    {
        return new static(['id'=>$ip  ]);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question