Exemplo n.º 1
0
 public function newToken($request, $response, $args)
 {
     // $data = $request->post('sdf');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     // Handle Login
     $user = User::where('email', '=', $email)->first();
     if ($user == null) {
         $res['ret'] = 0;
         $res['msg'] = "401 邮箱或者密码错误";
         return $this->echoJson($response, $res);
     }
     if (!Hash::checkPassword($user->pass, $passwd)) {
         $res['ret'] = 0;
         $res['msg'] = "402 邮箱或者密码错误";
         return $this->echoJson($response, $res);
     }
     $tokenStr = Tools::genToken();
     $storage = Factory::createTokenStorage();
     $expireTime = time() + 3600 * 24 * 7;
     if ($storage->store($tokenStr, $user, $expireTime)) {
         $res['ret'] = 1;
         $res['msg'] = "ok";
         $res['data']['token'] = $tokenStr;
         $res['data']['user_id'] = $user->id;
         return $this->echoJson($response, $res);
     }
     $res['ret'] = 0;
     $res['msg'] = "system error";
     return $this->echoJson($response, $res);
 }
Exemplo n.º 2
0
 public function testGenToken()
 {
     Tools::genToken();
 }