wip social

main
Paul Schneider 9 years ago
parent cdad8a558f
commit 5298431cc7
9 changed files with 245 additions and 50 deletions

@ -0,0 +1,147 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Yavsc.Model;
using Yavsc.Models;
namespace Yavsc.Controllers
{
[Produces("application/json")]
[Route("api/ContactsApi")]
public class ContactsApiController : Controller
{
private ApplicationDbContext _context;
public ContactsApiController(ApplicationDbContext context)
{
_context = context;
}
// GET: api/ContactsApi
[HttpGet]
public IEnumerable<ClientProviderInfo> GetClientProviderInfo()
{
return _context.ClientProviderInfo;
}
// GET: api/ContactsApi/5
[HttpGet("{id}", Name = "GetClientProviderInfo")]
public IActionResult GetClientProviderInfo([FromRoute] string id)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
ClientProviderInfo clientProviderInfo = _context.ClientProviderInfo.Single(m => m.UserId == id);
if (clientProviderInfo == null)
{
return HttpNotFound();
}
return Ok(clientProviderInfo);
}
// PUT: api/ContactsApi/5
[HttpPut("{id}")]
public IActionResult PutClientProviderInfo(string id, [FromBody] ClientProviderInfo clientProviderInfo)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
if (id != clientProviderInfo.UserId)
{
return HttpBadRequest();
}
_context.Entry(clientProviderInfo).State = EntityState.Modified;
try
{
_context.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!ClientProviderInfoExists(id))
{
return HttpNotFound();
}
else
{
throw;
}
}
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
}
// POST: api/ContactsApi
[HttpPost]
public IActionResult PostClientProviderInfo([FromBody] ClientProviderInfo clientProviderInfo)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
_context.ClientProviderInfo.Add(clientProviderInfo);
try
{
_context.SaveChanges();
}
catch (DbUpdateException)
{
if (ClientProviderInfoExists(clientProviderInfo.UserId))
{
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
}
else
{
throw;
}
}
return CreatedAtRoute("GetClientProviderInfo", new { id = clientProviderInfo.UserId }, clientProviderInfo);
}
// DELETE: api/ContactsApi/5
[HttpDelete("{id}")]
public IActionResult DeleteClientProviderInfo(string id)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
ClientProviderInfo clientProviderInfo = _context.ClientProviderInfo.Single(m => m.UserId == id);
if (clientProviderInfo == null)
{
return HttpNotFound();
}
_context.ClientProviderInfo.Remove(clientProviderInfo);
_context.SaveChanges();
return Ok(clientProviderInfo);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_context.Dispose();
}
base.Dispose(disposing);
}
private bool ClientProviderInfoExists(string id)
{
return _context.ClientProviderInfo.Count(e => e.UserId == id) > 0;
}
}
}

@ -19,64 +19,89 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Security.Claims;
using System.Security.Principal;
using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR;
using System; using System.Collections.Generic;
// using Microsoft.AspNet.Authorization; using System.Linq;
namespace Yavsc namespace Yavsc
{ {
public class ChatHub : Hub public class ChatHub : Hub
{
public override Task OnConnected()
{ {
bool isAuth = false; public override Task OnConnected()
string userId = null; {
if (Context.User!=null) { bool isAuth = false;
isAuth = Context.User.Identity.IsAuthenticated; string userId = null;
userId = Context.User.Identity.Name; if (Context.User != null)
var group = isAuth ? {
"authenticated":"anonymous"; isAuth = Context.User.Identity.IsAuthenticated;
// Log ("Cx: " + group); userId = Context.User.Identity.Name;
Groups.Add(Context.ConnectionId, group); var group = isAuth ?
} else Groups.Add(Context.ConnectionId, "anonymous"); "authenticated" : "anonymous";
// Log ("Cx: " + group);
Groups.Add(Context.ConnectionId, group);
}
else Groups.Add(Context.ConnectionId, "anonymous");
Clients.Group("authenticated").notify("connected", Context.ConnectionId, userId); Clients.Group("authenticated").notify("connected", Context.ConnectionId, userId);
return base.OnConnected ();
}
public override Task OnDisconnected (bool stopCalled)
{
string userId = Context.User?.Identity.Name;
Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userId);
return base.OnDisconnected (stopCalled);
}
public override Task OnReconnected () list.Add(new UserInfo
{ {
return base.OnReconnected (); ConnectionId = Context.ConnectionId,
} UserName = userId
});
public void Send(string name, string message) return base.OnConnected();
{ }
string uname = (Context.User!=null) ? public override Task OnDisconnected(bool stopCalled)
$"[{Context.User.Identity.Name}]": {
$"(anony{name})"; string userId = Context.User?.Identity.Name;
Clients.All.addMessage(uname,message); Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userId);
} list.Remove(list.Single(c=>c.ConnectionId==Context.ConnectionId));
return base.OnDisconnected(stopCalled);
}
public override Task OnReconnected()
{
return base.OnReconnected();
}
public void Send(string name, string message)
{
string uname = (Context.User != null) ?
$"[{Context.User.Identity.Name}]" :
$"(anony{name})";
Clients.All.addMessage(uname, message);
}
[Authorize]
public void SendPV (string connectionId, string message) [Authorize]
{ public void SendPV(string connectionId, string message)
var sender = Context.User.Identity.Name; {
// TODO personal black|white list + var sender = Context.User.Identity.Name;
// Contact list allowed only + // TODO personal black|white list +
// only pro // Contact list allowed only +
var hubCxContext = Clients.User(connectionId); // only pro
var cli = Clients.Client(connectionId); var hubCxContext = Clients.User(connectionId);
cli.addPV(sender,message); var cli = Clients.Client(connectionId);
} cli.addPV(sender, message);
} }
public class UserInfo
{
public string ConnectionId { get; set; }
public string UserId { get; set; }
public string UserName { get; set; }
}
static List<UserInfo> list = new List<UserInfo>();
[Authorize]
public IEnumerable<UserInfo> GetUserList()
{
return list;
}
}
} }

