I'm trying to authenticate a user with a custom login form. I designed the form, and I'm trying to authenticate users like this:
Template['account.login'].events
'submit #login-form': (e, t) ->
e.preventDefault()
Meteor.loginWithPassword(
t.find('#login_username').value,
t.find('#login_password').value,
(err)->
console.log(err)
)
return false
Relevant Template(in JADE - sorry):
form.smart-form.client-form#login-form(novalidate)
fieldset
section
label.input
input#login_username(type="text", name="username")
section
label.input
input#login_password(type="password", name="password")
footer
button.btn.btn-primary(type="submit", id="login.btn.login") Login
From the resource I found online, this would be correct. However, I get this exception thrown on the server:
Exception while invoking method 'login' Error: Match error: Failed Match.Where validation in field username in field user.username
You forgot to add a tab and Meteor.loginWithPassword() is running outside the Template event. Paste your coffeescript code at http://js2.coffee/ and you'll see it right away.
Related
I have a problem with the server-side error management on Google App Maker.
Here an exemple of my code
Server-side
function serverSideFn() {
// Consider the error to be throw.
if ( anError ) {
throw new Error("A specific error message");
}
}
Client-side
function clientSideFn() {
google.script.run
.withSuccessHandler(function(result) {
// Success code...
})
.withFailureHandler(function(error) {
console.log(error.message); // The message error here is not the same if I have or not the Admin role.
showErrorPopup(error.message);
})
.serverSideFn();
}
When I execute the "clientSideFn" function with default role Admin, I have the good message ("A specific error message"), but if I don't have the Admin role, I have a "Server Error" message instead of the expected.
I've tried to use the developer account option, and set Admin role to this account and execute the server side scripts, but the error is still present for users without Admin role.
I've also tried to throw a custom Exception, but the error is still changed on client side.
What I can change to got the expected message when the user don't have the Admin role ?
The relevant documentation to your question is located here https://developers.google.com/appmaker/scripting/api/server. The basics is that you use:
throw new app.ManagedError('Your custom message here');
I'm setting up Ninja Forms in Wordpress. And I want to use the Webhooks extension to post a code to an external URL. If the code is correct Ninja Forms should submit the data on move on. If the code is wrong then the user should get an error message and try again.
How can I do this, I see no way if interrupting the submit?
In Ninja Form when you use webhook, I guess you may catch the error respond from the API with this code
$data['errors']['form'][] = $this->submit_response->result[0]->error;
So when the API respond error, in this case user has no chance to re-submit the form again unless reload the page.
When the form contain the error, Ninja form prevent the form to submit, so you need to find a way to clear/remove this error.
Few workarounds can fix this problem.
An easy way is that, you cache the respond error differently with the following code:
$data['errors']['last']['message'] = $this->submit_response->result[0]->error;
With this code, your form will not display the error message respond from API but it is possible for user to re-submit the form again and you can use the javascript code below to display the error to some HTML element
var customFormController = Marionette.Object.extend({
initialize: function() {
// Listen to submit respond
this.listenTo(nfRadio.channel( 'forms' ), 'submit:response', this.checkSubmitRespond);
},
checkSubmitRespond: function(response, textStatus, jqXHR, formID) {
if ('undefined' != typeof response.errors.last) {
var msg = response.errors.last.message;
// display error on some pre-defined element
jQuery('.error-container').html(msg);
}
}
});
jQuery(document).ready(function($) {
new customFormController();
});
Hope this help.
This Meteor app has the insecure and autopublish removed and accounts-ui accounts-password added.
The code below needs to get the username and password, send them the to server which will run a method validateUser that returns true if valid.
validateUser tries to login to another server on the web, and returns true if successful, then my code should create a user account for this user.
The app is crashing because of this line
Accounts.createUser(useername: digest[0], password: digest[1]);
But even if it does not, Is this the meteor way to get this particular task done? Thanks
Edit:
After adding {} to the problem line in order to pass an object as suggested in the comments, I now get this error printed in the terminal;
Exception while invoking method 'logMeIn' Error: Match error: Failed Match.OneOf or Match.Optional validation in field password
<template name="myLogin">
<input type="text" name="username">
<input type="text" name="password">
<button id="logMe">log me in</button>
</template>
Template.myLogin.events({
'click #logMe': function() {
var credentials = [$('#password').val(), $('#username').val()];
Meteor.call('logMeIn', credentials, function(err, result) {
if (result) {
console.log('logged in!');
}
});
}
});
// on the server
Meteor.methods({
logMeIn: function(credenticals) {
//do work , if logged in, do next line
console.log("user account created");
Accounts.createUser({useername: credenticals[0], password: credenticals[1]});
}
});
Match error: Failed Match.OneOf - is because this method checks if email or username is presented in the object you are passing. You have typo in username and don't have email.
Next thing you are saying, after fixing typo you get Exception while invoking method 'logMeIn' Error: Match error: Expected string, got object in field username
This is because you have array with two undefined "members". Look at your jquery selectors. You are trying to select by id # but have inputs without ids.
Please organise yourself.
Your line
Accounts.createUser({useername: credenticals[0], password: credenticals[1]});
Has two typos, it should be
Accounts.createUser({username: credentials[0], password: credentials[1]});
I want to be able to resend an email verification link to users of my Meteor application in case they accidentally delete their email verification email.
I have a link with the id "resentEmailVerificationLink"
I have the following code in my client for when the link is click (alerts are just there to show myself how far the function gets before an error):
Template.dashboard.events({
'click #resentEmailVerificationLink' : function(event) {
event.preventDefault();
var id = Meteor.userId();
alert('clicked: ' + id);
Accounts.sendVerificationEmail(id);
alert('Verification Email resent');
return false; // Stops page from reloading
}
)};
I know the sendVerificationEmail is a server function but I have no idea how to call this function in the server upon clicking the verify email link (I'm a bit of a Meteor newbie).
Any idea of how to accomplish this, because currently it doesn't work with the following error: Uncaught TypeError: Accounts.sendVerificationEmail is not a function
Note: Meteor.Accounts.sendVerificationEmail(id); doesn't work either (it does however produce a different error.
You can try with server side method just create one pass the attrs and call http://docs.meteor.com/#/full/accounts_sendverificationemail on the server. More about meteor methods: http://docs.meteor.com/#/full/meteor_methods
I'm trying to get have users be able to post to their Facebook walls on my external site.
I've encountered a problem in Safari. If the user isn't logged in, i.e. they have not gone through the flow that calls FB.login(), I get the following JS error when calling FB.ui():
TypeError: 'undefined' is not an object (evaluating 'b.fbCallID=a.id')
However, if they are logged in, the dialog appears just fine.
FB.ui() is called in a callback function -- I'm retrieving a unique url from my server, and then calling FB.ui(). If I call FB.ui() directly, it works fine, but not when it's asynchronous.
Here's the code:
retrieveUrl(param1, param2, function(result) {
FB.ui({ method: 'feed',
description: 'My Description',
display: 'dialog',
link: result.uniqueUrl,
picture: 'http://foo.com/bar.jpg'
}, function(response) {
if (response && response.post_id) {
//Posted message
} else {
//Not posted message
}
});
});
This works in other browsers, regardless of logged in state or not.
FB.login or FB.ui methods must be called on a user initiated action (click) in Safari for new window/popup/iframe to be rendered by FB.UIServer.
If you try calling these methods on a network callback event it will be blocked and the exception you described will occur:
TypeError: 'undefined' is not an object (evaluating 'b.fbCallID=a.id')
Can you retrieve the unique URL before the user interacts with the page and then present the feed dialog when they click on a button?