public function addLog(LoginLog $model) { $model->createTime = time(); $model->ip = ApiRequest::getRemoteIp(); if ($model->status != LoginLog::STATUS_SUCCESS) { $model->status = LoginLog::STATUS_FAILED; } $dbManager = Db::getInstance(); $statement = $dbManager->prepare(self::ADD_LOGIN_LOG); if (!$statement->execute([$model->uid, $model->createTime, $model->ip, $model->status])) { return new ApiResponse(Code::FAIL_DATABASE_ERROR, 'add login log failed' . var_export($statement->errorInfo(), true)); } return null; }
public function addUserEx(User $model) { $ip = ApiRequest::getRemoteIp(); $regex = '/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(\\.\\d{1,3}\\.\\d{1,3})?$/'; if (!$ip || !preg_match($regex, $ip)) { return new ApiResponse(Code::FAIL_INVALID_IP, null); } $dbManager = Db::getInstance(); $statement = $dbManager->prepare(self::USER_COUNT_BY_IP); if (!$statement->execute([$ip, time() - 86400]) || false === ($number = $statement->fetchColumn())) { return new ApiResponse(Code::FAIL_DATABASE_ERROR, 'fetch create user count failed' . var_export($statement->errorInfo(), true)); } if ($number > 100) { return new ApiResponse(Code::FAIL_USER_CREATE_TOO_FREQUENTLY, null); } return $this->addUser($model); }