Premise :

one , In the interface that needs to get user information , The front end needs to call the api It's on the head token, this token Return to the front end when logging in .

two , All operations are based on User User table , If it is another user table, you need to make relevant changes . There are only two documents to be changed .API With Auth A series of operations can be performed in these two class libraries .

Fatal Frame , The ultimate move
$this->auth->direct($info->id); $info['token']=$this->auth->getToken();
$this->success(' Login successful ',$this->auth->getUserinfo());
This completes the login of an account , But pay attention to the account parameters , for instance status Is it 'normal', Is it restricted to log in , Basically, you can log in directly
 

 

 

 

one , Login for token

If it's the system default User Login inside , No problem , Will return you a token. If it's a custom login, you also want it token, There are three steps .

① Login Class Library inheritance app\common\controller\API, And use Get it as follows token
Api::getRefreshtoken($userid); // The value here is transmitted user_id
②app\common\controller\Api New method added :
/* establish token*/ public function getRefreshtoken($user_id){ return
$this->auth->getRefreshtoken($user_id); }
③app\common\library\Auth New method added :
public function getRefreshtoken($user_id){ $this->direct($user_id); return
$this->_token; }
two , Through effective token Get user information

① inherit app\common\controller\Api class , And add the following code to the current class library :
protected $noNeedLogin = ['login','test', 'mobilelogin', 'register',
'resetpwd', 'changeemail', 'changemobile', 'third']; protected $noNeedRight =
'*'; public function _initialize() { parent::_initialize(); }
The test passed api Headband token Get user information public function getinfos(){ $info=Api::getUser(); return
json($info); }
② app\common\controller\API Add the following method to it :
/* Get user information */ public function getUser(){ return $this->auth->getUser(); }
 

Technology
©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree