本文整理汇总了TypeScript中hapi.IReply类的典型用法代码示例。如果您正苦于以下问题:TypeScript IReply类的具体用法?TypeScript IReply怎么用?TypeScript IReply使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IReply类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
handler: function(request: Request, reply: IReply) {
reply.redirect('/blog' + request.path);
}
开发者ID:csgpro,项目名称:csgpro.com,代码行数:3,代码来源:index.ts
示例2: listAccounts
export async function listAccounts(server: Server, request: Request, reply: IReply)
{
return reply(notImplemented());
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:4,代码来源:accounts-routes.ts
示例3: handler
export default async function handler(req: Request, reply: IReply) {
const { hackId: hackid } = req.params
const requestDoc: HackChallengesRelationship.TopLevelDocument = req.payload
const hack = await HackModel
.findOne({ hackid }, 'hackid name challenges')
.populate('challenges', 'challengeid')
.exec()
if (hack === null) {
reply(Boom.notFound('Hack not found'))
return
}
const challengeIdsToAdd = requestDoc.data.map((challenge) => challenge.id)
const existingChallengeIds = challengeIdsToAdd.filter((challengeIdToAdd) => {
return hack.challenges.some((actualchallenge) => actualchallenge.challengeid === challengeIdToAdd)
})
if (existingChallengeIds.length > 0) {
reply(Boom.badRequest('One or more challenges are already challenges of this hack'))
return
}
const challenges = await ChallengeModel
.find({ challengeid: { $in: challengeIdsToAdd } }, 'challengeid name')
.exec()
if (challenges.length !== challengeIdsToAdd.length) {
reply(Boom.badRequest('One or more of the specified challenges could not be found'))
return
}
const challengeObjectIds = challenges.map((challenge) => challenge._id)
const hacks = await HackModel
.find({ challenges: { $in: challengeObjectIds } }, 'hackid')
.exec()
if (hacks.length > 0) {
reply(Boom.badRequest('One or more of the specified challenges are already in a hack'))
return
}
hack.challenges = hack.challenges.concat(challenges.map((challenge) => challenge._id))
await hack.save()
const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
challenges.forEach((challenge) => {
eventBroadcaster.trigger('hacks_update_challenges_add', {
hackid: hack.hackid,
name: hack.name,
entry: {
challengeid: challenge.challengeid,
name: challenge.name,
},
}, req.logger)
})
reply()
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:62,代码来源:add-hack-challenges.ts
示例4: updateUser
export async function updateUser(server: Server, request: Request, reply: IReply)
{
return reply(notImplemented());
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:4,代码来源:users-routes.ts
示例5: handler
export default async function handler(req: Request, reply: IReply) {
const query: any = {}
req.logger.info('Filter: ', req.query)
if (req.query['filter[name]']) {
query.name = createEscapedRegex(req.query['filter[name]'])
}
const teams = await TeamModel
.find(query, 'teamid name motto members entries')
.sort({ teamid: 1 })
.populate({
path: 'members',
select: 'userid name',
})
.populate({
path: 'entries',
select: 'hackid name challenges',
populate: {
path: 'challenges',
select: 'challengeid name',
},
})
.exec()
const teamResponses = teams.map((team): TeamResource.ResourceObject => ({
links: { self: `/teams/${encodeURIComponent(team.teamid)}` },
type: 'teams',
id: team.teamid,
attributes: {
name: team.name,
motto: team.motto || null,
},
relationships: {
members: {
links: { self: `/teams/${encodeURIComponent(team.teamid)}/members` },
data: team.members.map((member) => ({ type: 'users', id: member.userid })),
},
entries: {
links: { self: `/teams/${encodeURIComponent(team.teamid)}/entries` },
data: team.entries.map((hack) => ({ type: 'hacks', id: hack.hackid })),
},
},
}))
const includes: JSONApi.ResourceObject[] = [].concat(...teams.map((team): JSONApi.ResourceObject[] => {
const members = team.members.map((member): UserResource.ResourceObject => ({
links: { self: `/users/${member.userid}` },
type: 'users',
id: member.userid,
attributes: { name: member.name },
}))
const entries = team.entries.map((hack): HackResource.ResourceObject => ({
links: { self: `/hacks/${hack.hackid}` },
type: 'hacks',
id: hack.hackid,
attributes: { name: hack.name },
relationships: {
challenges: {
links: { self: `/hacks/${encodeURIComponent(hack.hackid)}/challenges` },
data: hack.challenges.map((challenge) => ({ type: 'challenges', id: challenge.challengeid })),
},
},
}))
const challenges: ChallengeResource.ResourceObject[] = [].concat(...team.entries.map((hack) => (
hack.challenges.map((challenge): ChallengeResource.ResourceObject => ({
links: { self: `/challenges/${challenge.challengeid}` },
type: 'challenges',
id: challenge.challengeid,
attributes: { name: challenge.name },
}))
)))
return [...members, ...entries, ...challenges]
}))
const teamsResponse: TeamsResource.TopLevelDocument = {
links: { self: `/teams` },
data: teamResponses,
included: includes,
}
reply(teamsResponse)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:87,代码来源:get-teams.ts
示例6: handler
export default async function handler(req: Request, reply: IReply) {
const requestDoc: TeamResource.TopLevelDocument = req.payload
const relationships = requestDoc.data.relationships
let members: JSONApi.ResourceIdentifierObject[] = []
let entries: JSONApi.ResourceIdentifierObject[] = []
if (relationships) {
if (relationships.members && relationships.members.data) {
if (!Array.isArray(relationships.members.data)) {
reply(Boom.badRequest())
return
}
members = relationships.members.data
}
if (relationships.entries && relationships.entries.data) {
if (!Array.isArray(relationships.entries.data)) {
reply(Boom.badRequest())
return
}
entries = relationships.entries.data
}
}
const team = new TeamModel({
teamid: slugify(requestDoc.data.attributes.name),
name: requestDoc.data.attributes.name,
motto: requestDoc.data.attributes.motto || null,
members: [],
entries: [],
})
let users: UserModel[] = []
let hacks: HackModel[] = []
if (members.length > 0) {
users = await UserModel.find({
userid: {
$in: members.map((member) => member.id.toString()),
},
}, '_id userid name').exec()
team.members = users.map((user) => user._id)
}
if (entries.length > 0) {
hacks = await HackModel.find({
hackid: {
$in: entries.map((entry) => entry.id.toString()),
},
}, '_id hackid name').exec()
team.entries = hacks.map((hack) => hack._id)
}
try {
await team.save()
} catch (err) {
if (err.code === MongoDBErrors.E11000_DUPLICATE_KEY) {
reply(Boom.conflict('Team already exists'))
return
}
throw err
}
const teamResponse: TeamResource.TopLevelDocument = {
links: {
self: `/teams/${encodeURIComponent(team.teamid)}`,
},
data: {
type: 'teams',
id: team.teamid,
attributes: {
name: team.name,
motto: team.motto,
},
relationships: {
members: {
links: { self: `/teams/${encodeURIComponent(team.teamid)}/members` },
data: users.map((user) => ({ type: 'users', id: user.userid })),
},
entries: {
links: { self: `/teams/${encodeURIComponent(team.teamid)}/entries` },
data: hacks.map((hack) => ({ type: 'hacks', id: hack.hackid })),
},
},
},
}
const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
eventBroadcaster.trigger('teams_add', {
teamid: team.teamid,
name: team.name,
motto: team.motto,
members: users.map((user) => ({ userid: user.userid, name: user.name })),
entries: hacks.map((hack) => ({ hackid: hack.hackid, name: hack.name })),
}, req.logger)
reply(teamResponse).code(201)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:99,代码来源:create-team.ts
示例7: postForgotPassword
export async function postForgotPassword(server: Server, request: Request, reply: IReply): Promise<IBoom | Response>
{
const props: ForgotPasswordProps = {
title: "Forgot your password?",
}
const validation = joi.validate<{username: string}>(request.payload, JoiValidation.forgotPassword);
const payload = validation.value;
if (validation.error)
{
props.username = payload.username;
props.error = humanizeError(validation.error);
return reply.view("auth/forgot_password.js");
}
let user: PasswordResetUser;
try
{
user = await Users.get<PasswordResetUser>(payload.username.toLowerCase());
}
catch (e)
{
const error: pouch.api.PouchError = e;
if (error.status !== 404)
{
throw e;
}
// Do not inform the user that the username does not exist
return reply.redirect(Routes.GetResetSent);
}
const token = guid.v4();
//Save the token to the user
user.passwordResetToken = token;
user.passwordResetRequestedAt = new Date();
const update = await Users.put(user);
if (!update.ok)
{
console.error("Failed to save password reset data to user model.", update);
return reply(boom.expectationFailed("Failed to save password reset data."));
}
const url = `${getRequestDomain(request)}/${Routes.GetResetPassword}?token=${token}`.replace(/\/+/ig, "/");
const message = {
content: {
from: {
name: "Support",
email: `support@${config.EmailDomain.replace(/^.*@/ig, "")}`,
},
subject: `[${config.AppName}] Reset your password.`,
html: `<p>Hello,</p><p>You recently requested to reset your password for ${config.AppName}. Please click the link below to reset your password.</p><p><a href='${url}'>Click here to reset your password.</a></p><p>If you did not request a password reset, please ignore this email or reply to let us know. This password reset is only valid for the next 30 minutes.</p><p>Thanks, <br/> The ${config.AppName} Team</p>`
},
recipients: [{
address: {
email: payload.username,
}
}]
}
//Send the password reset email
const transporter = createTransport({ transport: 'sparkpost', sparkPostApiKey: config.SparkpostKey } as any);
transporter.sendMail(message, (error, info) =>
{
if (error)
{
return reply(boom.wrap(error));
}
return reply.redirect(Routes.GetResetSent);
});
}
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:80,代码来源:auth-routes.ts
示例8: postRegister
export async function postRegister(server: Server, request: Request, reply: IReply): Promise<any>
{
let payload = request.payload as {
username: string;
password: string;
};
let props: LoginProps = {
username: payload.username,
title: "Create an account"
};
let validation = joi.validate(payload, JoiValidation.register);
if (validation.error)
{
props.error = humanizeError(validation.error);
return reply.view("auth/register.js", props);
}
payload = validation.value;
let user: User;
//Check if a user with that name already exists
try
{
user = await Users.get<User>(payload.username.toLowerCase());
props.error = "A user with that username already exists.";
return reply.view("auth/register.js", props);
}
catch (e)
{
let error: pouch.api.PouchError = e;
if (error.status !== 404)
{
throw e;
}
}
user = {
_rev: undefined,
_id: payload.username.toLowerCase(),
username: payload.username,
hashedPassword: hashSync(payload.password, 10),
appConfig: {
label: {
text: "Pick your delivery date:",
textAlignment: "left",
placement: "top",
},
input: {
placeholder: "Click/tap to select",
},
placement: "right",
format: "mm/dd/yyyy",
addPickerToCheckout: false,
allowChangeFromCheckout: false,
maxDays: 7,
}
}
const create = await Users.put(user);
if (!create.ok)
{
return reply(boom.expectationFailed("Could not create new user."));
}
//Log the user in
await setUserAuth(request, user);
return reply.redirect("/setup");
}
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:75,代码来源:auth-routes.ts
示例9: getLogout
export async function getLogout(server: Server, request: Request, reply: IReply)
{
request.yar.clear(cookieName);
return reply.redirect("/auth/login");
}
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:6,代码来源:auth-routes.ts
注:本文中的hapi.IReply类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论