Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TourDataManager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill
TourDataManager
Commits
bd519fc6
Commit
bd519fc6
authored
Oct 08, 2018
by
Kirill
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Авторизация и сохранение/восстановление куков
parent
84d38e51
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
291 additions
and
27 deletions
+291
-27
Authenticator.cs
TourDataManager/Authenticator.cs
+27
-0
CookieStorage.cs
TourDataManager/CookieStorage.cs
+60
-0
Debug.cs
TourDataManager/Debug.cs
+16
-0
IAuthenticator.cs
TourDataManager/IAuthenticator.cs
+8
-0
MyUtilities.cs
TourDataManager/MyUtilities.cs
+0
-24
TourDataManager.cs
TourDataManager/TourDataManager.cs
+50
-0
TourDataManager.csproj
TourDataManager/TourDataManager.csproj
+61
-1
packages.config
TourDataManager/packages.config
+15
-0
Program.cs
TourDataManagerConsoleApplication/Program.cs
+19
-2
TourDataManagerConsoleApplication.csproj
...nsoleApplication/TourDataManagerConsoleApplication.csproj
+27
-0
packages.config
TourDataManagerConsoleApplication/packages.config
+8
-0
No files found.
TourDataManager/Authenticator.cs
0 → 100644
View file @
bd519fc6
using
System
;
using
System.Collections.Generic
;
using
System.Net.Http
;
using
Ninject
;
namespace
TourDataManager
{
public
class
Authenticator
:
IAuthenticator
{
private
readonly
Uri
authUri
=
new
Uri
(
"https://biganto.com/users/login/?client=desktopplayer&client_version=3.0&v=2.0"
);
[
Inject
]
public
HttpClient
HttpClient
{
get
;
set
;
}
public
async
void
Login
(
string
email
,
string
password
,
Action
<
bool
,
string
>
continuation
=
null
){
var
x
=
await
HttpClient
.
PostAsync
(
authUri
,
new
FormUrlEncodedContent
(
new
[]{
new
KeyValuePair
<
string
,
string
>(
"email"
,
email
),
new
KeyValuePair
<
string
,
string
>(
"password"
,
password
)
}));
var
content
=
await
x
.
Content
.
ReadAsStringAsync
();
continuation
?.
Invoke
(
x
.
IsSuccessStatusCode
,
content
);
}
public
void
Logout
(){
}
}
}
\ No newline at end of file
TourDataManager/CookieStorage.cs
0 → 100644
View file @
bd519fc6
using
System
;
using
System.IO
;
using
System.Net
;
using
System.Runtime.Serialization.Formatters.Binary
;
namespace
TourDataManager
{
public
class
CookieStorage
{
private
readonly
string
cookiePath
;
private
CookieContainer
CookieContainer
;
public
CookieStorage
(
string
cookiePath
){
this
.
cookiePath
=
cookiePath
;
}
public
CookieContainer
Get
(){
if
(
CookieContainer
!=
null
)
return
CookieContainer
;
CookieContainer
=
ReadCookiesFromDisk
(
cookiePath
);
Debug
.
Log
(
$"Count of cookies restored :
{
CookieContainer
.
Count
}
"
);
return
CookieContainer
;
}
public
void
Save
(
CookieContainer
cookieContainer
){
WriteCookiesToDisk
(
cookiePath
,
cookieContainer
);
Debug
.
Log
(
$"Count of cookies saved :
{
cookieContainer
}
"
);
}
public
void
Save
(){
Save
(
CookieContainer
);
}
public
static
void
WriteCookiesToDisk
(
string
file
,
CookieContainer
cookieJar
){
using
(
Stream
stream
=
File
.
Create
(
file
)){
try
{
Debug
.
Log
(
"Writing cookies to disk... "
);
var
formatter
=
new
BinaryFormatter
();
formatter
.
Serialize
(
stream
,
cookieJar
);
Debug
.
Log
(
"Done."
);
}
catch
(
Exception
e
)
{
Debug
.
LogError
(
"Problem writing cookies to disk: "
+
e
.
GetType
());
}
}
}
public
static
CookieContainer
ReadCookiesFromDisk
(
string
file
){
try
{
using
(
Stream
stream
=
File
.
Open
(
file
,
FileMode
.
Open
)){
Debug
.
Log
(
"Reading cookies from disk... "
);
var
formatter
=
new
BinaryFormatter
();
Debug
.
Log
(
"Done."
);
return
(
CookieContainer
)
formatter
.
Deserialize
(
stream
);
}
}
catch
(
Exception
e
)
{
Debug
.
LogError
(
"Problem reading cookies from disk: "
+
e
.
GetType
());
return
new
CookieContainer
();
}
}
}
}
\ No newline at end of file
TourDataManager/Debug.cs
0 → 100644
View file @
bd519fc6
using
System
;
namespace
TourDataManager
{
public
static
class
Debug
{
public
static
void
Log
(
object
msg
){
Console
.
WriteLine
(
msg
);
}
public
static
void
LogError
(
object
msg
){
Console
.
ForegroundColor
=
ConsoleColor
.
Red
;
Console
.
WriteLine
(
msg
);
Console
.
ResetColor
();
}
}
}
\ No newline at end of file
TourDataManager/IAuthenticator.cs
0 → 100644
View file @
bd519fc6
using
System
;
namespace
TourDataManager
{
public
interface
IAuthenticator
{
void
Login
(
string
email
,
string
password
,
Action
<
bool
,
string
>
continuation
=
null
);
void
Logout
();
}
}
\ No newline at end of file
TourDataManager/MyUtilities.cs
deleted
100644 → 0
View file @
84d38e51
namespace
TourDataManager
{
public
class
MyUtilities
{
public
int
c
;
public
void
AddValues
(
int
a
,
int
b
)
{
c
=
a
+
b
;
var
t1
=
(
1
,
2
);
var
t2
=
(
1
,
2
);
if
(
t1
==
t2
){
}
}
/// C# 7.3 feature
public
static
bool
CompareTuples
((
int
,
int
)
a
,(
int
,
int
)
b
){
return
a
==
b
;
}
public
static
int
GenerateRandom
(
int
min
,
int
max
)
{
System
.
Random
rand
=
new
System
.
Random
();
return
rand
.
Next
(
min
,
max
);
}
}
}
\ No newline at end of file
TourDataManager/TourDataManager.cs
0 → 100644
View file @
bd519fc6
using
System.Net.Http
;
using
Ninject
;
using
Ninject.Modules
;
namespace
TourDataManager
{
public
class
TourDataManager
{
private
string
persistentPath
;
private
IKernel
Container
;
public
TourDataManager
(
string
persistentPath
){
this
.
persistentPath
=
persistentPath
;
Container
=
new
StandardKernel
(
new
MyModule
(
persistentPath
));
}
public
void
Login
(
string
email
,
string
password
){
Container
.
Get
<
IAuthenticator
>().
Login
(
email
,
password
,
(
b
,
s
)
=>
{
var
cookiestor
=
Container
.
Get
<
CookieStorage
>();
Debug
.
Log
(
$"Authorization :
{
s
}
"
);
Debug
.
Log
(
$"Cookie count in storage :
{
cookiestor
.
Get
().
Count
}
"
);
cookiestor
.
Save
();
});
}
}
public
class
MyModule
:
NinjectModule
{
private
readonly
string
persistentPath
;
public
MyModule
(
string
persistentPath
){
this
.
persistentPath
=
persistentPath
;
}
public
override
void
Load
(){
var
cookieStorage
=
new
CookieStorage
(
persistentPath
+
"\\cookie.storage"
);
var
httpClientHandler
=
new
HttpClientHandler
();
//CookieContainer сам запоминает полученные из ответа куки
httpClientHandler
.
CookieContainer
=
cookieStorage
.
Get
();
var
httpClient
=
new
HttpClient
(
httpClientHandler
);
Bind
<
CookieStorage
>().
ToConstant
(
cookieStorage
).
InSingletonScope
();
Bind
<
HttpClientHandler
>().
ToConstant
(
httpClientHandler
).
InSingletonScope
();
Bind
<
HttpClient
>().
ToConstant
(
httpClient
).
InSingletonScope
();
Bind
<
IAuthenticator
>().
To
<
Authenticator
>().
InSingletonScope
();
}
}
}
\ No newline at end of file
TourDataManager/TourDataManager.csproj
View file @
bd519fc6
...
...
@@ -33,14 +33,74 @@
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"mscorlib"
/>
<Reference
Include=
"Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7"
>
<HintPath>
..\packages\Ninject.3.3.4\lib\net45\Ninject.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.ComponentModel.Composition"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.IO.4.3.0\lib\net462\System.IO.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Reactive, Version=4.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263"
>
<HintPath>
..\packages\System.Reactive.4.1.1\lib\net46\System.Reactive.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
>
<HintPath>
..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
>
<HintPath>
..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Windows"
/>
<Reference
Include=
"System.Windows.Forms"
/>
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"WindowsBase"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"MyUtilities.cs"
/>
<Compile
Include=
"Authenticator.cs"
/>
<Compile
Include=
"CookieStorage.cs"
/>
<Compile
Include=
"Debug.cs"
/>
<Compile
Include=
"IAuthenticator.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"TourDataManager.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"packages.config"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
...
...
TourDataManager/packages.config
0 → 100644
View file @
bd519fc6
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
package
id
=
"Ninject"
version
=
"3.3.4"
targetFramework
=
"net472"
/>
<
package
id
=
"System.IO"
version
=
"4.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Net.Http"
version
=
"4.3.3"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Reactive"
version
=
"4.1.1"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Runtime"
version
=
"4.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Runtime.CompilerServices.Unsafe"
version
=
"4.5.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Security.Cryptography.Algorithms"
version
=
"4.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Security.Cryptography.Encoding"
version
=
"4.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Security.Cryptography.Primitives"
version
=
"4.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Security.Cryptography.X509Certificates"
version
=
"4.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Threading.Tasks.Extensions"
version
=
"4.5.1"
targetFramework
=
"net472"
/>
<
package
id
=
"System.ValueTuple"
version
=
"4.4.0"
targetFramework
=
"net472"
/>
</
packages
>
\ No newline at end of file
TourDataManagerConsoleApplication/Program.cs
View file @
bd519fc6
...
...
@@ -3,9 +3,26 @@ using TourDataManager;
namespace
TourDataManagerConsoleApplication
{
internal
class
Program
{
const
string
PersistentPath
=
"C:\\Users\\Bigantounity\\AppData\\LocalLow\\Biganto\\StandalonePlayer"
;
const
string
defaultLogin
=
"demo@biganto.ru"
;
const
string
defaultPassword
=
"demo"
;
public
static
void
Main
(
string
[]
args
){
var
isEqual
=
MyUtilities
.
CompareTuples
((
1
,
2
),
(
1
,
2
));
Console
.
Write
(
isEqual
);
var
tourDataManager
=
new
TourDataManager
.
TourDataManager
(
PersistentPath
);
tourDataManager
.
Login
(
defaultLogin
,
defaultPassword
);
Console
.
Read
();
}
public
static
async
void
Login
(){
}
}
}
\ No newline at end of file
TourDataManagerConsoleApplication/TourDataManagerConsoleApplication.csproj
View file @
bd519fc6
...
...
@@ -33,10 +33,34 @@
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"mscorlib"
/>
<Reference
Include=
"Ninject, Version=3.3.4.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7"
>
<HintPath>
..\packages\Ninject.3.3.4\lib\net45\Ninject.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Reactive, Version=4.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263"
>
<HintPath>
..\packages\System.Reactive.4.1.1\lib\net46\System.Reactive.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
>
<HintPath>
..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
>
<HintPath>
..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
>
<HintPath>
..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Windows"
/>
<Reference
Include=
"System.Windows.Forms"
/>
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"WindowsBase"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Program.cs"
/>
...
...
@@ -48,6 +72,9 @@
<Name>
TourDataManager
</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None
Include=
"packages.config"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
TourDataManagerConsoleApplication/packages.config
0 → 100644
View file @
bd519fc6
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
package
id
=
"Ninject"
version
=
"3.3.4"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Reactive"
version
=
"4.1.1"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Runtime.CompilerServices.Unsafe"
version
=
"4.5.0"
targetFramework
=
"net472"
/>
<
package
id
=
"System.Threading.Tasks.Extensions"
version
=
"4.5.1"
targetFramework
=
"net472"
/>
<
package
id
=
"System.ValueTuple"
version
=
"4.4.0"
targetFramework
=
"net472"
/>
</
packages
>
\ No newline at end of file
Kirill
@Nobi
mentioned in issue
#1 (closed)
·
Oct 08, 2018
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment