Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996582
finalize-registration-intent.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
finalize-registration-intent.ts
View Options
import
{
Middleware
}
from
"@koa/router"
;
import
{
hasShape
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
assert
from
"assert"
;
const
finalizeRegistrationIntent
:
Middleware
=
async
(
ctx
)
=>
{
if
(
!
hasShape
(
{
token
:
predicates
.
string
,
username
:
predicates
.
string
,
password
:
predicates
.
string
,
},
ctx
.
$body
)
)
{
throw
new
Error
(
"Missing attributes. Required: token, username, password"
);
}
const
intents
=
await
ctx
.
$app
.
collections
[
"registration-intents"
]
.
suList
()
.
filter
({
token
:
ctx
.
$body
.
token
})
.
fetch
();
if
(
intents
.
empty
)
{
throw
new
Error
(
"Incorrect token"
);
}
const
intent
=
intents
.
items
[
0
];
const
user
=
await
ctx
.
$app
.
collections
.
users
.
suCreate
({
password
:
ctx
.
$body
.
password
,
username
:
ctx
.
$body
.
username
,
email
:
intent
.
get
(
"email"
)
as
string
,
roles
:
[],
});
if
(
intent
.
get
(
"role"
))
{
await
ctx
.
$app
.
collections
[
"user-roles"
].
suCreate
({
user
:
user
.
id
,
role
:
intent
.
get
(
"role"
)
as
string
,
});
}
await
intent
.
remove
(
new
ctx
.
$app
.
SuperContext
());
const
target_path
=
ctx
.
$app
.
ConfigManager
.
get
(
"accout_creation_success_path"
);
if
(
target_path
)
{
assert
.
strictEqual
(
target_path
[
0
],
"/"
,
"'accout_creation_success_path' set, but doesn't start with a '/'"
);
ctx
.
body
=
`<meta http-equiv="refresh" content="0; url=
${
target_path
}
" />`
;
}
ctx
.
body
=
"Account creation successful"
;
ctx
.
status
=
201
;
};
export
default
finalizeRegistrationIntent
;
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:05 (44 m, 36 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557322
Default Alt Text
finalize-registration-intent.ts (1 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline
Log In to Comment