refabrique : une librairie serveur
This commit is contained in:
parent
5785cf72b1
commit
4df7ef7f4b
25 changed files with 457 additions and 86 deletions
|
|
@ -1,18 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Json;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Server.Helpers;
|
||||
using Yavsc.Server.Model;
|
||||
|
||||
namespace testOauthClient.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
ILogger _logger;
|
||||
|
||||
public HomeController(ILoggerFactory loggerFactory)
|
||||
{
|
||||
_logger=loggerFactory.CreateLogger<HomeController>();
|
||||
|
|
@ -39,6 +45,45 @@ namespace testOauthClient.Controllers
|
|||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostFiles(string subdir)
|
||||
{
|
||||
string results = null;
|
||||
_logger.LogInformation($"{Request.Form.Files.Count} file(s) to send");
|
||||
|
||||
// TODO better uri construction in production environment
|
||||
List<FormFile> args = new List<FormFile>();
|
||||
foreach (var formFile in Request.Form.Files)
|
||||
{
|
||||
_logger.LogWarning($"Treating {formFile.ContentDisposition}");
|
||||
var memStream = new MemoryStream();
|
||||
const int sz = 1024*64;
|
||||
byte [] buffer = new byte[sz];
|
||||
using (var innerStream = formFile.OpenReadStream()) {
|
||||
int szRead = 0;
|
||||
do {
|
||||
szRead = innerStream.Read(buffer,0,sz);
|
||||
memStream.Write(buffer,0,szRead);
|
||||
} while (szRead>0);
|
||||
}
|
||||
memStream.Seek(0,SeekOrigin.Begin);
|
||||
args.Add(
|
||||
new FormFile {
|
||||
ContentDisposition = formFile.ContentDisposition,
|
||||
ContentType = formFile.ContentType,
|
||||
Stream = memStream
|
||||
});
|
||||
}
|
||||
string uri = "http://dev.pschneider.fr/api/fs/"+System.Uri.EscapeDataString(subdir);
|
||||
_logger.LogInformation($"Posting data to '{uri}'...");
|
||||
|
||||
results = await RequestHelper.PostMultipart(uri, args.ToArray(), AccessToken);
|
||||
_logger.LogInformation("Data posted.");
|
||||
|
||||
return View("Index", model: results);
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostDeviceInfo(CancellationToken cancellationToken)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -112,12 +112,15 @@ namespace testOauthClient
|
|||
string email = null;
|
||||
if (emails !=null)
|
||||
email = emails.First?.Value<string>();
|
||||
context.Identity.AddClaim(
|
||||
new Claim( ClaimTypes.NameIdentifier,identifier));
|
||||
context.Identity.AddClaim(
|
||||
new Claim( ClaimTypes.Name,givenName));
|
||||
context.Identity.AddClaim(
|
||||
new Claim( ClaimTypes.Email,email));
|
||||
if (identifier!=null)
|
||||
context.Identity.AddClaim(
|
||||
new Claim( ClaimTypes.NameIdentifier,identifier));
|
||||
if (givenName!=null)
|
||||
context.Identity.AddClaim(
|
||||
new Claim( ClaimTypes.Name,givenName));
|
||||
if (email!=null)
|
||||
context.Identity.AddClaim(
|
||||
new Claim( ClaimTypes.Email,email));
|
||||
// TODO add all emails and roles
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@
|
|||
<h3>@ViewData["Message"]</h3>
|
||||
|
||||
<address>
|
||||
One Microsoft Way<br />
|
||||
Redmond, WA 98052-6399<br />
|
||||
<abbr title="Phone">P:</abbr>
|
||||
425.555.0100
|
||||
Paul Schneider<br />
|
||||
<abbr title="Adresse postale">A:</abbr> Boulevard Aristide Briand - 92150 Suresnes
|
||||
<abbr title="Mobile">M:</abbr> 336 51 14 15 64
|
||||
</address>
|
||||
|
||||
<address>
|
||||
<strong>Support:</strong> <a href="mailto:Support@example.com">Support@example.com</a><br />
|
||||
<strong>Marketing:</strong> <a href="mailto:Marketing@example.com">Marketing@example.com</a>
|
||||
<strong>Support:</strong> <a href="mailto:contact@pschneider.fr">contact@pschneider.fr</a><br />
|
||||
<strong>Marketing:</strong> <a href="mailto:paul@pschneider.fr">paul@pschneider.fr</a>
|
||||
</address>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
}
|
||||
</p>
|
||||
|
||||
if (!string.IsNullOrEmpty(Model)) {
|
||||
if (Model!=null) {
|
||||
<h3>Message received from the resource controller: @Model</h3>
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +22,10 @@
|
|||
<form action="~/Home/PostDeviceInfo" method="post">
|
||||
<button class="btn btn-lg btn-warning" type="submit">Post device info</button>
|
||||
</form>
|
||||
<form action="~/Home/PostFiles/?subdir=test" method="post" enctype="multipart/form-data">
|
||||
Envoyer vers le dossier "test" <input type="file" name="file" multiple/>
|
||||
<button class="btn btn-lg btn-warning" type="submit">Post files</button>
|
||||
</form>
|
||||
|
||||
<a class="btn btn-lg btn-danger" href="/signout">Sign out</a>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"licence": "GNU GPL",
|
||||
"name": "testOauthClient",
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-concat": "2.5.2",
|
||||
"gulp-cssmin": "0.1.7",
|
||||
"gulp-uglify": "1.2.0",
|
||||
"rimraf": "2.2.8"
|
||||
}
|
||||
}
|
||||
"licence": "GNU GPL v3",
|
||||
"name": "test-oauth-client",
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-concat": "^2.6.1",
|
||||
"gulp-cssmin": "^0.2.0",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,11 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Yavsc.Abstract": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
"Yavsc.Server": {
|
||||
"target": "project",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
|
||||
|
|
@ -32,9 +37,10 @@
|
|||
"frameworks": {
|
||||
"dnx451": {
|
||||
"dependencies": {
|
||||
"System.Json": "4.0.0"
|
||||
"System.Json": "4.0.20126.16343"
|
||||
}
|
||||
}
|
||||
},
|
||||
"net451": {}
|
||||
},
|
||||
"exclude": [
|
||||
"wwwroot",
|
||||
|
|
@ -56,4 +62,4 @@
|
|||
"gulp min"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue