Home arrow Delphi-Kylix arrow Page 3 - User Management for an Internet Access Control Application
DELPHI-KYLIX

User Management for an Internet Access Control Application


In this part of the Internet access control application, we are going to discuss the last section of the server application that deals with user management. The term "user management" is somewhat misleading in the context of our application because it is not actually users of the Internet café that we are referring to, but rather the staff members. This section will deal with how staff members allocate Internet sessions to users and also how staff members with administration level access can add, remove and change new staff member details.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 4
September 22, 2008
TABLE OF CONTENTS:
  1. · User Management for an Internet Access Control Application
  2. · User Management Module
  3. · User Management Module Explained
  4. · Stats Page

print this article
SEARCH DEVARTICLES

User Management for an Internet Access Control Application - User Management Module Explained
(Page 3 of 4 )

This module does three things. First, it prepares the form for user input, and then it checks that all the fields in the form is updated. The newly inputted data is then posted to the database and a confirmation message is displayed, stating that a new user has been created. Let’s look at the code that makes each of these three steps happen.

The first procedure checks that the administrator entered all the required information:

procedure TForm6.BitBtn1Click(Sender: TObject);

begin

The first part of the code checks that the administrator entered all the required information. This information comprises the user's name, password, etc.:


if (edname.Text = '') OR (eduname.Text = '') OR (edupass.Text = '') OR (edupass2.Text = '') OR (edupass.Text <> edupass2.Text) then begin


If the administrator leaves out any of the information, an error message is displayed informing her of it:

messagedlg('Please ensure that you fill in all the fields and that the password fields are the same.',mtInformation,[mbOK],0);

exit;

end

If the administrator has entered all the information correctly, it is posted to the database using the insert property of the ado component:

else begin

ado1.TableName:='users';

ado1.Active := True;

ado1.Insert;

ado1.FieldByName('name').AsString := edname.Text;

ado1.FieldByName('username').AsString :=eduname.text;

ado1.FieldByName('password').AsString := edupass.text;

ado1.FieldByName('Alevel').AsString :=cb.Text;

ado1.Post;

end;

end;

A confirmation message is then displayed as the final step in this process:

procedure TForm6.ado1AfterPost(DataSet: TDataSet);

begin

messagedlg(edname.Text + ' has now been created.',mtinformation,[mbOK],0);

end;


The next option in the user management module covers changing a staff member's password in the database. The code should be familiar to you by now. The following takes place in this module: first, all the names of the users in the database are retrieved and stored in a combo box. You have to select the name of the user whose details you want to change, and then add the new fields to the form. The changes are posted to the database and a confirmation message is displayed. Below is the code for the module:

unit changepassword;


interface


uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Buttons;


type

TForm7 = class(TForm)

gb1: TGroupBox;

cb: TComboBox;

StaticText1: TStaticText;

newpass: TEdit;

StaticText3: TStaticText;

StaticText4: TStaticText;

newpass2: TEdit;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

procedure BitBtn2Click(Sender: TObject);

procedure FormShow(Sender: TObject);

procedure cbSelect(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;


var

Form7: TForm7;

pname:string;

implementation


{$R *.dfm}

uses Logon;

procedure TForm7.BitBtn2Click(Sender: TObject);

begin

close;

end;


procedure TForm7.FormShow(Sender: TObject);

begin

gb1.Enabled:=false;

form3.q.close;

form3.q.SQL.Text:='SELECT name from users';

form3.q.Open;

while not form3.q.Eof do begin

cb.Items.Add(form3.q.fieldbyname('name').AsString);

form3.q.Next;

end;


end;


procedure TForm7.cbSelect(Sender: TObject);

begin

pname:=cb.Text;

gb1.Enabled:=true;

end;


procedure TForm7.BitBtn1Click(Sender: TObject);

begin

//check to see that all password fields are filled in

if (newpass.Text = '') OR (newpass2.Text = '' ) OR (newpass.Text <> newpass2.Text) then begin

messagedlg('Please ensure that you fill in all the fields and that both new password fields are the same.',mtInformation,[mbOK],0);

exit;

end else

begin

form3.q.close;

form3.q.SQL.text:='INSERT INTO users SET password=:newpass WHERE name=:thename';

form3.q.Parameters.ParamByName('thename').Value:=pname;

form3.q.Parameters.ParamByName('newpass').Value:=newpass.text;

form3.q.ExecSQL;

messagedlg('The password for ' + pname + 'has been changed.',mtInformation,[mbOK],0);

end;

end;

end.




blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials