I have the running app which sends verification emails in case of email/account name creation but it does not send verification email if I login with google/facebook; it is probably due to email address which is in services.google.email; how can I set field 'to' in Accounts.emailTemplates if it does exist.
configureAccounts = function() {
setMailVerification(enableMailVerification);
};
setMailVerification = function() {
Accounts.emailTemplates.from = 'myEmail#.com';
Accounts.emailTemplates.verifyEmail = {
subject : function(user) {
return "Confirmation"
},
text : function(user, url) {
var greeting = (user.profile && user.profile.nick) ? ("Hello " + user.profile.nick + ",") : "Hello,";
return greeting +
"\n\n" + "Thank you for registration."+
"\n" + "To confirm click the following link:" + url +
"\n\n" + "thank you."
}
};
Accounts.config({
sendVerificationEmail : true,
forbidClientAccountCreation : false
});
};
please let me know if you where I should put ...services.google.email in case of google login and the same for facebook...
in other words how I can sent verification email to Meteor.user().services.google.email .. (even recalling sendUserVerificationEmail with that email does not work as it is not in 'emails')
I modified .email property onCreateUser as follows:
if(user.services != undefined) {
console.log('services in onCreateUser');
user.sentVerificationEmail = false;
user.emails =[];
var emailServices = user.services.google != undefined ?
user.services.google.email :
user.services.facebook.email;
user.emails.push({
address : emailServices,
verified : false
});
}
if (options.profile)
user.profile = options.profile;
return user;
I called then Accounts.sentVerificationEmail then onLogin .. and it worked;
thank you all for having a look
Related
I'm trying to remove an entry from my Firebase database, but am not able to delete it.
Here's my database structure:
Here's what I've tried:
let subRefs = firebase.database().ref('subscriptions/' + userId).once('value').then(function(snapshot){
let objs = snapshot.val();
for (let key in objs){
if (objs[key].uid == memberId){
console.log('found'); // I see this in the console
//remove the subscription
let ref = firebase.database().ref('subscription/' + userId + '/' + key);
ref.remove().then(function() {
console.log("Remove succeeded");
}).catch(function(error) {
console.log("Remove failed");
});
}
}
});
I've also tried the following approach as suggested here in the docs, but that didn't work either.
let update = {};
update['subscription/' + userId + '/' + key] = null;
firebase.database().ref().update(update).then(function(){
console.log('remove success');
}).catch(function(err){
console.log('remove failed');
});
In both cases, I see the "remove success" log, but when I check the database, it's not actually deleted.
I'm getting the error "SignUps Forbidden" when i try to create a user account. Any ideas why?
My packages:
useraccounts:materialize
materialize:materialize
accounts-password
accounts-facebook
service-configuration
accounts-google
accounts-twitter
kadira:blaze-layout
msavin:mongol
kadira:flow-router
kevohagan:sweetalert
Client Code:
Template.register.events({
'click #register-button': function(e, t) {
e.preventDefault();
// Retrieve the input field values
var email = $('#email').val(),
firstName = $('#first-name').val(),
lastName = $('#last-name').val(),
password = $('#password').val(),
passwordAgain = $('#password-again').val();
// Trim Helper
var trimInput = function(val) {
return val.replace(/^\s*|\s*$/g, "");
}
var email = trimInput(email);
// If validation passes, supply the appropriate fields to the
// Meteor.loginWithPassword() function.
Accounts.createUser({
email: email,
firstName: firstName,
lastName: lastName,
password: password
}, function(error) {
if (error) {
return swal({
title: error.reason,
text: "Please try again",
showConfirmButton: true,
type: "error"
});
} else {
FlowRouter.go('/');
}
});
return false;
}
});
Server code
Accounts.onCreateUser(function(options, user) {
user.profile = options.profile || {};
user.profile.firstName = options.firstName;
user.profile.lastName = options.lastName;
user.profile.organization = ["Org"];
user.roles = ["User"];
return user;
});
UPDATE:
Here is a link to the repo
The problem seems to be on .....meteor\local\build\programs\server\packages. If i switch the value to false it's useless because it resets on every build.
// Client side account creation is disabled by default:
// the methos ATCreateUserServer is used instead!
// to actually disable client side account creation use:
//
// AccountsTemplates.config({
// forbidClientAccountCreation: true
// });
Accounts.config({
forbidClientAccountCreation: true
});
I had to remove the useraccounts:materialize in order to solve this problem
I don't think that the current accepted answer is the right one.
If you want to keep your packages yet override the setting you can change the value of Accounts._options.forbidClientAccountCreation in your code.
Set it to true if you want to prevent the account creation, or to false otherwise.
I have tested my meteor app on dev and the verification email is sent out. But on production it is not. Could it maybe the content of smtp.js? My code is as follows:
// server/smtp.js
Meteor.startup(function () {
var smtp = {
username: 'dummy#wbs.co.za',
password: 'hw783378hjshd',
server: 'smtp.wbs.co.za',
port: 25
}
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password)
+ '#' + encodeURIComponent(smtp.server) + ':' + smtp.port;
});
// (server-side)
Meteor.startup(function() {
// 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.
Accounts.emailTemplates.from = 'NOREPLY <no-reply#meteor.com>';
// The public name of your application. Defaults to the DNS name of the application (eg: awesome.meteor.com).
Accounts.emailTemplates.siteName = 'No Reply';
// A Function that takes a user object and returns a String for the subject line of the email.
Accounts.emailTemplates.verifyEmail.subject = function(user) {
return 'Confirm Your Email Address';
};
// 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.verifyEmail.html = function(user, url) {
return 'click on the following link to verify your email address: ' + url;
};
});
// (server-side) called whenever a login is attempted
Accounts.validateLoginAttempt(function(attempt){
if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified ) {
console.log('email not verified');
throw new Meteor.Error(403, 'Verification email has been sent to your email address. Use the url in the email to verify yourself.');
return false; // the login is aborted
}
return true;
});
Please help.
I have set up a firebase simple login and its all working within my angular project. However for soem reason when ever I call the functions I have set up containing the login and createUser methods, they are called twice?
The controller is set up as follows:
angular.module('webApp')
.controller('AccountCtrl', function($scope, $window, $timeout) {
var ref = new Firebase('https://sizzling-fire-4246.firebaseio.com/');
and both methods are placed within my function straight from the firebase example on their website
When I press register, it will create the user and authenticate it, and then it will run again and tell me the email is taken.
I have checked with and without the timeouts and it still happens.
$scope.login = function(){
$scope.loginErrors = [];
$scope.loginSuccess = '';
var user = $scope.loginUser;
if(user.email === ''){
$scope.loginErrors.push('Please enter your email');
}
else if(user.password === ''){
$scope.loginErrors.push('Please enter your password');
}
else if(user.email === 'Admin'){
$window.location.href = '/#/admin';
} else {
ref.authWithPassword({
email : user.email,
password : user.password
}, function(error, authData) {
if (error) {
switch(error.code) {
case 'INVALID_EMAIL':
$scope.loginShow = true;
$timeout( function(){ $scope.loginMessage = 'Please enter a valid email address'; }, 500);
break;
case 'INVALID_USER':
$scope.loginShow = true;
$timeout( function(){ $scope.loginMessage = 'Please enter a valid user address'; }, 500);
break;
case 'INVALID_PASSWORD':
$scope.loginShow = true;
$timeout( function(){ $scope.loginMessage = 'Please enter the correct password'; }, 500);
break;
default:
console.log('error', error);
}
} else {
console.log('Authenticated successfully with payload:', authData);
$window.location.href = '/#/dashboard';
}
});
}
any help would be appreciated
I had a similar problem when developing and I had two browser tabs up running browser sync. Closed one and the problem went away.
This is works:
console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
but this one is not:
$scope.authenticated.currentUser = user.id;
My goal here is to take to take some of the authentication variables (Email+UserID) and then use them to access a profile node ON firebase. On initialization I want the username, email, and a few other things I need for the app.
crossfitApp.controller('globalIdCtrl', ["$scope",'defautProfileData','$q', function ($scope,defautProfileData,$q) {
var dataRef = new Firebase("https://glowing-fire-5401.firebaseIO.com");
$scope.authenticated={
currentUser: $scope.authemail,
emailAddress: "",
settings: "",
};
var chatRef = new Firebase('https://<YOUR-FIREBASE>.firebaseio.com');
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
if (error) {
// an error occurred while attempting login
switch(error.code) {
case 'INVALID_EMAIL':
case 'INVALID_PASSWORD':
default:
}
} else if (user) {
// user authenticated with Firebase
console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
$scope.authenticated.currentUser = user.id ;//
} else {
// user is logged out
}
});
}]); //GlobaldCtrl
Most likely, you're running into a problem with Angular's HTML Compiler.
Whenever you use an event like ng-click/ng-submit/etc, Angular fires $scope.$apply(), which checks for any changes to your $scope variables and applies them to the DOM.
Since FirebaseSimpleLogin is not part of Angular's purview, it has no idea that when the callback is fired, you've updated $scope.authenticated.currentUser. This would also explain why it works when you call auth.login(), since you're probably invoking that via an ng-click event somewhere, which would fire a digest check and discover the changes.
If this is indeed the case, you can correct this issue by alerting Angular that it needs to run $apply by using $timeout:
crossfitApp.controller('globalIdCtrl', ["$scope",'defautProfileData','$q', '$timeout', function ($scope,defautProfileData,$q, $timeout) {
/* ... */
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
if (error) {
/* ... */
} else if (user) {
$timeout(function() {
$scope.authenticated.currentUser = user.id ;//
});
} else {
// user is logged out
}
});