Add created field to API Tokens.

This commit is contained in:
Jonathan Bernard 2019-03-08 03:02:57 -06:00
parent b23d3d36af
commit 9a9fa7c5d9
3 changed files with 7 additions and 3 deletions

View File

@ -312,6 +312,7 @@ proc start*(ctx: PMApiContext): void =
var newToken = ApiToken( var newToken = ApiToken(
userId: session.user.id, userId: session.user.id,
name: jsonBody.getOrFail("name").getStr, name: jsonBody.getOrFail("name").getStr,
created: getTime().utc,
expires: none[DateTime](), expires: none[DateTime](),
hashedToken: "") hashedToken: "")
@ -523,7 +524,7 @@ proc start*(ctx: PMApiContext): void =
message: jsonBody.getOrFail("message").getStr, message: jsonBody.getOrFail("message").getStr,
scope: jsonBody.getOrFail("scope").getStr, scope: jsonBody.getOrFail("scope").getStr,
stacktrace: jsonBody.getIfExists("stacktrace").getStr(""), stacktrace: jsonBody.getIfExists("stacktrace").getStr(""),
timestamp: jsonBody.getOrFail("timestampe").getStr.parseIso8601 timestamp: jsonBody.getOrFail("timestamp").getStr.parseIso8601
) )
resp(Http200, $(%ctx.db.createClientLogEntry(logEntry)), JSON) resp(Http200, $(%ctx.db.createClientLogEntry(logEntry)), JSON)
except BadRequestError: jsonResp(Http400, getCurrentExceptionMsg()) except BadRequestError: jsonResp(Http400, getCurrentExceptionMsg())
@ -541,7 +542,7 @@ proc start*(ctx: PMApiContext): void =
message: it.getOrFail("message").getStr, message: it.getOrFail("message").getStr,
scope: it.getOrFail("scope").getStr, scope: it.getOrFail("scope").getStr,
stacktrace: it.getIfExists("stacktrace").getStr(""), stacktrace: it.getIfExists("stacktrace").getStr(""),
timestamp: it.getOrFail("timestampe").getStr.parseIso8601 timestamp: it.getOrFail("timestamp").getStr.parseIso8601
)) ))
resp(Http200, $(%respMsgs), JSON) resp(Http200, $(%respMsgs), JSON)
except BadRequestError: jsonResp(Http400, getCurrentExceptionMsg()) except BadRequestError: jsonResp(Http400, getCurrentExceptionMsg())

View File

@ -13,6 +13,7 @@ type
id*: UUID id*: UUID
userId*: UUID userId*: UUID
name*:string name*:string
created*: DateTime
expires*: Option[DateTime] expires*: Option[DateTime]
hashedToken*: string hashedToken*: string
@ -74,7 +75,8 @@ proc `%`*(tok: ApiToken): JsonNode =
result = %*{ result = %*{
"id": $tok.id, "id": $tok.id,
"userId": $tok.userId, "userId": $tok.userId,
"name": tok.name "name": tok.name,
"created": tok.created
} }
if tok.expires.isSome: if tok.expires.isSome:

View File

@ -14,6 +14,7 @@ create table "api_tokens" (
id uuid default uuid_generate_v4() primary key, id uuid default uuid_generate_v4() primary key,
user_id uuid not null references users (id) on delete cascade on update cascade, user_id uuid not null references users (id) on delete cascade on update cascade,
name varchar not null, name varchar not null,
created timestamp with time zone not null default current_timestamp,
expires timestamp with time zone default null, expires timestamp with time zone default null,
hashed_token varchar not null hashed_token varchar not null
); );