Changeset 46 for trunk


Ignore:
Timestamp:
Jul 15, 2016, 2:24:18 PM (8 years ago)
Author:
chronos
Message:
  • Added: Now user name and password can be specified for import sources which require user authentication. Password is not stored in project file for safety reasons. Only Basic authentication is supported.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormImportSource.lfm

    r35 r46  
    11object FormImportSource: TFormImportSource
    22  Left = 492
    3   Height = 403
     3  Height = 444
    44  Top = 313
    55  Width = 604
    66  Caption = 'Import source'
    7   ClientHeight = 403
     7  ClientHeight = 444
    88  ClientWidth = 604
    99  OnShow = FormShow
     
    4444    Left = 515
    4545    Height = 25
    46     Top = 365
     46    Top = 406
    4747    Width = 75
    4848    Anchors = [akRight, akBottom]
     
    5454    Left = 413
    5555    Height = 25
    56     Top = 365
     56    Top = 406
    5757    Width = 75
    5858    Anchors = [akRight, akBottom]
     
    136136    Left = 10
    137137    Height = 2
    138     Top = 352
     138    Top = 393
    139139    Width = 580
    140140    Anchors = [akLeft, akBottom]
     141  end
     142  object Label5: TLabel
     143    Left = 10
     144    Height = 20
     145    Top = 352
     146    Width = 73
     147    Caption = 'User name:'
     148    ParentColor = False
     149  end
     150  object Label6: TLabel
     151    Left = 305
     152    Height = 20
     153    Top = 351
     154    Width = 65
     155    Caption = 'Password:'
     156    ParentColor = False
     157  end
     158  object EditUserName: TEdit
     159    Left = 136
     160    Height = 28
     161    Top = 351
     162    Width = 153
     163    TabOrder = 10
     164  end
     165  object EditPassword: TEdit
     166    Left = 436
     167    Height = 28
     168    Top = 351
     169    Width = 153
     170    EchoMode = emPassword
     171    PasswordChar = '*'
     172    TabOrder = 11
    141173  end
    142174  object ActionList1: TActionList
  • trunk/Forms/UFormImportSource.lrt

    r33 r46  
    88TFORMIMPORTSOURCE.CHECKBOXENABLED.CAPTION=Enabled
    99TFORMIMPORTSOURCE.LABEL4.CAPTION=Categories:
     10TFORMIMPORTSOURCE.LABEL5.CAPTION=User name:
     11TFORMIMPORTSOURCE.LABEL6.CAPTION=Password:
    1012TFORMIMPORTSOURCE.ACATEGORYREMOVE.CAPTION=Remove
    1113TFORMIMPORTSOURCE.ACATEGORYADD.CAPTION=Add
  • trunk/Forms/UFormImportSource.pas

    r33 r46  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ActnList, Menus, ExtCtrls, UAcronym;
     9  ActnList, Menus, ExtCtrls, MaskEdit, UAcronym;
    1010
    1111type
     
    2525    CheckBoxEnabled: TCheckBox;
    2626    ComboBox1: TComboBox;
     27    EditUserName: TEdit;
    2728    EditName: TEdit;
    2829    EditURL: TEdit;
     30    EditPassword: TEdit;
    2931    Label1: TLabel;
    3032    Label2: TLabel;
    3133    Label3: TLabel;
    3234    Label4: TLabel;
     35    Label5: TLabel;
     36    Label6: TLabel;
    3337    ListBox1: TListBox;
    3438    MenuItem1: TMenuItem;
     
    132136  CheckBoxEnabled.Checked := ImportSource.Enabled;
    133137  ImportSource.Categories.AssignToStrings(ListBox1.Items);
     138  EditUserName.Text := ImportSource.UserName;
     139  EditPassword.Text := ImportSource.Password;
    134140end;
    135141
     
    141147  ImportSource.Enabled := CheckBoxEnabled.Checked;
    142148  ImportSource.Categories.AssignFromStrings(ListBox1.Items);
     149  ImportSource.UserName := EditUserName.Text;
     150  ImportSource.Password := EditPassword.Text;
    143151end;
    144152
  • trunk/Languages/AcronymDecoder.cs.po

    r45 r46  
    379379msgstr "Kategorie:"
    380380
     381#: tformimportsource.label5.caption
     382msgid "User name:"
     383msgstr "Jméno:"
     384
     385#: tformimportsource.label6.caption
     386msgid "Password:"
     387msgstr "Heslo:"
     388
    381389#: tformimportsources.aadd.caption
    382390msgctxt "tformimportsources.aadd.caption"
     
    604612msgstr "Přeskočit"
    605613
     614#: uacronym.sunsupportedimportformat
     615msgid "Unsupported import format"
     616msgstr "Nepodporovaný formát importu"
     617
    606618#: uacronym.swrongfileformat
    607619msgid "Wrong file format"
  • trunk/Languages/AcronymDecoder.po

    r45 r46  
    369369msgstr ""
    370370
     371#: tformimportsource.label5.caption
     372msgid "User name:"
     373msgstr ""
     374
     375#: tformimportsource.label6.caption
     376msgid "Password:"
     377msgstr ""
     378
    371379#: tformimportsources.aadd.caption
    372380msgctxt "TFORMIMPORTSOURCES.AADD.CAPTION"
     
    594602msgstr ""
    595603
     604#: uacronym.sunsupportedimportformat
     605msgid "Unsupported import format"
     606msgstr ""
     607
    596608#: uacronym.swrongfileformat
    597609msgid "Wrong file format"
  • trunk/UAcronym.pas

    r45 r46  
    170170  TImportSource = class
    171171  private
     172    ResponseStream: TMemoryStream;
    172173    procedure DoPassword(Sender: TObject; var RepeatRequest : Boolean);
    173174  public
     
    180181    ItemCount: Integer;
    181182    Categories: TAcronymCategories;
     183    UserName: string;
     184    Password: string;
    182185    function DownloadHTTP(URL: string; Stream: TStream): Boolean;
    183186    procedure Process;
     
    235238resourcestring
    236239  SWrongFileFormat = 'Wrong file format';
     240  SUnsupportedImportFormat = 'Unsupported import format';
    237241  SDescription = 'Description';
    238242  SMeaning = 'Meaning';
     
    366370
    367371procedure TImportSource.DoPassword(Sender: TObject; var RepeatRequest: Boolean);
    368 begin
    369   if TFPHttpClient(Sender).Password = '' then begin
    370     TFPHttpClient(Sender).UserName := 'test';
    371     TFPHttpClient(Sender).Password := 'test';
    372     RepeatRequest := True;
    373   end else RepeatRequest := False;
    374 end;
     372var
     373  H: string;
     374  P: Integer;
     375begin
     376  with TFPHttpClient(Sender) do begin
     377    H := GetHeader(ResponseHeaders, 'WWW-Authenticate');
     378    if Pos(' ', H) > 0 then H := Copy(H, 1, Pos(' ', H) - 1);
     379
     380    if H <> 'Basic' then
     381      raise Exception.Create('Unsupported HTTP authorization method');
     382
     383    if (Self.UserName <> '') and (UserName = '') then begin
     384      UserName := Self.UserName;
     385      Password := Self.Password;
     386      ResponseStream.Clear;
     387      RepeatRequest := True;
     388    end else RepeatRequest := False;
     389  end;
     390end;
     391
    375392
    376393function TImportSource.DownloadHTTP(URL: string; Stream: TStream): Boolean;
     
    379396  FormData: TStringList;
    380397begin
     398  Result := False;
    381399  HTTPClient := TFPHttpClient.Create(nil);
     400  HTTPClient.AllowRedirect := True;
    382401  HTTPClient.OnPassword := DoPassword;
    383402  FormData := TStringList.Create;
    384 (*
    385 FormData.action=clientlogin
    386   &loginreturnurl=http://example.com/&
    387   logintoken=29590a3037d325be70b93fb8258ed29257448cfb%2B%5C&
    388   username=Bob&
    389   password=secret&
    390   rememberMe=1
    391   HTTPClient.FormPost(URL, FormData, Stream);
    392   *)
    393   HTTPClient.Get(URL, Stream);
    394   FormData.Free;
    395   HTTPClient.Free;
    396   Result := True;
     403  try
     404    HTTPClient.Get(URL, Stream);
     405    Result := True;
     406  finally
     407    FormData.Free;
     408    HTTPClient.Free;
     409  end;
    397410end;
    398411
     
    402415    ifkParse: ProcessTextParse;
    403416    ifkMSAccess: ProcessMSAccess;
    404     else raise Exception.Create('Unsupported import format');
     417    else raise Exception.Create(SUnsupportedImportFormat);
    405418  end;
    406419end;
     
    603616procedure TImportSource.ProcessTextParse;
    604617var
    605   Stream: TMemoryStream;
    606618  S: string;
    607619  SS: string;
     
    616628begin
    617629  ItemCount := 0;
    618   Stream := TMemoryStream.Create;
    619630  NewAcronym := TAcronymEntry.Create;
    620631  try
    621     if DownloadHTTP(URL, Stream) then begin
    622       Stream.Position := 0;
    623       SetLength(S, Stream.Size);
    624       Stream.Read(S[1], Length(S));
     632    if DownloadHTTP(URL, ResponseStream) then begin
     633      ResponseStream.Position := 0;
     634      SetLength(S, ResponseStream.Size);
     635      ResponseStream.Read(S[1], Length(S));
    625636
    626637      // Find main block
     
    705716  finally
    706717    NewAcronym.Free;
    707     Stream.Free;
    708718  end;
    709719end;
     
    718728  ItemCount := Source.ItemCount;
    719729  Categories.Assign(Source.Categories);
     730  UserName := Source.UserName;
     731  Password := Source.Password;
    720732end;
    721733
     
    730742  WriteBoolean(Node, 'Enabled', Enabled);
    731743  WriteInteger(Node, 'ItemCount', ItemCount);
     744  WriteString(Node, 'UserName', UserName);
    732745
    733746  NewNode := Node.OwnerDocument.CreateElement('Categories');
     
    745758  Enabled := ReadBoolean(Node, 'Enabled', True);
    746759  ItemCount := ReadInteger(Node, 'ItemCount', 0);
     760  UserName := ReadString(Node, 'UserName', '');
    747761
    748762  Categories.Db := Sources.AcronymDb;
     
    758772  Categories := TAcronymCategories.Create;
    759773  Categories.OwnsObjects := False;
     774  ResponseStream := TMemoryStream.Create;
    760775end;
    761776
    762777destructor TImportSource.Destroy;
    763778begin
     779  FreeAndNil(ResponseStream);
    764780  FreeAndNil(Categories);
    765781  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.