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); }
public function testGenToken() { Tools::genToken(); }