What does this mean? `No matching function [AUTH] ...
# box-products
o
What does this mean?
No matching function [AUTH] found
Copy code
try{
			auth.authenticate( auth().user().getEmail(), rc.password );
		} catch ( InvalidCredentials e ) {
			flash.put( "changepassword_form_errors", { "Change Password" : "Incorrect credentials" } );
			redirectBack();
		}
s
Presumably just what it says - you are calling
auth()
as a built-in function, which it isn't
o
I'm injecting auth as a dependency though
property name="auth" inject="AuthenticationService@cbauth";
s
then call
auth
not
auth()
s
^^^ yeah you're using it correctly as an object in the outer function, it's the inner
auth()
that's the problem
o
Sorry i'm new, why did i have to use it that way in my template but, not here?
s
with cbsecurity, a helper
auth()
is provided in views to access the auth module
in a handler or model, you need to inject the auth module so that you can access it
o
Ah that makes sense thanks. I'll let you know how it went
@Scott Steinbeck do i have to inject print too as a dependency?
s
print?
o
to print stuff for debugging purposes:
print("We authenticated successfully");
s
for coldfusion we use
writeoutput
or
writedump
for complex data
lucee also allows
echo
as an alias to
writeoutput
o
Where does writeOutput go to?
s
it outputs to the webpage
are you writing something for the console? or are you trying to send things to the trace logs?
o
Trying to see if something is happening or not
s
can you give a code snippet of what your trying to debug?
o
Basically I am trying to create a form for the user to change his password. Here is a sniplet of the handler code:
Copy code
try{
			auth.authenticate( email, rc.password );
			writeOutput("Ok");
            var user = getInstance( "User" ).update( { "password" : rc.newpassword } );
            writeOutput("Password Changed")
            auth.logout();
		    relocate( uri = "/" );
		} catch ( InvalidCredentials e ) {
			flash.put( "changepassword_form_errors", { "Change Password" : "Incorrect current password" } );
			redirectBack();
		}
s
ah, so you have a handler that is relocating after it writes to the page. try adding an
writeOutput("Password Changed");abort;
to see the message
abort will stop page execution, so you can see what is happening
o
Ok i managed to test what happens if the user enters the wrong current password. Issue now is why this line isn't firing:
flash.put( "changepassword_form_errors", { "Change Password" : "Incorrect current password" } );
Nevermind, I'm an idiot 😛
w
in a handler or model, you need to inject the auth module so that you can access it
Scott, you can also use auth() in handlers. There’s a difference between view helpers and global application helpers This function is registered as a global application helper, which means it will be available inside views, layouts AND handlers.