Cleanup frontend to only pass the required description field
This commit is contained in:
parent
374910d73a
commit
dfff8ad667
4 changed files with 30 additions and 27 deletions
|
@ -13,18 +13,6 @@ class StoreApiKeyRequest extends ClientApiRequest
|
|||
|
||||
return [
|
||||
'description' => $rules['memo'],
|
||||
'allowed_ips' => $rules['allowed_ips'],
|
||||
'allowed_ips.*' => 'ip',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'allowed_ips.*' => 'All of the IP addresses entered must be valid IPv4 addresses.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,11 @@ class PersonalAccessToken extends Model implements HasAbilities
|
|||
{
|
||||
public const RESOURCE_NAME = 'personal_access_token';
|
||||
|
||||
/**
|
||||
* The length of the raw API token.
|
||||
*/
|
||||
public const TOKEN_LENGTH = 32;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
|
@ -28,6 +33,16 @@ class PersonalAccessToken extends Model implements HasAbilities
|
|||
'abilities',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static array $validationRules = [
|
||||
'token' => 'required|string',
|
||||
'token_id' => 'required|string|size:16',
|
||||
'description' => 'required|nullable|string|max:500',
|
||||
'last_used_at' => 'nullable|date',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
|
@ -87,4 +102,14 @@ class PersonalAccessToken extends Model implements HasAbilities
|
|||
|
||||
return static::where('token_id', $id)->where('token', hash('sha256', $token))->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new identifier for a personal access token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generateTokenIdentifier(): string
|
||||
{
|
||||
return 'ptdl_' . Str::random(11);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ trait HasAccessTokens
|
|||
$token = $this->tokens()->create([
|
||||
'user_id' => $this->id,
|
||||
'description' => $description,
|
||||
'token' => hash('sha256', $plain = Str::random(36)),
|
||||
'token_id' => 'ptdl_' . Str::random(11),
|
||||
'token' => hash('sha256', $plain = Str::random(PersonalAccessToken::TOKEN_LENGTH)),
|
||||
'token_id' => PersonalAccessToken::generateTokenIdentifier(),
|
||||
'abilities' => $abilities,
|
||||
]);
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ import { ApplicationStore } from '@/state';
|
|||
import { httpErrorToHuman } from '@/api/http';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import { ApiKey } from '@/api/account/getApiKeys';
|
||||
import tw, { styled } from 'twin.macro';
|
||||
import tw from 'twin.macro';
|
||||
import Button from '@/components/elements/Button';
|
||||
import Input, { Textarea } from '@/components/elements/Input';
|
||||
import Input from '@/components/elements/Input';
|
||||
import ApiKeyModal from '@/components/dashboard/ApiKeyModal';
|
||||
|
||||
interface Values {
|
||||
|
@ -18,8 +18,6 @@ interface Values {
|
|||
allowedIps: string;
|
||||
}
|
||||
|
||||
const CustomTextarea = styled(Textarea)`${tw`h-32`}`;
|
||||
|
||||
export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => {
|
||||
const [ apiKey, setApiKey ] = useState('');
|
||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
@ -52,7 +50,6 @@ export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => {
|
|||
onSubmit={submit}
|
||||
initialValues={{ description: '', allowedIps: '' }}
|
||||
validationSchema={object().shape({
|
||||
allowedIps: string(),
|
||||
description: string().required().min(4),
|
||||
})}
|
||||
>
|
||||
|
@ -62,18 +59,11 @@ export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => {
|
|||
<FormikFieldWrapper
|
||||
label={'Description'}
|
||||
name={'description'}
|
||||
description={'A description of this API key.'}
|
||||
description={'This API key will be able to act on your behalf against this Panel\'s API.'}
|
||||
css={tw`mb-6`}
|
||||
>
|
||||
<Field name={'description'} as={Input}/>
|
||||
</FormikFieldWrapper>
|
||||
<FormikFieldWrapper
|
||||
label={'Allowed IPs'}
|
||||
name={'allowedIps'}
|
||||
description={'Leave blank to allow any IP address to use this API key, otherwise provide each IP address on a new line.'}
|
||||
>
|
||||
<Field name={'allowedIps'} as={CustomTextarea}/>
|
||||
</FormikFieldWrapper>
|
||||
<div css={tw`flex justify-end mt-6`}>
|
||||
<Button>Create</Button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue