- Регистрация
- 27 Апр 2015
- Сообщения
- 79
- Баллы
- 60
Сделал авторизацию на сайте под Joomla 3. Авторизация проходит через раз. Подскажите пожалуйста где я накосячил.
Код:
unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,
Dialogs, StdCtrls, sLabel, sButton, sEdit, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, ShellAPI,inifiles,
sCheckBox;
type
TAvtoriz_Form = class(TForm)
sEdit1: TsEdit;
sEdit2: TsEdit;
sButton1: TsButton;
sButton2: TsButton;
sLabel1: TsLabel;
sLabel2: TsLabel;
sLabel3: TsLabel;
sLabel4: TsLabel;
IdHTTP1: TIdHTTP;
Memo1: TMemo;
sButton3: TsButton;
sCheckBox1: TsCheckBox;
procedure sButton2Click(Sender: TObject);
procedure sButton1Click(Sender: TObject);
procedure sButton3Click(Sender: TObject);
procedure sCheckBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
tavtoriz = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
var
Avtoriz_Form: TAvtoriz_Form;
code, token:string;
avtoriz:tavtoriz;
myreturn, mycbsecuritym3, my1, bufer: string;
optin2:TIniFile;
implementation
uses Unit1, Unit2;
{$R *.dfm}
procedure tavtoriz.Execute;
var
stream:TStringList;
str: TStringList;
begin
try
Avtoriz_Form.IdHTTP1.Request.AcceptCharSet := 'windows-1251';
str := TStringList.Create;
stream:=TStringList.Create;
myreturn := Utf8ToAnsi(Avtoriz_Form.IdHTTP1.Get('http://as-1w.ru/cb-profile/login'));
code:=Avtoriz_Form.IdHTTP1.Post('http://as-1w.ru/cb-profile/login',stream);
Delete(myreturn, 1, Pos('name="return" value="', myreturn) + 20);
bufer := myreturn;
Delete(myreturn, Pos('" />', myreturn), Length(myreturn));
my1 := bufer;
Delete(my1, 1, Pos('name=', my1) + 5);
Delete(my1, Pos('"', my1), Length(my1));
myreturn := 'return=' + myreturn;
my1 := my1 + '=1';
if Pos('"cbsecuritym3"',code)<> 0 then
begin
token:=Copy(code,Pos('"cbsecuritym3"',code),76);
Delete(token,1,22);
Avtoriz_Form.Memo1.Lines.Add('cbsecuritym3='+token);
// ---------------------------------------------------------------------------------
str.Add('username=' + Avtoriz_Form.sEdit1.text);
str.Add('passwd=' + Avtoriz_Form.sEdit2.text);
str.Add(myreturn);
str.Add('cbsecuritym3=' + token);
str.Add(my1);
end;
Avtoriz_Form.IdHTTP1.HandleRedirects:=True;
bufer := Avtoriz_Form.IdHTTP1.Post('http://as-1w.ru/cb-profile/login', str);
bufer := Utf8ToAnsi(Avtoriz_Form.IdHTTP1.Get('http://as-1w.ru/cb-profile/login'));
if Pos('Выход', bufer) > 1 then
begin
ShowMessage('Здорова '+Avtoriz_Form.sEdit1.Text);
end
else
begin
ShowMessage('Проверьте логин\пароль'); //
end;
except
on e:Exception do
begin
str.Free;
stream.Free;
Exit;
end;
end;
end;
procedure TAvtoriz_Form.sButton2Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TAvtoriz_Form.sButton1Click(Sender: TObject);
begin
avtoriz:=tavtoriz.Create(False);
end;
procedure TAvtoriz_Form.sButton3Click(Sender: TObject);
begin
ShellExecute (Avtoriz_Form.Handle, nil, 'http://as-1w.ru/component/comprofiler/registers', nil, nil, SW_RESTORE);
end;
procedure TAvtoriz_Form.sCheckBox1Click(Sender: TObject);
begin
if sCheckBox1.Checked=true then
begin
sEdit2.PasswordChar:=#0 ;
end else
begin
sEdit2.PasswordChar:='*' ;
end;
end;
end.