Skip to content

Commit

Permalink
fix create user - move pw & un to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
joedanz committed Jan 31, 2008
1 parent 1038f7c commit 214a8b2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 57 deletions.
20 changes: 15 additions & 5 deletions ajax/proj_users.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset thread.sleep(250)>
<cfelseif StructKeyExists(form,"addnew")>
<cfset newID = createUUID()>
<cfset application.user.create(newID,form.f,form.l,form.e,form.p,form.adm)>
<cfset application.role.add(form.p,newID,form.a,form.f,form.i,form.m,form.ms,form.t,form.s)>
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset thread.sleep(250)>
<cfset userExists = application.user.get('','',form.un)>
<cfif userExists.recordCount>
<cfset error = "Username already exists!">
<cfelse>
<cfset newID = createUUID()>
<cfset application.user.create(newID,form.fn,form.ln,form.e,form.ph,form.un,form.pw,form.adm)>
<cfset application.role.add(form.p,newID,form.a,form.f,form.i,form.m,form.ms,form.t,form.s)>
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset thread.sleep(250)>
</cfif>
<cfset url.p = form.p>
<cfelseif StructKeyExists(url,"d")>
<cfset application.role.remove(url.p,url.d)>
Expand All @@ -22,6 +27,11 @@
<cfset userRole = application.role.get(session.user.userid,url.p)>

<cfoutput>
<cfif StructKeyExists(variables,"error")>
<script type="text/javascript">
alert('Username already exists - please try another!');
</script>
</cfif>
<cfloop query="projectUsers">
<div class="user<cfif currentRow neq recordCount> listitem</cfif>" id="#userID#">

Expand Down
54 changes: 7 additions & 47 deletions cfcs/user.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,7 @@

<cfset variables.dsn = "">
<cfset variables.tableprefix = "">

<cfscript>
/**
* Generates an 8-character random password free of annoying similar-looking characters such as 1 or l.
*
* @return Returns a string.
* @author Alan McCollough (amccollough@anmc.org)
* @version 1, December 18, 2001
*/
function MakePassword()
{
var valid_password = 0;
var loopindex = 0;
var this_char = "";
var seed = "";
var new_password = "";
var new_password_seed = "";
while (valid_password eq 0){
new_password = "";
new_password_seed = CreateUUID();
for(loopindex=20; loopindex LT 35; loopindex = loopindex + 2){
this_char = inputbasen(mid(new_password_seed, loopindex,2),16);
seed = int(inputbasen(mid(new_password_seed,loopindex/2-9,1),16) mod 3)+1;
switch(seed){
case "1": {
new_password = new_password & chr(int((this_char mod 9) + 48));
break;
}
case "2": {
new_password = new_password & chr(int((this_char mod 26) + 65));
break;
}
case "3": {
new_password = new_password & chr(int((this_char mod 26) + 97));
break;
}
} //end switch
}
valid_password = iif(refind("(O|o|0|i|l|1|I|5|S)",new_password) gt 0,0,1);
}
return new_password;
}
</cfscript>


