2
A
回答
1
您可以使用下面的代碼:
設置一個firstLogin
標誌上創建
Accounts.onCreateUser(function(options, user) {
user.firstLogin = true;
return user;
});
方法來更新標誌
Meteor.methods({
updateUserFirstLogin: function(userId) {
Meteor.users.update({
_id: userId
}, {
$set: {
'firstLogin': false
}
});
}
});
檢查,如果用戶在登錄一個新
Accounts.validateLoginAttempt(function(attemptInfo) {
if (!attemptInfo.user) {
return false;
}
if (!attemptInfo.user.firstLogin) {
return true;
} else {
Meteor.call('updateUserFirstLogin', attemptInfo.user._id);
return false;
}
});
8
這是通過電子郵件登錄一個簡單的解決方案,它將解除用戶創建後autologins直到電子郵件地址驗證拒絕後登錄:
if (Meteor.isServer) {
Accounts.validateLoginAttempt(function(attemptInfo) {
if (attemptInfo.type == 'resume') return true;
if (attemptInfo.methodName == 'createUser') return false;
if (attemptInfo.methodName == 'login' && attemptInfo.allowed) {
var verified = false;
var email = attemptInfo.methodArguments[0].user.email;
attemptInfo.user.emails.forEach(function(value, index) {
if (email == value.address && value.verified) verified = true;
});
if (!verified) throw new Meteor.Error(403, 'Verify Email first!');
}
return true;
});
}
+0
問題在於,代碼不會創建用戶。因爲這個validateLoginAttemp()以某種方式在createUser()之前運行。當它在第二秒返回false時,流星不會註冊新用戶,既不發送電子郵件確認。 – 2017-10-27 16:44:05
0
我發現了一個更簡單的方法:
Accounts.validateLoginAttempt((data) => {
let diff = new Date() - new Date(data.user.createdAt);
if (diff < 2000) {
console.info('New user created -- denying autologin.');
return false;
} else {
return true;
}
});
這看到用戶剛剛創建,因此不會登錄。
相關問題
- 1. 註冊後自動創建用戶
- 2. 註冊後註冊用戶
- 3. 創建註冊註冊 - 新手用戶
- 4. 流星:註冊用戶,然後自動登錄
- 5. 註冊頁面沒有註冊用戶
- 6. 如何在用戶註冊後動態創建用戶頁面
- 7. SEAN.js註冊後自動註冊和req.user.roles
- 8. 禁用流星註冊
- 9. 流星autoform用戶註冊和登錄
- 10. 註冊後創建匿名用戶cookie
- 11. 如何創建用戶註冊頁面
- 12. 註冊後的用戶流程
- 13. 如何註冊流星SpaceBars助手?
- 14. 如何在liferay註冊portlet的幫助下創建用戶註冊
- 15. 如何在Parse.com上創建帳戶?沒有註冊按鈕?
- 16. 註冊用戶和未註冊用戶
- 17. DLL自注冊:如何爲當前用戶註冊?
- 18. 註冊後自動登錄
- 19. 註冊後自動登錄
- 20. 註冊後自動登錄
- 21. 註冊後自動登錄
- 22. 用PHP註冊MySQL的用戶註冊
- 23. 用戶註冊(註冊)的Wordpress REST API
- 24. Django註冊自動創建UserProfile
- 25. 如何限制註冊並在設計中創建自己的註冊?
- 26. 當新用戶註冊時,自動創建DISQUS帳戶
- 27. 註冊表項沒有被創建
- 28. 如何在註冊後自動登錄用戶
- 29. 在cakephp中自動註冊用戶
- 30. 如何讓註冊用戶使用Devise註冊其他用戶?
可能重複[如何防止創建用戶後自動登錄](http://stackoverflow.com/questions/17360037/how-to-prevent-auto-login-after-create-user) – 2014-09-03 10:57:29
是的,它是重複的。對不起,我在創建之前還沒有找到它。謝謝! – skozz 2014-09-03 11:03:58