Solved

Delphi Mysql user login and set premession for each user

Posted on 2014-09-22
4
549 Views
Last Modified: 2014-09-29
i have multi user chat program and iam using mysql to define each user has logged in and give him premession

i have 2 forms main and login

in login form here is my code to allow user to login and start using the application

 SQL := Tloginclass.Create;
  try
    SQL.Login:= trim(Usrnm.Text);
    SQL.passwd := trim(passwd.Text);
    if SQl.logins then
     begin
      LoginSuccess := True;
     end

Open in new window


but how to sort each user how to show that there is a user joined the room also how to implement the tracking of online users. Second is how to enable/disable some functionality of my application based on the specific user

iam using indy tcp as chat server and client .
0
Comment
Question by:drama22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40338857
when your user do succesful login - read permission field(s) for that user and store it somewhere (record)
Logic for user activity can be kept in same record on server side:
TChatUserInfo = record
  UserCredential: Integer; //maybe level of user
  LastActivity: TDateTime; // on last login, send message, ... here keep current date/time
end;

Open in new window

Using distance from Now and LastActivity - you can get how many time elapsed and decide about online status.

few examples:
http://www.devarticles.com/c/a/Delphi-Kylix/Creating-Chat-Application-with-Borland-DelphiIndy-The-Client/
http://www.ciuly.com/delphi/indy/tcp-single-exe-chat-demo/ (this one have simple user menagement)
0
 

Author Comment

by:drama22
ID: 40340232
Example if I want to store his user name what should I do ? Can you tell me an example with my code it will be more understandable for me and I walk on the logic. Thanks for your comment.
0
 

Author Comment

by:drama22
ID: 40346516
i make   a public variable in the main form and set this variable string from login form

like this

Main.usernmo := username;

Open in new window



then i did somthing like this to store username

type
TMember = class(TObject)
Public
Name : string;
end;

Open in new window


then call it like this

var
mame : TMember;
begin
mame := TMember.Create;
mame.Name := usernmo;
Memo.Lines.Add(mame.Name + '' +' Joined');

Open in new window


is that right way i feel its wrong , could you correct me ?
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40350793
this is more correct:
type
  TMember = class(TObject)
  private
    FName: String;
  public
    property Name: String read FName write FName;
  end;

Open in new window


... and when you create new member - put it in Tlist for later. On destroy - free all TList members:
...
//global
UserList: TList;
...
UserList := TList.Create;
...
mame := TMember.Create;
mame.Name := usernmo;
//add to list
UserList.Add(mame);


///server destroy
p: TMember;
...
for i:=1 to UserList.Count do
begin
   p := UserList.Item[i-1];
   UserList.Item[i-1] := nil;
  FreeAndNil(p);
end;
 UserList.Free;

Open in new window


... you can add/remove some member dynamically  - when user do login/logout...
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question