本文整理汇总了TypeScript中meteor/accounts-base.Accounts.validateLoginAttempt方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Accounts.validateLoginAttempt方法的具体用法?TypeScript Accounts.validateLoginAttempt怎么用?TypeScript Accounts.validateLoginAttempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meteor/accounts-base.Accounts
的用法示例。
在下文中一共展示了Accounts.validateLoginAttempt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
return "<h1>Some html here</h1>";
};
Accounts.emailTemplates.enrollAccount.from = function () {
return "asdf@asdf.com";
};
Accounts.emailTemplates.enrollAccount.text = function (user: Meteor.User, url: string) {
return "You have been selected to participate in building a better future!"
+ " To activate your account, simply click the link below:\n\n"
+ url;
};
var handle = Accounts.validateLoginAttempt(function (attemptInfoObject: Accounts.IValidateLoginAttemptCbOpts) {
var type: string = attemptInfoObject.type;
var allowed: boolean = attemptInfoObject.allowed;
var error: Meteor.Error = attemptInfoObject.error;
var user: Meteor.User = attemptInfoObject.user;
var connection: Meteor.Connection = attemptInfoObject.connection;
var methodName: string = attemptInfoObject.methodName;
var methodArguments: any[] = attemptInfoObject.methodArguments;
return true;
});
handle.stop();
// Covers https://github.com/meteor-typings/meteor/issues/8
const publicSetting = Meteor.settings.public['somePublicSetting'];
const deeperPublicSetting = Meteor.settings.public['somePublicSetting']['deeperSetting'];
const privateSetting = Meteor.settings['somePrivateSetting'];
const deeperPrivateSetting = Meteor.settings['somePrivateSettings']['deeperSetting'];
// Covers https://github.com/meteor-typings/meteor/issues/9
示例2: function
export default function() {
Meteor.methods({
sendVerification: function(email: string) {
check(email, String);
let user = Meteor.users.findOne({
"emails.address": email
});
if (!user) {
throw new Meteor.Error(403, "User not found");
}
if (user.emails[0].verified) {
throw new Meteor.Error(403, "User already verified");
}
console.log("Sending verification email to: " + user.emails[0].address);
return Accounts.sendVerificationEmail(user._id);
},
addUser: function(data: any) {
check(data, {
email: String,
password: String,
profile: Match.Any
});
// TODO: Roles
let userId = Accounts.createUser({
email: data.email,
password: data.password,
profile: data.profile
});
if (!userId) {
throw new Error("createUser failed to insert new user");
}
// If `Accounts._options.sendVerificationEmail` is set, register
// a token to verify the user"s primary email, and send it to
// that address.
Accounts.sendVerificationEmail(userId);
}
});
// configs
// By default, the email is sent from no-reply@meteor.com. If you wish to receive email from users asking for
// help with their account, be sure to set this to an email address that you can receive email at.
const config = {
siteName: "Boilerplate",
from: "tomi.trescak@gmail.com",
accounts: {
subject: "Please verify your email",
body: `Hello \${user},<br />
<br />
To verify your account email, simply click the link below.<br />
<br />
<a href="\${url}">\${url}</a><br />
<br />
Truly yours,<br />
Site Admin`
}
};
Accounts.emailTemplates.from = config.from;
// The public name of your application. Defaults to the DNS name of the application (eg: awesome.meteor.com).
Accounts.emailTemplates.siteName = config.siteName;
// A Function that takes a user object and returns a String for the subject line of the email.
Accounts.emailTemplates.enrollAccount.subject =
Accounts.emailTemplates.verifyEmail.subject = function(user: Meteor.User): string {
return config.accounts.subject
.replace("${user}", user.profile.name)
.replace("${siteName}", Accounts.emailTemplates.siteName);
};
// A Function that takes a user object and a url, and returns the body text for the email.
// Note: if you need to return HTML instead, use Accounts.emailTemplates.verifyEmail.html
Accounts.emailTemplates.enrollAccount.html =
Accounts.emailTemplates.verifyEmail.html = function(user: Meteor.User, url: string): string {
return config.accounts.body
.replace("${siteName}", Accounts.emailTemplates.siteName)
.replace(/\$\{url\}/g, url)
.replace(/\$\{user\}/g, user.profile.name);
};
Accounts.config({
sendVerificationEmail: true,
// restrictCreationByEmailDomain: function(email: string) {
// let domain = email.slice(email.lastIndexOf("@") + 1); // or regex
// let exists = Sites.findOne({ accounts: domain });
// return exists;
// },
forbidClientAccountCreation: true
});
Accounts.validateLoginAttempt(function(attempt: any) {
if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified) {
return false; // the login is aborted
}
//.........这里部分代码省略.........