@ -1,7 +1,6 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;

@ -12,6 +12,7 @@ using Yavsc.Models.OAuth;
using Yavsc.Models.Workflow; using Yavsc.Models.Workflow;
using Yavsc.Models.Identity; using Yavsc.Models.Identity;
using Yavsc.Models.Market; using Yavsc.Models.Market;
using Yavsc.Model;
namespace Yavsc.Models namespace Yavsc.Models
{ {
@ -182,5 +183,7 @@ namespace Yavsc.Models
public DbSet<EstimateTemplate> EstimateTemplates { get; set; } public DbSet<EstimateTemplate> EstimateTemplates { get; set; }
public DbSet<Contact> Contacts { get; set; } public DbSet<Contact> Contacts { get; set; }
public DbSet<ClientProviderInfo> ClientProviderInfo { get; set; }
} }
} }

@ -0,0 +1,10 @@
namespace Yavsc.Model.Chat
{
public class Connection
{
public string ConnectionID { get; set; }
public string UserAgent { get; set; }
public bool Connected { get; set; }
}
}

@ -4,6 +4,7 @@ using Microsoft.AspNet.Identity.EntityFramework;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models.Identity; using Yavsc.Models.Identity;
using Yavsc.Model.Chat;
namespace Yavsc.Models namespace Yavsc.Models
{ {
@ -53,6 +54,9 @@ namespace Yavsc.Models
[InverseProperty("DeviceOwner")] [InverseProperty("DeviceOwner")]
public virtual List<GoogleCloudMobileDeclaration> Devices { get; set; } public virtual List<GoogleCloudMobileDeclaration> Devices { get; set; }
public ICollection<Connection> Connections { get; set; }
/// <summary> /// <summary>
/// User's circles /// User's circles
/// </summary> /// </summary>

@ -1,14 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Yavsc.Model namespace Yavsc.Model
{ {
public class ClientProviderInfo public class ClientProviderInfo
{ {
public string UserName { get; set; } public string UserName { get; set; }
public string Avatar { get; set; } public string Avatar { get; set; }
[Key]
public string UserId { get; set; } public string UserId { get; set; }
public int Rate { get; set; } public int Rate { get; set; }
public string EMail { get; set; } public string EMail { get; set; }
public string Phone { get; set; } public string Phone { get; set; }
public Location BillingAddress { get; set; } public Location BillingAddress { get; set; }
public string ChatHubConnectionId { get; set; }
} }
} }

@ -49,6 +49,7 @@
<li><a asp-controller="Home" asp-action="Index" class="navbar-link">@SR["Home"]</a></li> <li><a asp-controller="Home" asp-action="Index" class="navbar-link">@SR["Home"]</a></li>
<li><a asp-controller="Blogspot" asp-action="Index" class="navbar-link">@SR["Blogs"]</a></li> <li><a asp-controller="Blogspot" asp-action="Index" class="navbar-link">@SR["Blogs"]</a></li>
<li><a asp-controller="Home" asp-action="About" class="navbar-link">@SR["About"] @SiteSettings.Value.Title</a> </li> <li><a asp-controller="Home" asp-action="About" class="navbar-link">@SR["About"] @SiteSettings.Value.Title</a> </li>
<li><a asp-controller="Home" asp-action="Chat" class="navbar-link">@SR["Chat"]</a></li>
<li><a asp-controller="Home" asp-action="Contact" class="navbar-link">@SR["Contact"]</a></li> <li><a asp-controller="Home" asp-action="Contact" class="navbar-link">@SR["Contact"]</a></li>
</ul> </ul>
@await Html.PartialAsync("_LoginPartial") @await Html.PartialAsync("_LoginPartial")

@ -30,6 +30,8 @@
<li> @SR["Uses the mobile application, and receives push notifications"] <li> @SR["Uses the mobile application, and receives push notifications"]
</li> </li>
} }
</ul> </ul>
<button id="btnAddUser">Ajouter aux contacts</button>
} }
</div> </div>

Loading…