Develop and Download Open Source Software

Browse Subversion Repository

Contents of /NicoVitanD_Login.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations) (download) (as text)
Mon Oct 20 03:46:34 2014 UTC (9 years, 6 months ago) by arigayas
File MIME type: text/x-pascal
File size: 8672 byte(s)
ListViewを仮想モードで使うようにする前のバージョンをコミットしておく。
このコミットで必要なpas/dfmファイルは
* NIcoVitanD_setting
* NicoVitanD_Login
* NicoVitanD_pas
* ProgramInfoTabDlg
とプロジェクトファイルは
* NIcoVitanD.dpr
* NIcoVitanD.dproj
である。
1 unit NicoVitanD_Login;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, RegularExpressions, IniFiles, ExtCtrls, IdIOHandler,
8 IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL,
9 IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
10 IWURLResponderBase, IWURLResponder, xmldom, XMLIntf, msxmldom, XMLDoc,
11 IdCookieManager,Filectrl,ShlObj;
12
13 type
14 TLoginForm = class(TForm)
15 LoginOkBtn: TButton;
16 GroupBox1: TGroupBox;
17 GroupBox2: TGroupBox;
18 LoginCancelBtn: TButton;
19 BrowserChoiceCBox: TComboBox;
20 CookieButton: TButton;
21 ErrorLbl: TLabel;
22 MailEdit: TLabeledEdit;
23 PasswordEdit: TLabeledEdit;
24 IdHTTP1: TIdHTTP;
25 IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
26 BrowserInfo: TLabel;
27 Memo1: TMemo;
28 XMLDocument1: TXMLDocument;
29 IdCookieManager1: TIdCookieManager;
30 procedure LoginCancelBtnClick(Sender: TObject);
31 procedure LoginOkBtnClick(Sender: TObject);
32 procedure FormCreate(Sender: TObject);
33 procedure PasswordEditChange(Sender: TObject);
34 procedure CookieButtonClick(Sender: TObject);
35 procedure BrowserChoiceCBoxChange(Sender: TObject);
36 procedure MozillaCookies(SoftName:string);
37 private
38 { Private ���� }
39 public
40 { Public ���� }
41 end;
42
43 var
44 LoginForm: TLoginForm;
45 LoginMail: string;
46 LoginPass: ShortString;
47
48
49
50 implementation
51
52 {$R *.dfm}
53
54 uses HTTPApp, IdGlobalProtocols;
55
56
57 procedure TLoginForm.BrowserChoiceCBoxChange(Sender: TObject);
58 begin
59 CookieButton.SetFocus; // �g�����������������t�H�[�J�X������
60 end;
61
62 // �u���E�U�[(Cookie)���I��
63 procedure TLoginForm.CookieButtonClick(Sender: TObject);
64 var
65 BrowserNum : ShortInt;
66 val : string;
67 begin
68 // BrowserChoiceCBox ���I���������������o case���H
69 BrowserNum := BrowserChoiceCBox.ItemIndex;
70 case BrowserNum of
71 0 : ShowMessage('Internet Explorer �����������\��'); // Internet Explorer ������
72 1 : begin
73 ShowMessage('Firefox ���I������������'); // Firefox ������
74 ShowMessage('Firefox2 ���I������������');
75 end;
76 2 : ShowMessage('SeaMonkey ���I������������'); // SeaMonkey ������
77 3 : ShowMessage('Opera �����������\��'); // Opera ������
78 4 : ShowMessage('Google Chrome �����������\��'); // Google Chrome ������
79 else
80 begin
81 ShowMessage('�����I��������������');
82 end;
83 end;
84
85 val := BrowserChoiceCBox.Items[BrowserChoiceCBox.ItemIndex];
86 ShowMessage(val);
87
88
89
90 // close;
91 end;
92
93 procedure TLoginForm.FormCreate(Sender: TObject); // ���O�C���t�H�[����������������
94 var
95 Ini: TIniFile;
96
97 begin
98 LoginOkBtn.Enabled := False; // �uOK�v��������
99 ErrorLbl.Caption := ''; // ���\��
100 BrowserInfo.Caption := '';
101
102 // ini�t�@�C���������A�h������������
103 Ini := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
104 try
105 MailEdit.Text := ini.ReadString('Login','Mail', LoginMail);
106 PasswordEdit.Text := ini.ReadString('Login','Pass', LoginPass);
107 finally
108 Ini.Free;
109 end;
110
111 end;
112
113 procedure TLoginForm.LoginCancelBtnClick(Sender: TObject);
114 begin
115
116 // �����t�@�C�������[���A�h���X������������������������������
117 if MailEdit.Text = '' then
118 MailEdit.Text := ''
119 else
120 PasswordEdit.Text := '';
121 Close;
122 end;
123
124 procedure TLoginForm.LoginOkBtnClick(Sender: TObject); // ���C������
125 var
126 Ini: TIniFile;
127
128 ResStrm: TMemoryStream;
129 PostData: TStringList;
130 url : string;
131
132 LoginApi_A : IXMLNodeList;
133 LoginApi_B : IXMLNodeList;
134 tickets : string;
135
136 I : int8;
137 begin
138 LoginMail := MailEdit.Text;
139 LoginPass := PasswordEdit.Text;
140 // ErrorLbl.Caption := '';
141 // ErrorLbl.Caption :='���O�C���o�������e�X�g��';
142
143 if ((LoginMail = '') or (LoginPass = '')) then
144 begin
145 ShowMessage('���[���A�h���X �� �p�X���[�h������������');
146 end;
147 LoginOkBtn.Enabled := True;
148
149
150 // ���K�\���� http://catbot.net/blog/2007/06/re_php.html ��Ethna����
151 begin
152 if (TRegEx.IsMatch(LoginMail, '.+@(([a-z0-9_\-])+\.)+[a-z]{2,6}$')) then
153
154 // �T�[�o�������A�h���p�X��������������ID���e�X�g�����B
155 begin
156 ResStrm := TMemoryStream.Create;
157 PostData := TStringList.Create;
158 url := 'https://secure.nicovideo.jp/secure/login?site=nicolive_antenna';
159
160 PostData.Add('mail=' + HTTPEncode(LoginMail)); // Post �f�[�^���i�[
161 PostData.Add('password=' + LoginPass);
162
163 try
164 IdHTTP1.Post(url, PostData, ResStrm);
165 XMLDocument1.LoadFromStream(ResStrm, xetUTF_8);
166 LoginApi_A := XMLDocument1.DocumentElement.ChildNodes;
167
168 if LoginApi_A.Get(0).ChildNodes.First.ParentNode.NodeName='ticket' then
169 begin { TODO : ���O�C�������������� }
170
171 Memo1.Lines.Add(LoginApi_A.Get(0).ChildNodes.First.ParentNode.NodeValue); // nicolive_antenna_[����]
172 Memo1.Lines.Add('-----------------');
173
174 url := 'http://live.nicovideo.jp/api/getalertstatus';
175 PostData.Free;
176 // ResStrm.Free; // Free ������xml������������
177 tickets := LoginApi_A.Get(0).ChildNodes.First.ParentNode.NodeValue;
178
179 PostData.Add('ticket=' + tickets); // nicolive_antenna_[����]�t�^
180 { TODO : �F��API����2 ���i�K��try�`except ���L�q���������������k�B
181 �@�@�@�@ �T�[�o���������D���������������B
182 �@�@�@�@ }
183
184 IdHTTP1.Post(url, PostData, ResStrm);
185 Memo1.Lines.Add(IdHTTP1.Response.ResponseText);
186 ResStrm.Position:=0;
187 Memo1.Lines.LoadFromStream(ResStrm, TEncoding.UTF8);
188
189 XMLDocument1.LoadFromStream(ResStrm, xetUTF_8); // �G���[����
190 Memo1.Lines.Add(IdHTTP1.Response.ResponseText);
191 // LoginApi_B := XMLDocument1.DocumentElement.ChildNodes;
192 // LoginApi_A := LoginApi_A.Last.AddChild(LoginApi_B);
193 //// for I := 0 to LoginApi_B.Count - 1 do
194 // begin
195 // Memo1.Lines.Add(LoginApi_A.Get(0).ChildNodes.Last.NodeName); // nicolive_antenna_[����]
196 //
197 // end;
198 //
199 end
200 else
201 begin // �R�l�N�V���������������������O�C�����s��������
202 ShowMessage('���[���A�h���X �� �p�X���[�h�������������������B');
203 ErrorLbl.Caption :='���O�C�����s';
204 end;
205
206 except on E: EIdHTTPProtocolException do
207 begin
208 if IdHTTP1.ResponseCode = 302 then
209 IdHTTP1.Post(IdHTTP1.Response.Location, ResStrm);
210 end;
211 end;
212
213 // ResStrm.Position:=0; // �f�[�^�����u����
214 // Memo1.Lines.LoadFromStream(ResStrm, TEncoding.UTF8);
215 // Memo1.Lines.Add(IdHTTP1.Response.ResponseText);
216
217
218
219 if IdHTTP1.Connected then IdHTTP1.Disconnect;
220 // FreeAndNil(PostData);
221 FreeAndNil(ResStrm);
222 PostData.Free;
223
224 // ���[���A�h���X���p�X���[�h�� ini�t�@�C�� �������B
225 Ini := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
226 try
227 Ini.WriteString('Login','Mail',LoginMail);
228 Ini.WriteString('Login','Pass',LoginPass); { TODO : INI�t�@�C�����������������A�����A�h�������������B }
229
230 finally
231 Ini.Free;
232 end;
233 end
234
235 else
236 begin
237 ShowMessage('���������[���A�h���X���������������B');
238 ErrorLbl.Caption :='�h���C����NG';
239 end;
240 end;
241 end;
242
243
244 //�p�X���[�h�����������������uOK�v�{�^�����L�����B
245 procedure TLoginForm.PasswordEditChange(Sender: TObject);
246 var
247 n : Byte;
248 begin
249 n := Length(WideString(PasswordEdit.Text));
250 if (n < 8) or (n >= 17)then
251 begin
252 LoginOkBtn.Enabled := False;
253 end
254
255 else
256 begin
257 LoginOkBtn.Enabled := True;
258 end;
259
260 end;
261
262
263 procedure TLoginForm.MozillaCookies(SoftName:string); // ShlObj
264 var
265 ProfilesDir, SelectFolder : string;
266 begin
267 ProfilesDir := '::' + GUIDToString(CLSID_MyComputer);
268 // ProfilesDir := '::' + GUIDToString(CSIDL_APPDATA);
269 if SelectDirectory('���������t�H���_���I��',ProfilesDir,SelectFolder) then
270 end;
271
272 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26