views:

140

answers:

2

I'm trying to learn the new cfscript syntax, as well as use cflogin. I'm guessing I can't mix cf tags in cfscript, and I don't see a script equivalent to cflogin, cflogout, cfloginuser.

Should I call a component that is written in the CF8 syntax in order to use cflogin?

public void function onRequest(required string Page) output="true" {
if (StructKeyExists(url,"logout")) {
 <cflogout>
}
<cflogin>
 local.qryUsr = new Components.Usr.Login(form);
 if (local.qryUsr.Recordcount) {
  <cfloginuser name="#form.UsrName#" password="#form.UsrPassword#" roles="#local.qryUsr.Roles#">
 } else {
  request.errorMessage = "Incorrect login";
  include login/login.cfm;
  return;
 }
</cflogin>
include arguments.Page;
}
+7  A: 

You cannot directly mix tags and scripts. However, you can fake it by writing function wrappers around the tags:

<cffunction name="logout">
   <cflogout />
</cffunction>

and call like:

logout();

Obviously, this is a trivial example. You'd want to specify your arguments, your return value, etc. in your actual code.

Note one: Do not do this for a generic query function that accepts user input, as you won't be able to use cfqueryparam.

Note two: I generally don't do this. If I'm writing code that depends on tag-only operations, I use the tag syntax.

Ben Doom
Oh, ok. Thanks!I guess I'll forgo using cflogin (still) and simply use a session variable to see if they're logged in.
cf_PhillipSenn
You can rewrite these and put them in a library, or use the library(ies) from cflib.org, and simply include them. Then, you can call them wherever. That would let you use cflogin if that is your specific goal.
Ben Doom
A: 

as a side note, there is a small effort going on over at CFLib.org to create functions for all CF Tags. check out CFMLLib for more details

LucasS
cflib.org is interesting.Any time I can view source code, I appreciate it!I suppose a <cflogin> would have to be written as a custom tag.
cf_PhillipSenn
Phillip -- these are rewritten as functions, which are not the same as custom tags.
Ben Doom
Right. I guess I thought 'custom tag' because cflogin has an opening and closing tag.
cf_PhillipSenn