Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { -- Todo :
- fix const userfile to config.datapath + userfilename
- add acs checking possably use pipeline style acs checking
- add more user vars as more is written
- add encrypt string to encrypt password from sysop
- -sd
- }
- unit UserManager;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, IniFiles, Windows, SyncObjs;
- const
- userfile = 'userdata.ini'; // replace this with config string +'userdata.ini'
- type
- TUserAccount = class(TObject)
- protected
- FName: string;
- FRealName: string;
- FPassword: string;
- FACSString: string;
- FFlagAttributes: string;
- FEmailAddress : String;
- public
- constructor Create;
- destructor Destroy; override;
- function CheckPassword(const APassword: string): boolean;
- function ACSCheck(const AValue: string): boolean;
- published
- property UserName: string read FName write FName;
- property UserRealName: string read FRealName write FRealName;
- property Password: string read FPassword write FPassword;
- property UserACS: string read FACSString write FACSString;
- property UserFlags: string read FFlagAttributes write FFlagAttributes;
- property EmailAddress : string read FEmailAddress write FEmailAddress;
- end;
- TUserAccountManager = class(TObject)
- protected
- FLock: TRTLCriticalSection;
- FLastError: integer;
- FLastErrorStr: string;
- FIFile: TInifile;
- procedure FSetError(ACode: integer; AError: string);
- procedure FResetError;
- public
- constructor Create;
- destructor Destroy; override;
- function GetAccountByUserName(const AUserName: string): TUserAccount;
- function DoesAccountExist(const AUserName: string): boolean;
- procedure AddAccount(const AAccount: TUserAccount);
- procedure DeleteAcccount(const AUserName: string);
- procedure UpdateAccount(const AAccount: TUserAccount);
- published
- property LastError: integer read FLastError default 0;
- property LastErrorStr: string read FLastErrorStr;
- end;
- implementation
- constructor TUserAccountManager.Create;
- begin
- if not FileExists(userfile) then
- FSetError(1, 'TUserAccountManager.Create : User File Does NOT Exist');
- FIFile := TInifile.Create(userfile);
- InitializeCriticalSection(FLock);
- end;
- destructor TUserAccountManager.Destroy;
- begin
- FIFile.Free;
- DeleteCriticalSection(FLock);
- end;
- procedure TUserAccountManager.FSetError(ACode: integer; AError: string);
- begin
- FLastError := ACode;
- FLastErrorStr := AError;
- end;
- procedure TUserAccountManager.FResetError;
- begin
- FLastError := 0;
- FlastErrorStr := '';
- end;
- function TUserAccountManager.DoesAccountExist(const AUserName: string): boolean;
- begin
- EnterCriticalSection(FLock);
- try
- Result := FIFile.SectionExists(AUserName);
- finally
- LeaveCriticalSection(FLock);
- end;
- end;
- function TUserAccountManager.GetAccountByUserName(const AUserName: string): TUserAccount;
- begin
- if not DoesAccountExist(AUserName) then
- begin
- FSetError(2, 'TUserAccountManager.GetAccountByUserName : User Does Not Exist');
- exit;
- end;
- EnterCriticalSection(FLock);
- try
- Result := TUserAccount.Create;
- Result.UserRealName := FIFile.ReadString(AUserName, 'USER_REAL_NAME', '');
- Result.UserName := FIFile.ReadString(AUserName, 'USER_HANDLE', '');
- Result.Password := FIFile.ReadString(AUserName, 'USER_PASSWORD', '');
- Result.EmailAddress:= FIFile.ReadString(AUserName,'USER_EMAIL,'');
- Result.UserACS := FIFile.ReadString(AUserName, 'USER_ACS', '');
- Result.UserFlags := FIFile.ReadString(AUserName, 'USER_FLAGS', '');
- finally
- LeaveCriticalSection(FLock);
- end;
- end;
- procedure TUserAccountManager.AddAccount(const AAccount: TUserAccount);
- begin
- if DoesAccountExist(AAccount.UserName) then
- begin
- FSetError(3, 'TUserAccountManager.AddAccount : User Already Exist');
- exit;
- end;
- EnterCriticalSection(FLock);
- try
- FIFile.WriteString(AAccount.UserName, 'USER_HANDLE', AAccount.UserName);
- FIFile.WriteString(AAccount.UserName, 'USER_REAL_NAME', AAccount.UserRealName);
- FIFile.WriteString(AAccount.UserName, 'USER_EMAIL',AAccount.EmailAddress);
- FIFile.WriteString(AAccount.UserName, 'USER_PASSWORD', AAccount.Password);
- FIFile.WriteString(AAccount.UserName, 'USER_ACS', AAccount.UserACS);
- FIFile.WriteString(AAccount.UserName, 'USER_FLAGS', AAccount.UserFlags);
- finally
- LeaveCriticalSection(FLock);
- end;
- end;
- procedure TUserAccountManager.DeleteAcccount(const AUserName: string);
- begin
- if not DoesAccountExist(AUserName) then
- begin
- FSetError(2, 'TUserAccountManager.DeleteAccount : User Does Not Exist');
- Exit;
- end;
- EnterCriticalSection(FLock);
- try
- FIFile.EraseSection(AUserName);
- if DoesAccountExist(AUserName) then
- FSetError(4, 'TUserAccountManager.DeleteAccount : User Exist After Deletion');
- finally
- LeaveCriticalSection(FLock);
- end;
- end;
- procedure TUserAccountManager.UpdateAccount(const AAccount: TUserAccount);
- begin
- if not DoesAccountExist(AAccount.UserName) then
- begin
- FSetError(3, 'TUserAccountManager.UpdateAccount : User Does Not Exist');
- exit;
- end;
- EnterCriticalSection(FLock);
- try
- FIFile.WriteString(AAccount.UserName, 'USER_HANDLE', AAccount.UserName);
- FIFile.WriteString(AAccount.UserName, 'USER_REAL_NAME', AAccount.UserRealName);
- FIFile.WriteString(AAccount.UserName, 'USER_PASSWORD', AAccount.Password);
- FIFile.WriteString(AAccount.UserName, 'USER_EMAUL',AAccount.EmailAddress);
- FIFile.WriteString(AAccount.UserName, 'USER_ACS', AAccount.UserACS);
- FIFile.WriteString(AAccount.UserName, 'USER_FLAGS', AAccount.UserFlags);
- finally
- LeaveCriticalSection(FLock);
- end;
- end;
- constructor TUserAccount.Create;
- begin
- // lets set defaults
- UserName := 'Unknown';
- UserRealName := 'Unknown';
- Password := '';
- UserACS := '';
- UserFlags := '';
- end;
- destructor TUserAccount.Destroy;
- begin
- end;
- function TUserAccount.CheckPassword(const APassword: string): boolean;
- begin
- Result := match(EncryptString(Uppercase(APassword), Password));
- end;
- function TUserAccount.ACSCheck(const AValue: string): boolean;
- begin
- Result := True;
- // fix me!! iniquity / rg / tg / pipeline acs style system research time
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement