source: SMSSender/gateways/Schoolnet/ACSchoolnet/ACSchoolnet.pas @ 3:9652cf89778d

2.2
Last change on this file since 3:9652cf89778d was 3:9652cf89778d, checked in by Sämy Zehnder <saemy.zehnder@…>, 10 years ago

moving all projects from language specific folder into one projects folder

File size: 4.1 KB
Line 
1unit ACSchoolnet;
2
3 {Schoolnet gateway plugin - The SMSSender-plugin for the Schoolnet platform.
4  Copyright (C) 2008-2009, gorrión. See http://www.gorrion.ch
5
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with this program.  If not, see <http://www.gnu.org/licenses/>.}
18
19interface
20
21uses
22  IniFiles,
23  Interfaces, SchoolnetInterfaces,
24  AbstractAccount, BCTypes;
25
26const
27  PWD_KEY = 'jw;d=5dkjWda[dmYq3*22_3*';
28
29type
30  TACSchoolnet = class(TAbstractLogInOutAccount, IAccount, ILogInOutAccount, ISchoolnetAccount)
31  private
32    FUsername: String;
33    FPassword: String;
34    FSendFrom: TSendFrom;
35  protected
36    function  getGateway: IGateway; override;
37
38    { IAccount }
39    procedure loadAccountFromIni(ini: TIniFile); override;
40    procedure saveAccountToIni(ini: TIniFile); override;
41
42    function  splitTextToLongSMS(text: String): TStringArray; override;
43    function  splitTextToShortSMS(text: String): TStringArray; override;
44
45    { ISchoolnetAccount}
46    function getUsername: String;
47    function getPassword: String;
48    function getSendFrom: TSendFrom;
49
50    procedure parseLoginPage(html: String);
51
52    procedure setUsername(username: String);
53    procedure setPassword(password: String);
54    procedure setSendFrom(sendFrom: TSendFrom);
55  end;
56
57implementation
58
59uses
60  SysUtils, RegExpr,
61  SZPwd,
62  GtwySchoolnet, BCSettings;
63
64procedure TACSchoolnet.parseLoginPage(html: String);
65var
66  exp: TRegExpr;
67begin
68  exp := TRegExpr.Create;
69  try
70    with exp do
71    begin
72      ModifierI  := true; {Ignore case}
73      ModifierG  := false; {Non-Greedy - necessary, no idea why, but otherwise it wont find the substrings correctly}
74
75      Expression := '<span id="userSnPoints"><b>(\d*)</b></span>';
76      if not Exec(html) then
77        raise Exception.Create('Can not fetch the free sms count!');
78
79      setFreeSMSCount(StrToInt(Match[1]));
80    end;
81  finally
82    exp.Free;
83  end;
84end;
85
86function TACSchoolnet.getGateway: IGateway;
87begin
88  Result := TGtwySchoolnet.getInstance;
89end;
90
91procedure TACSchoolnet.loadAccountFromIni(ini: TIniFile);
92begin
93  inherited;
94
95  setUsername(ini.ReadString(getAccountId, 'username', ''));
96  setPassword(mapPassword(ini.ReadString(getAccountId, 'password', ''), PWD_KEY));
97  setSendFrom(StrToSendFrom(ini.ReadString(getAccountId, 'sendFrom', sendFromStr[sfMobileNo])));
98end;
99
100procedure TACSchoolnet.saveAccountToIni(ini: TIniFile);
101begin
102  inherited;
103
104  ini.WriteString(getAccountId, 'username', FUsername);
105  ini.WriteString(getAccountId, 'password', '"' + makePassword(FPassword, PWD_KEY).code + '"');
106  ini.WriteString(getAccountId, 'sendFrom', SendFromStr[FSendFrom]);
107end;
108
109function TACSchoolnet.splitTextToLongSMS(text: String): TStringArray;
110begin
111  Result := (getGateway as ISchoolnetGateway).splitTextToLongSMS(text);
112end;
113function TACSchoolnet.splitTextToShortSMS(text: String): TStringArray;
114begin
115  Result := (getGateway as ISchoolnetGateway).splitTextToShortSMS(text);
116end;
117
118function TACSchoolnet.getUsername: String;
119begin
120  Result := FUsername;
121end;                                                           
122function TACSchoolnet.getPassword: String;
123begin
124  Result := FPassword;
125end;
126function TACSchoolnet.getSendFrom: TSendFrom;
127begin
128  Result := FSendFrom;
129end;
130
131procedure TACSchoolnet.setUsername(username: String);
132begin
133  FUsername := username;
134end;
135procedure TACSchoolnet.setPassword(password: String);
136begin
137  FPassword := password;
138end;
139procedure TACSchoolnet.setSendFrom(sendFrom: TSendFrom);
140begin
141  FSendFrom := sendFrom;
142end;
143
144end.
Note: See TracBrowser for help on using the repository browser.