home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * *
- * SmUAdmin.jfm -- Security User Administration Form *
- * *
- * This form is part of the security administration prebuilt business *
- * solution. This is the user adminstration form. It allows you to define *
- * new groups and update existing users. This form is called from the *
- * SmAdmin form. *
- * *
- * Dependencies: secur21.gif *
- * *
- * Updated 11/13/96 by IntraBuilder Samples Group *
- * $Revision: 1.10 $ *
- * *
- * Copyright (c) 1996, Borland International, Inc. All rights reserved. *
- * *
- \****************************************************************************/
- #include "security.h"
- // {End Header} Do not remove this comment//
- // Generated on 11/13/96
- //
- var f = new smuadminForm();
- f.open();
- class smuadminForm extends SecurityForm from "SMADMIN.JCF" {
- _sys.scripts.load(_sys.env.home() + "APPS\\SHARED\\CONTROLS.CC")
- with (this) {
- preRender = class::Form_preRender;
- onServerLoad = class::Form_onServerLoad;
- color = "fff7c4";
- height = 14.6667;
- left = 0;
- top = 0;
- width = 74;
- title = "User Administration";
- }
-
-
- with (this.rule1 = new Rule(this)){
- top = 4;
- size = 2;
- right = 74;
- pageno = 0;
- }
-
-
- with (this.rule2 = new Rule(this)){
- top = 24;
- size = 2;
- right = 74;
- pageno = 0;
- }
-
-
- with (this.actionHTML = new HTML(this)){
- height = 1;
- left = 12;
- top = 2;
- width = 30;
- color = "400040";
- text = "Update Existing User";
- }
-
-
- with (this.saveButton = new Button(this)){
- onServerClick = class::saveButton_onServerClick;
- left = 42;
- top = 2;
- width = 14;
- text = "Save";
- }
-
-
- with (this.exitButton = new Button(this)){
- onServerClick = class::exitButton_onServerClick;
- left = 58;
- top = 2;
- width = 14;
- text = " Exit ";
- }
-
-
- with (this.userHTML = new HTML(this)){
- height = 1;
- top = 7;
- width = 18;
- color = "400040";
- alignVertical = 1;
- text = "User name";
- }
-
-
- with (this.usernameHTML = new HTML(this)){
- height = 1;
- left = 18;
- top = 7;
- width = 18;
- color = "black";
- alignVertical = 1;
- text = "username";
- }
-
-
- with (this.usernameText = new Text(this)){
- visible = false;
- left = 18;
- top = 7;
- width = 18;
- value = "username";
- }
-
-
- with (this.createHTML = new HTML(this)){
- height = 1;
- top = 5;
- width = 18;
- color = "400040";
- alignVertical = 1;
- text = "Created";
- }
-
-
- with (this.createdHTML = new HTML(this)){
- height = 1;
- left = 18;
- top = 5;
- width = 18;
- color = "black";
- alignVertical = 1;
- text = " / / : : ";
- }
-
-
- with (this.lastloginHTML = new HTML(this)){
- height = 1;
- top = 6;
- width = 18;
- color = "400040";
- alignVertical = 1;
- text = "Last login";
- }
-
-
- with (this.loginHTML = new HTML(this)){
- height = 1;
- left = 18;
- top = 6;
- width = 18;
- color = "black";
- alignVertical = 1;
- text = " / / : : ";
- }
-
-
- with (this.descriptionHTML = new HTML(this)){
- height = 1;
- top = 8;
- width = 18;
- color = "400040";
- alignVertical = 1;
- text = "Description";
- }
-
-
- with (this.descriptionText = new Text(this)){
- left = 18;
- top = 8;
- width = 44;
- value = "description";
- }
-
-
- with (this.disableCheck = new CheckBox(this)){
- height = 1;
- top = 11.5;
- width = 74;
- text = "Account disabled";
- checked = false;
- }
-
-
- with (this.lockoutCheck = new CheckBox(this)){
- height = 1;
- top = 12.5;
- width = 74;
- text = "Account locked out";
- checked = false;
- }
-
-
- with (this.passwordHTML = new HTML(this)){
- height = 1;
- top = 9;
- width = 18;
- color = "400040";
- alignVertical = 1;
- text = "Password ";
- }
-
-
- with (this.passwordText = new Password(this)){
- left = 18;
- top = 9;
- width = 18;
- value = "";
- }
-
-
- with (this.confirmHTML = new HTML(this)){
- height = 1;
- top = 10;
- width = 18;
- color = "400040";
- alignVertical = 1;
- text = "Confirm password ";
- }
-
-
- with (this.confirmText = new Password(this)){
- left = 18;
- top = 10;
- width = 18;
- value = "";
- }
-
-
- with (this.inGroupHTML = new HTML(this)){
- height = 1;
- top = 14;
- width = 24;
- color = "400040";
- text = "Member of group";
- }
-
-
- with (this.outGroupHTML = new HTML(this)){
- height = 1;
- left = 48;
- top = 14;
- width = 24;
- color = "400040";
- text = "Not member of group";
- }
-
-
- with (this.inGroupSelect = new ListBox(this)){
- height = 3.5;
- top = 15;
- width = 24;
- }
-
-
- with (this.addGroupButton = new Button(this)){
- onServerClick = class::addGroupButton_onServerClick;
- left = 26;
- top = 15;
- width = 20;
- text = "Add Group";
- }
-
-
- with (this.removeGroupButton = new Button(this)){
- onServerClick = class::removeGroupButton_onServerClick;
- left = 26;
- top = 16.5;
- width = 20;
- text = "Remove Group";
- }
-
-
- with (this.outGroupSelect = new ListBox(this)){
- height = 3.5;
- left = 48;
- top = 15;
- width = 24;
- }
-
-
- with (this.inResourceHTML = new HTML(this)){
- height = 1;
- top = 19;
- width = 24;
- color = "400040";
- text = "May access resource";
- }
-
-
- with (this.outResourceHTML = new HTML(this)){
- height = 1;
- left = 48;
- top = 19;
- width = 24;
- color = "400040";
- text = "May not access resource";
- }
-
-
- with (this.inResourceSelect = new ListBox(this)){
- height = 3.5;
- top = 20;
- width = 24;
- }
-
-
- with (this.addResourceButton = new Button(this)){
- onServerClick = class::addResourceButton_onServerClick;
- left = 26;
- top = 20;
- width = 20;
- text = "Add Res.";
- }
-
-
- with (this.removeResourceButton = new Button(this)){
- onServerClick = class::removeResourceButton_onServerCli;
- left = 26;
- top = 21.5;
- width = 20;
- text = "Remove Res.";
- }
-
-
- with (this.outResourceSelect = new ListBox(this)){
- height = 3.5;
- left = 48;
- top = 20;
- width = 24;
- }
-
-
- with (this.errorHTML = new HTML(this)){
- height = 4;
- left = 2;
- top = 8;
- width = 74;
- color = "400040";
- text = "Error loading user administration form. Notify system administrator.";
- pageno = 2;
- }
-
-
- with (this.backButton = new Button(this)){
- onServerClick = {;this.form.pageno = 1 ;this.form.Form_preRender(this.form)};
- left = 2;
- top = 14;
- width = 20;
- text = "Back";
- pageno = 2;
- }
-
-
- with (this.GeneratedHTML1 = new GeneratedHTML(this)){
- height = 1;
- top = 24.5;
- width = 74;
- pageno = 0;
- }
-
-
- function Form_preRender( formRef )
- {
- var form = Form_preRender.arguments.length == 1 ? formRef : this;
- //
- // clear the password controls
- //
- form.passwordText.value = "";
- form.confirmText.value = "";
- }
-
- function Form_onServerLoad()
- {
- try {
- //
- // make sure that all the custom properties are set
- //
- var x = this.copyEntity?1:0;
- var x = this.entity.name;
- var x = this.security._admin;
- var x = this.callingForm.title;
- //
- // set the action text
- //
- this.createNew = true;
- if (this.entity.name == null)
- this.actionHTML.text = "Create New User";
- else if (this.copyEntity)
- this.actionHTML.text = ("Copy " + this.entity.name + " To New User");
- else {
- this.createNew = false;
- this.actionHTML.text = "Update Existing User";
- }
- //
- // set the control values on this form
- //
- if ((this.entity.name == null) || (this.copyEntity)) {
- this.usernameText.value = new StringEx().replicate(" ",20);
- this.usernameText.visible = true;
- this.usernameHTML.visible = false;
- }
- else {
- this.usernameHTML.text = this.entity.name;
- this.usernameHTML.visible = true;
- this.usernameText.visible = false;
- }
- this.createdHTML.text = (this.entity.created == null) ?
- "(new user)" : ("" + this.entity.created);
- this.loginHTML.text = (this.entity.login == null) ?
- "(no prior login)" : ("" + this.entity.login);
- this.descriptionText.value = (this.entity.description == null) ?
- new StringEx().replicate(" ",80) :
- this.entity.description;
- this.disableCheck.checked = this.entity.disabled;
- this.lockoutCheck.checked = this.entity.lockout;
- // create arrays for the select controls
- this.inGroup = new Array();
- this.outGroup = new Array();
- this.inResource = new Array();
- this.outResource = new Array();
- // save original groups/resources for use in save
- this.inGroupStart = new Array();
- this.inResourceStart = new Array();
- var entity = "";
- // build group lists
- if (this.entity.name == null)
- var inGroup = new AssocArray();
- else
- var inGroup = this.security.getAllGroups(this.entity.name, SM_ENTITY_USER);
- var outGroup = this.security.getAllGroups();
- // add all in groups to list
- for (var i = 0; i<inGroup.count(); i++) {
- entity = (i==0) ? inGroup.firstKey : inGroup.nextKey(entity);
- this.inGroup.add(entity);
- this.inGroupStart.add(entity);
- }
- this.inGroup.sort();
- this.inGroupSelect.options = 'array this.inGroup';
- // add groups to out list if they are not in in list
- for (i = 0; i<outGroup.count(); i++) {
- entity = (i==0) ? outGroup.firstKey : outGroup.nextKey(entity);
- if (!inGroup.isKey(entity))
- this.outGroup.add(entity);
- }
- this.outGroup.sort();
- this.outGroupSelect.options = 'array this.outGroup';
- // build resource lists
- if (this.createNew)
- var inResource = new AssocArray();
- else
- var inResource = this.security.getAllResources(this.entity.name, SM_ENTITY_USER);
- var outResource = this.security.getAllResources();
- // add all in resources to list
- for (var i = 0; i<inResource.count(); i++) {
- entity = (i==0) ? inResource.firstKey : inResource.nextKey(entity);
- this.inResource.add(entity);
- this.inResourceStart.add(entity);
- }
- this.inResource.sort();
- this.inResourceSelect.options = 'array this.inResource';
- // add resources to out list if they are not in in list
- for (i = 0; i<outResource.count(); i++) {
- entity = (i==0) ? outResource.firstKey : outResource.nextKey(entity);
- if (!inResource.isKey(entity))
- this.outResource.add(entity);
- }
- this.outResource.sort();
- this.outResourceSelect.options = 'array this.outResource';
- }
- catch (Exception e) {
- form.errorHTML.text = "Error loading user: " + e.message + " (" + e.code + ")";
- this.pageno = 2;
- }
- }
-
- function saveButton_onServerClick()
- {
- var form = this.form;
- try {
- // have an exception ready
- var error = new Exception();
- error.message = "";
- error.code = 0;
- //
- // set the properties of the entity object
- //
- // user name
- if (form.createNew) {
- var name = new StringEx(form.usernameText.value);
- name.string = name.leftTrim();
- name.string = name.rightTrim();
- if (name.length == 0) {
- error.message = "User name may not be blank";
- throw error;
- }
- else
- form.entity.name = name;
- }
- // password
- if (form.passwordText.value != form.confirmText.value) {
- error.message = "Password and confirmation do not match";
- throw error;
- }
- if (form.passwordText.value == "********")
- form.entity.password = null;
- else
- form.entity.password = form.passwordText.value;
- // description
- form.entity.description = form.descriptionText.value;
- // disabled and lockout
- form.entity.disabled = form.disableCheck.checked;
- form.entity.lockout = form.lockoutCheck.checked;
- //
- // call create/update with entity object
- //
- if (form.createNew)
- form.security.createUser(form.entity);
- else
- form.security.updateUser(form.entity);
- //
- // assign group membership
- //
- for (var i = 0; i<form.inGroup.length; i++) {
- if ((form.createNew) || (form.inGroupStart.scan(form.inGroup[i]) < 0))
- form.security.assignGroupUser(form.inGroup[i],form.entity.name);
- }
- //
- // assign resource privileges
- //
- for (var i = 0; i<form.inResource.length; i++) {
- if ((form.createNew) || (form.inResourceStart.scan(form.inResource[i]) < 0))
- form.security.assignResourceUser(form.inResource[i],form.entity.name);
- }
- //
- // remove group memberships for existing users only
- //
- if (!form.createNew) {
- for (var i = 0; i<form.inGroupStart.length; i++) {
- if (form.inGroup.scan(form.inGroupStart[i]) < 0)
- form.security.unassignGroupUser(form.inGroupStart[i],form.entity.name);
- }
- }
- //
- // remove resource privileges for existing users only
- //
- if (!form.createNew) {
- for (var i = 0; i<form.inResourceStart.length; i++) {
- if (form.inResource.scan(form.inResourceStart[i]) < 0)
- form.security.unassignResourceUser(form.inResourceStart[i],form.entity.name);
- }
- }
- //
- // Successful change, no longer in createNew mode
- //
- if (form.createNew) {
- form.createNew = false;
- form.actionHTML.text = "Update Existing User";
- form.usernameHTML.text = form.entity.name;
- form.usernameHTML.visible = true;
- form.usernameText.visible = false;
- }
- //
- // current inXxxxx arrays become the inXxxxxStart arrays
- //
- form.inGroupStart = new Array();
- form.inResourceStart = new Array();
- for (var i = 0; i<form.inGroup.length; i++)
- form.inGroupStart.add(form.inGroup[i]);
- for (var i = 0; i<form.inResource.length; i++)
- form.inResourceStart.add(form.inResource[i]);
- //
- // reset the password controls
- //
- form.Form_preRender(form);
- }
- catch (Exception e) {
- form.errorHTML.text = "Error saving user: " + e.message + " (" + e.code + ")";
- form.pageno = 2;
- }
- }
-
- function exitButton_onServerClick()
- {
- try {
- this.form.callingForm.open();
- this.form.close();
- this.form.release();
- }
- catch (Exception e) {
- this.form.errorHTML.text = "Unable to return to calling form.";
- this.form.pageno = 2;
- }
- }
-
- function addGroupButton_onServerClick()
- {
- if ((this.form.outGroupSelect.value.length > 0) && (this.form.outGroup.scan(this.form.outGroupSelect.value) >= 0)) {
- this.form.inGroup.add(this.form.outGroupSelect.value);
- this.form.inGroup.sort();
- this.form.inGroupSelect.options = "array this.form.inGroup";
- this.form.outGroup.delete(this.form.outGroup.scan(this.form.outGroupSelect.value));
- this.form.outGroup.length -= 1;
- this.form.outGroupSelect.options = "array this.form.outGroup";
- }
- }
-
- function removeGroupButton_onServerClick()
- {
- if ((this.form.inGroupSelect.value.length > 0) && (this.form.inGroup.scan(this.form.inGroupSelect.value) >= 0)) {
- this.form.outGroup.add(this.form.inGroupSelect.value);
- this.form.outGroup.sort();
- this.form.outGroupSelect.options = "array this.form.outGroup";
- this.form.inGroup.delete(this.form.inGroup.scan(this.form.inGroupSelect.value));
- this.form.inGroup.length -= 1;
- this.form.inGroupSelect.options = "array this.form.inGroup";
- }
- }
-
- function addResourceButton_onServerClick()
- {
- if ((this.form.outResourceSelect.value.length > 0) && (this.form.outResource.scan(this.form.outResourceSelect.value) >= 0)) {
- this.form.inResource.add(this.form.outResourceSelect.value);
- this.form.inResource.sort();
- this.form.inResourceSelect.options = "array this.form.inResource";
- this.form.outResource.delete(this.form.outResource.scan(this.form.outResourceSelect.value));
- this.form.outResource.length -= 1;
- this.form.outResourceSelect.options = "array this.form.outResource";
- }
- }
-
- function removeResourceButton_onServerClick()
- {
- if ((this.form.inResourceSelect.value.length > 0) && (this.form.inResource.scan(this.form.inResourceSelect.value) >= 0)) {
- this.form.outResource.add(this.form.inResourceSelect.value);
- this.form.outResource.sort();
- this.form.outResourceSelect.options = "array this.form.outResource";
- this.form.inResource.delete(this.form.inResource.scan(this.form.inResourceSelect.value));
- this.form.inResource.length -= 1;
- this.form.inResourceSelect.options = "array this.form.inResource";
- }
- }
-
- }
-