Skip to content

Commit

Permalink
Merge branch 'develop' into qBallExample
Browse files Browse the repository at this point in the history
  • Loading branch information
jphustman committed May 19, 2014
2 parents 0027c18 + 0b1e5d9 commit d68e674
Show file tree
Hide file tree
Showing 29 changed files with 635 additions and 1,166 deletions.
2 changes: 1 addition & 1 deletion Application.cfc
Expand Up @@ -5,7 +5,7 @@ component extends="org.corfield.framework" {
// FW/1 - configuration for introduction application:
// controllers/layouts/services/views are in this folder (allowing for non-empty context root):
variables.framework = {
base = getDirectoryFromPath( CGI.SCRIPT_NAME ).replace( getContextRoot(), '' ) & 'introduction',
base = getDirectoryFromPath( CGI.SCRIPT_NAME ).replaceFirst( getContextRoot(), '' ) & 'introduction',
unhandledPaths = "/mxunit"
};

Expand Down
Binary file modified docs/fw1.pdf
Binary file not shown.
14 changes: 5 additions & 9 deletions examples/Application.cfc
Expand Up @@ -7,18 +7,14 @@ component extends="org.corfield.framework" {
variables.framework = {
usingSubsystems = true,
SESOmitIndex = true,
trace = true,
// this example uses the deprecated service() call
// this example uses the deprecated start/end actions
suppressServiceQueue = false
trace = true
};

// pull in bean factory for hello8:
// pull in bean factory for each subsystem:
public void function setupSubsystem( string subsystem ) {
if ( subsystem == "hello8" ) {
var bf = new framework.ioc( "./hello8" );
setSubsystemBeanFactory( subsystem, bf );
}
var bf = new framework.ioc( "./" & subsystem );
bf.addBean( "fw", this ); // so controllers can be init'd with fw
setSubsystemBeanFactory( subsystem, bf );
}

}
2 changes: 1 addition & 1 deletion examples/hello5/Application.cfc
@@ -1,7 +1,7 @@
component extends="org.corfield.framework" {

// setting framework.base so the application will work when there is a non-empty context root:
variables.root = getDirectoryFromPath( CGI.SCRIPT_NAME ).replace( getContextRoot(), '' );
variables.root = getDirectoryFromPath( CGI.SCRIPT_NAME ).replaceFirst( getContextRoot(), '' );
variables.framework = {
base = variables.root & 'cfml',
cfcbase = replace( right( variables.root, len( variables.root ) - 1 ), '/', '.', 'all' ) & 'cfcs'
Expand Down
4 changes: 2 additions & 2 deletions examples/hello8/controllers/main.cfc
@@ -1,11 +1,11 @@
component accessors="true" {

property framework;
property framework; // alternative way to depend on FW/1"
property mainService;

public void function default( rc ) {
param name="rc.name" default="anonymous";
rc.data = variables.mainService.default( rc.name );
rc.captured = variables.framework.view( "main/capture" );
}
}
}
4 changes: 2 additions & 2 deletions examples/litepost/fw1/Application.cfc
@@ -1,4 +1,4 @@
<cfcomponent extends="org.corfield.framework" output="false"><cfscript>
component extends="org.corfield.framework" {

this.name = 'fw1litepost';
this.sessionmanagement = true;
Expand Down Expand Up @@ -34,4 +34,4 @@

}

</cfscript></cfcomponent>
}
4 changes: 2 additions & 2 deletions examples/litepost/fw1/controllers/blog.cfc
@@ -1,4 +1,4 @@
<cfcomponent><cfscript>
component {

// constructor - access to FW/1 API:
function init(fw) {
Expand Down Expand Up @@ -295,4 +295,4 @@
variables.userService = userService;
}

</cfscript></cfcomponent>
}
7 changes: 2 additions & 5 deletions examples/userManagerAccessControl/Application.cfc
Expand Up @@ -7,16 +7,13 @@ component extends="org.corfield.framework" {

// FW/1 - configuration:
variables.framework = {
suppressImplicitService = false,
// this example uses the deprecated service() call
// this example uses the deprecated start/end actions
suppressServiceQueue = false
trace = true
};

function setupApplication()
{
application.adminEmail = 'admin@mysite.com';
setBeanFactory(createObject("component", "model.ObjectFactory").init(expandPath("./assets/config/beans.xml.cfm")));
setBeanFactory( new framework.ioc( 'model' ) );
}

function setupSession() {
Expand Down
115 changes: 48 additions & 67 deletions examples/userManagerAccessControl/controllers/login.cfc
@@ -1,67 +1,48 @@
<cfcomponent>
<cfset variables.fw = '' />
<cffunction name="init" access="public" returntype="void">
<cfargument name="fw" type="any" required="yes" />
<cfset variables.fw = arguments.fw />
</cffunction>

<cffunction name="setUserService" access="public" output="false" returntype="void">
<cfargument name="userService" type="any" required="true" />
<cfset variables.userService = arguments.userService />
</cffunction>
<cffunction name="getUserService" access="public" output="false" returntype="any">
<cfreturn variables.userService />
</cffunction>

<cffunction name="before" access="public" output="no" returntype="void">
<cfargument name="rc" type="struct" required="yes" />
<cfif session.auth.isLoggedIn and variables.fw.getItem() is not 'logout'>
<cfset variables.fw.redirect('main') />
</cfif>
</cffunction>

<cffunction name="login" access="public" returntype="void">
<cfargument name="rc" type="struct" required="yes" />

<cfset var userValid = 0 />
<cfset var userService = getUserService() />
<cfset var user = '' />

<!--- if the form variables do not exist, redirect to the login form --->
<cfif not structkeyexists(rc,'email') or not structkeyexists(rc,'password')>
<cfset variables.fw.redirect('login') />
</cfif>

<!--- look up the user's record by the email address --->
<cfset user = userService.getByEmail(rc.email) />

<!--- if the user object contains a record then the username was legit, lets look at the passwords --->
<cfif user.getId()>
<cfset userValid = userService.validatePassword(user,rc.password) />
</cfif>

<!--- if the login credentials failed the test, set a message and redirect to the login form --->
<cfif not userValid>
<cfset rc.message = ['Invalid Username or Password'] />
<cfset variables.fw.redirect('login','message') />
</cfif>

<!--- since the user is valid, set session variables --->
<cfset session.auth.isLoggedIn = true />
<cfset session.auth.fullname = user.getFirstName() & ' ' & user.getLastName() />
<cfset session.auth.user = user />

<cfset variables.fw.redirect('main') />
</cffunction>

<cffunction name="logout" access="public" returntype="void">
<cfargument name="rc" type="struct" required="yes" />
<!--- reset the session variables --->
<cfset session.auth.isLoggedIn = false />
<cfset session.auth.fullname = 'Guest' />
<cfset structdelete(session.auth,'user') />
<cfset rc.message = ['You have safely logged out'] />
<cfset variables.fw.redirect('login','message') />
</cffunction>

</cfcomponent>
component accessors=true {

property userService;

function init( fw ) {
variables.fw = fw;
return this;
}

function before( rc ) {
if ( structKeyExists( session, "auth" ) && session.auth.isLoggedIn &&
variables.fw.getItem() != "logout" ) {
variables.fw.redirect( "main" );
}
}

function login( rc ) {
// if the form variables do not exist, redirect to the login form
if ( !structKeyExists( rc, "email" ) || !structKeyExists( rc, "password" ) ) {
variables.fw.redirect( "login" );
}
// look up the user's record by the email address
var user = variables.userService.getByEmail( rc.email );
// if that's a real user, verify their password is also correct
var userValid = user.getId() ? variables.userService.validatePassword( user, rc.password ) : false;
// on invalid credentials, redisplay the login form
if ( !userValid ) {
rc.message = ["Invalid Username or Password"];
variables.fw.redirect( "login", "message" );
}
// set session variables from valid user
session.auth.isLoggedIn = true;
session.auth.fullname = user.getFirstName() & " " & user.getLastName();
session.auth.user = user;

variables.fw.redirect( "main" );
}

function logout( rc ) {
// reset session variables
session.auth.isLoggedIn = false;
session.auth.fullname = "Guest";
structdelete( session.auth, "user" );
rc.message = ["You have safely logged out"];
variables.fw.redirect( "login", "message" );
}

}
78 changes: 30 additions & 48 deletions examples/userManagerAccessControl/controllers/main.cfc
@@ -1,48 +1,30 @@
<cfcomponent>
<cfset variables.fw = '' />
<cffunction name="init" access="public" returntype="void">
<cfargument name="fw" type="any" required="yes" />
<cfset variables.fw = arguments.fw />
</cffunction>

<cffunction name="setUserService" access="public" output="false" returntype="void">
<cfargument name="userService" type="any" required="true" />
<cfset variables.userService = arguments.userService />
</cffunction>
<cffunction name="getUserService" access="public" output="false" returntype="any">
<cfreturn variables.userService />
</cffunction>

<cffunction name="password" access="public" returntype="void">
<cfargument name="rc" type="struct" required="yes" />
<cfset rc.id = session.auth.user.getId() />
<cfset rc.user = getUserService().get(rc.id) />
</cffunction>

<cffunction name="change" access="public" output="false" returntype="void">
<cfargument name="rc" type="struct" required="true">
<cfset var userService = getUserService() />
<cfset var newPasswordHash = '' />

<!--- validate new password --->
<cfset rc.user = userService.get(argumentCollection=rc) />
<cfset rc.message = userService.checkPassword(argumentCollection=rc) />

<!--- if the new password failed, redirect to the form --->
<cfif not arrayIsEmpty(rc.message)>
<cfset variables.fw.redirect('main.password','message') />
</cfif>

<!--- hash the new password and populate the user object --->
<cfset newPasswordHash = userService.hashPassword(rc.newPassword) />
<cfset rc.passwordHash = newPasswordHash.hash />
<cfset rc.passwordSalt = newPasswordHash.salt />
<cfset variables.fw.populate( cfc = rc.user, trim = true )>

<!--- save the user and redirect --->
<cfset userService.save(rc.user) />
<cfset rc.message = ['Your password was changed'] />
<cfset variables.fw.redirect('main','message') />
</cffunction>

</cfcomponent>
component accessors=true {

property userService;

function init( fw ) {
variables.fw = fw;
}

function password( rc ) {
rc.id = session.auth.user.getId();
}

function change( rc ) {
rc.user = variables.userService.get( rc.id );
rc.message = variables.userService.checkPassword( argumentCollection = rc );
if ( !arrayIsEmpty( rc.message ) ) {
variables.fw.redirect( "main.password", "message" );
}
var newPasswordHash = variables.userService.hashPassword( rc.newPassword );
rc.passwordHash = newPasswordHash.hash;
rc.passwordSalt = newPasswordHash.salt;
// this will update any user fields from RC so it's a bit overkill here
variables.fw.populate( cfc = rc.user, trim = true );

variables.userService.save( rc.user );
rc.message = ["Your password was changed"];
variables.fw.redirect( "main", "message" );
}

}
40 changes: 20 additions & 20 deletions examples/userManagerAccessControl/controllers/security.cfc
@@ -1,23 +1,23 @@
<cfcomponent><cfscript>
component {

function init( fw ) {
variables.fw = fw;
}
function init( fw ) {
variables.fw = fw;
}

function session( rc ) {
// set up the user's session
session.auth = {};
session.auth.isLoggedIn = false;
session.auth.fullname = 'Guest';
}

function authorize( rc ) {
// check to make sure the user is logged on
if ( not session.auth.isLoggedIn and
not listfindnocase( 'login', variables.fw.getSection() ) and
not listfindnocase( 'main.error', variables.fw.getFullyQualifiedAction() ) ) {
variables.fw.redirect('login');
}
}
function session( rc ) {
// set up the user's session
session.auth = {};
session.auth.isLoggedIn = false;
session.auth.fullname = 'Guest';
}

</cfscript></cfcomponent>
function authorize( rc ) {
// check to make sure the user is logged on
if ( not ( structKeyExists( session, "auth" ) && session.auth.isLoggedIn ) &&
!listfindnocase( 'login', variables.fw.getSection() ) &&
!listfindnocase( 'main.error', variables.fw.getFullyQualifiedAction() ) ) {
variables.fw.redirect('login');
}
}

}

0 comments on commit d68e674

Please sign in to comment.