काम नहीं कर रही है इसलिए मैं पासपोर्ट-स्थानीय का उपयोग कर रहा हूं और उपयोगकर्ता लॉग-इन को संभालने के लिए व्यक्त कर रहा हूं। अब तक मैं उपयोगकर्ता नामों का उपयोग करते समय एक सफल लॉग-इन प्राप्त करने में सक्षम हूं, लेकिन उपयोगकर्ता नाम याद रखना मुश्किल है और मैं व्यक्तिगत रूप से नहीं सोचता कि उन्हें उपयोगकर्ताओं को संभालने के लिए उपयोग किया जाना चाहिए, इसलिए मैंने पासपोर्ट पर प्रदान की गई नमूना रणनीति को संशोधित करने का प्रयास किया- ईमेल के माध्यम से उपयोगकर्ताओं की पुष्टि करने के लिए स्थानीय पृष्ठ, लेकिन कोड काम नहीं करता है।पासपोर्ट-स्थानीय के साथ ईमेल का उपयोग करें। पिछली मदद
रणनीति मैं ईमेल के लिए है:
passport.use(new LocalStrategy(function(email, password, done) {
User.findOne({ email: email }, {}, function(err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false, { message: 'Unknown user ' + e }); }
user.comparePassword(password, function(err, isMatch) {
if (err) return done(err);
if(isMatch) {
return done(null, user);
} else {
return done(null, false, { message: 'Invalid password' });
}
});
});
}));
और यह इस रणनीति से ली गई है:
//The login strategy
passport.use(new LocalStrategy(function(username, password, done) {
User.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false, { message: 'Unknown user ' + username }); }
user.comparePassword(password, function(err, isMatch) {
if (err) return done(err);
if(isMatch) {
return done(null, user);
} else {
return done(null, false, { message: 'Invalid password' });
}
});
});
}));
तो उपयोगकर्ता नाम रणनीति काम करता है बिल्कुल ठीक है, लेकिन ईमेल एक नहीं है। मैंने यह देखने के लिए कि क्या रणनीतियां वापस आ रही हैं, दोनों उपयोगकर्ता नाम और ईमेल रणनीति में एक console.log() भी छोड़ा। प्रयोक्ता नाम रणनीति उपयोगकर्ता पर सभी जानकारी देता है, ईमेल रणनीति देता है, जबकि
झूठी
। मुझे नहीं पता कि साइट यह क्यों कर रही है, और मैंने अभी तक कोई भी समाधान नहीं देखा है।
एक समाधान मैं एक पोस्ट पर देखा है सुझाव दिया है कि मैं सिर्फ ईमेल के साथ प्रवेश करने के लिए उपयोगकर्ता को खोजने के लिए
findOne({email: email}, function(err, user){
});
विकल्प का उपयोग, लेकिन यह बिल्कुल भी नहीं काम कर रहा है। यहाँ
extends layout
block content
h1 Login
form(action= '/login', method='post')
p Email
br
input#email(type='text',value='',placeholder='@',name='email')
p Password
br
input#password(type='password',value='',placeholder='Password',name='password')
input(type='submit') Submit
और बाद इनपुट है:
यहाँ जेड फ़ाइल मैं उपयोगकर्ता से इनपुट लेने के लिए इस्तेमाल करते हैं
// POST /login
// This is an alternative implementation that uses a custom callback to
// acheive the same functionality.
exports.postlogin = function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
if (err) { return next(err) }
if (!user) {
req.session.messages = [info.message];
return res.redirect('/login')
}
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.redirect('/');
});
})(req, res, next);
};
क्या बिल्ली यहाँ चल रहा है? ईमेल के साथ यह पूरी तरह से काम करना चाहिए। चूंकि मैं एक सवाल पूछ रहा हूं, फिर भी किसी ने पंजीकरण के बाद ईमेल की पुष्टि कैसे की?
मैं स्टैक ओवरफ्लो में जादू का कसम खाता हूं।सबसे लंबे समय तक मैंने इस मुद्दे के साथ काम करने की कोशिश की है। मैंने आपके द्वारा पहले पोस्ट किए गए उदाहरण की भी कोशिश की, अब तक कुछ भी काम नहीं किया। आपका बहुत बहुत धन्यवाद! – Kivo360
'पासवर्ड फ़ील्ड 'पासवर्ड' आईएमओ होना चाहिए –