<cffunction name="init" access="public" returntype="user" output="false"
hint="Returns an instance of the CFC initialized with the correct DSN & table prefix.">
<cfargument name="settings" type="struct" required="true" hint="Settings">
Expand Down Expand Up @@ -121,6 +78,8 @@
<cfargument name="lastName" type="string" required="true">
<cfargument name="email" type="string" required="true">
<cfargument name="phone" type="string" required="true">
<cfargument name="username" type="string" required="true">
<cfargument name="password" type="string" required="true">
<cfargument name="admin" type="numeric" required="true">
<cfargument name="active" type="numeric" required="false" default="1">
<cfset var newUsername = left(lcase(ARGUMENTS.firstName),1) & lcase(ARGUMENTS.lastName)>
Expand All @@ -138,15 +97,16 @@
</cfif>
</cfloop>
<cfquery datasource="#variables.dsn#">
INSERT INTO #variables.tableprefix#users (userID, firstName, lastName, username, password, email, avatar, style, email_todos, mobile_todos, email_mstones, mobile_mstones, email_issues, mobile_issues, admin, active)
INSERT INTO #variables.tableprefix#users (userID, firstName, lastName, username, password, email, avatar, style, email_files, mobile_files, email_issues, mobile_issues, email_msgs, mobile_msgs, email_mstones, mobile_mstones, email_todos, mobile_todos, admin, active)
VALUES(<cfqueryparam cfsqltype="cf_sql_char" value="#arguments.userID#" maxlength="35">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstName#" maxlength="12">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastName#" maxlength="20">,
'#newUsername#', '#newPass#',
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.username#" maxlength="30">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#" maxlength="20">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.email#" maxlength="120">,
0,
'#application.settings.default_style#',
0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,
<cfqueryparam cfsqltype="cf_sql_tinyint" value="#arguments.admin#">,
<cfqueryparam cfsqltype="cf_sql_tinyint" value="#arguments.active#">
)
Expand Down
42 changes: 42 additions & 0 deletions includes/udf.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,48 @@ function RFind(substr,str) {
return len(str)-rcnt-len(substr)+2;
}
request.udf.RFind = RFind;
/**
* Generates an 8-character random password free of annoying similar-looking characters such as 1 or l.
*
* @return Returns a string.
* @author Alan McCollough (amccollough@anmc.org)
* @version 1, December 18, 2001
*/
function MakePassword()
{
var valid_password = 0;
var loopindex = 0;
var this_char = "";
var seed = "";
var new_password = "";
var new_password_seed = "";
while (valid_password eq 0){
new_password = "";
new_password_seed = CreateUUID();
for(loopindex=20; loopindex LT 35; loopindex = loopindex + 2){
this_char = inputbasen(mid(new_password_seed, loopindex,2),16);
seed = int(inputbasen(mid(new_password_seed,loopindex/2-9,1),16) mod 3)+1;
switch(seed){
case "1": {
new_password = new_password & chr(int((this_char mod 9) + 48));
break;
}
case "2": {
new_password = new_password & chr(int((this_char mod 26) + 65));
break;
}
case "3": {
new_password = new_password & chr(int((this_char mod 26) + 97));
break;
}
} //end switch
}
valid_password = iif(refind("(O|o|0|i|l|1|I|5|S)",new_password) gt 0,0,1);
}
return new_password;
}
request.udf.MakePassword = MakePassword;
</cfscript>

<cfsetting enablecfoutputonly=false>
2 changes: 1 addition & 1 deletion js/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function add_new(pid) {
$.ajax({
type: 'post',
url: './ajax/proj_users.cfm',
data: 'addnew=1&p=' + pid + '&f=' + $('#fname').val() + '&l=' + $('#lname').val() + '&p=' + $('#phone').val() + '&adm=' + $('#admin').val() + '&e=' + $('#email').val() + '&a=' + $('#a_new:checked').val() + '&f=' + $('#f_new').val() + '&i=' + $('#i_new').val() + '&m=' + $('#m_new').val() + '&ms=' + $('#ms_new').val() + '&t=' + $('#t_new').val() + '&s=' + $('#s_new:checked').val(),
data: 'addnew=1&p=' + pid + '&fn=' + $('#fname').val() + '&ln=' + $('#lname').val() + '&ph=' + $('#phone').val() + '&un=' + $('#username').val() + '&pw=' + $('#password').val() + '&adm=' + $('#admin').val() + '&e=' + $('#email').val() + '&a=' + $('#a_new:checked').val() + '&f=' + $('#f_new').val() + '&i=' + $('#i_new').val() + '&m=' + $('#m_new').val() + '&ms=' + $('#ms_new').val() + '&t=' + $('#t_new').val() + '&s=' + $('#s_new:checked').val(),
success: function(txt){
$('#replace').html(txt);
}
Expand Down
16 changes: 12 additions & 4 deletions people.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,31 @@
<legend class="b">Add a new person to this project:</legend>

<label for="fname">First
<input type="text" name="firstName" id="fname" size="7" />
<input type="text" name="firstName" id="fname" size="6" />
</label>

<label for="lname">Last
<input type="text" name="lastName" id="lname" size="10" />
<input type="text" name="lastName" id="lname" size="8" />
</label>

<label for="email">Email
<input type="text" name="email" id="email" size="22" />
</label>

<label for="phone">Phone
<input type="text" name="phone" id="phone" size="7" />
<input type="text" name="phone" id="phone" size="6" />
</label>

<label for="username">Username
<input type="text" name="username" id="username" size="8" />
</label>

<label for="password">Password
<input type="text" name="password" id="password" value="#lcase(left(request.udf.MakePassword(),4))#" size="6" />
</label>

<cfif session.user.admin>
<label for="globaladmin">Global Admin?
<label for="globaladmin">SysAdmin?
<select name="admin" id="admin" class="block">
<option value="0">No
<option value="1">Yes
Expand Down

0 comments on commit 214a8b2

Please sign in to comment.