本文整理汇总了TypeScript中hapi.IReply.view方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IReply.view方法的具体用法?TypeScript IReply.view怎么用?TypeScript IReply.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.IReply
的用法示例。
在下文中一共展示了IReply.view方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setup
export async function setup(server: Server, request: Request, reply: IReply)
{
let payload = request.payload as {shopUrl: string};
const props: SetupProps = {
title: "Connect your Shopify store.",
shopUrl: payload.shopUrl,
};
const validation = joi.validate(payload, setupValidation);
if (validation.error)
{
props.error = humanizeError(validation.error);
return reply.view("setup/setup.js", props);
}
payload = validation.value;
if (! (await isValidShopifyDomain(payload.shopUrl)))
{
props.error = "It looks like the URL you entered is not a valid Shopify domain.";
return reply.view("setup/setup.js", props);
}
const scopes: Enums.AuthScope[] = ["write_script_tags"]
const redirect = `${getRequestProtocol(request)}://${getDomain(true)}${ConnectRoutes.GetShopify}`.toLowerCase();
const oauthUrl = await buildAuthorizationUrl(scopes, payload.shopUrl, ShopifyApiKey, redirect);
return reply.redirect(oauthUrl);
}
示例2: postLogin
export async function postLogin(server: Server, request: Request, reply: IReply)
{
const validation = joi.validate<{username: string; password: string}>(request.payload, JoiValidation.login);
const payload = validation.value;
const props: LoginProps = {
username: payload.username,
title: "Sign in to your account.",
};
if (validation.error)
{
props.error = humanizeError(validation.error);
return reply.view("auth/login.js", props);
}
let user: User;
let passwordMatches = false;
try
{
user = await Users.get<User>(payload.username.toLowerCase());
if (user)
{
//Check if password matches the one stored in the database
passwordMatches = compareSync(payload.password, user.hashedPassword);
}
}
catch (e)
{
let error: pouch.api.PouchError = e;
if (error.status !== 404)
{
throw e;
}
}
if (!user || !passwordMatches)
{
props.error = "Username or password is incorrect."
return reply.view("auth/login.js", props);
}
//Successful login
await setUserAuth(request, user);
return reply.redirect("/");
}
示例3: postResetPassword
export async function postResetPassword(server: Server, request: Request, reply: IReply): Promise<IBoom | Response>
{
const payload: {password: string, token: string, confirmPassword: string} = request.payload;
const validation = joi.validate(payload, JoiValidation.resetPassword);
const props: ResetPasswordProps = {
title: "Reset your password.",
token: payload.token,
}
if (validation.error)
{
props.error = humanizeError(validation.error);
return reply.view("auth/reset_password.js", props);
}
if (payload.confirmPassword !== payload.password)
{
props.error = "Passwords do not match.";
return reply.view("auth/reset_password.js", props);
}
// Ensure the user's password token is still valid
const user = await findUserByPasswordResetToken(payload.token);
if (!user || user.passwordResetToken !== payload.token || new Date(user.passwordResetRequestedAt as string) < new Date(new Date().getTime() - (30 * 60 * 1000) /* 30 minutes */))
{
props.error = "Your password reset request has expired.";
return reply.view("auth/reset_password.js", props);
}
// Reset user's password
user.passwordResetToken = undefined;
user.passwordResetRequestedAt = undefined;
user.hashedPassword = hashSync(payload.password, 10);
const update = await Users.put(user);
if (!update.ok)
{
console.error("Failed to save user's new password during password reset request.", update);
return reply(boom.expectationFailed("Failed to save user's new password during password reset request."));
}
return reply.redirect(Routes.GetLogin);
}
示例4: getLogin
export async function getLogin(server: Server, request: Request, reply: IReply)
{
const props: LoginProps = {
title: "Sign in to your account."
}
return reply.view("auth/login.js", props);
}
示例5: getResetSent
export async function getResetSent(server: Server, request: Request, reply: IReply)
{
const props: ResetSentProps = {
title: "Password reset request sent.",
}
return reply.view("auth/reset_sent.js", props);
}
示例6: getSettings
export async function getSettings(server: Server, request: Request, reply: IReply)
{
const props: SettingsProps = {
title: "Account Settings.",
}
return reply.view("account/settings.js", props);
}
示例7: getForgotPassword
export async function getForgotPassword(server: Server, request: Request, reply: IReply)
{
const props: ForgotPasswordProps = {
title: "Forgot your password?",
};
return reply.view("auth/forgot_password.js", props);
}
示例8: getSetupForm
export async function getSetupForm(server: Server, request: Request, reply: IReply)
{
const props: SetupProps = {
title: "Connect your Shopify store.",
};
return reply.view("setup/setup.js", props);
}
示例9: getRegister
export async function getRegister(server: Server, request: Request, reply: IReply)
{
const props: RegisterProps = {
title: "Create an account."
}
return reply.view("auth/register.js", props);
}
示例10: view
function view(error: string, success?: boolean)
{
const props: SettingsProps = {
title: "Account Settings.",
success: !!success,
}
return reply.view("account/settings.js", props);
}