Skip to content

Commit 2817a3d

Browse files
committed
Update rôles marche en Front,
Reste à update la BD
2 parents 20d98a3 + 72b413b commit 2817a3d

30 files changed

+1043
-117
lines changed

Diff for: Zenergy/Zenergy/App_Start/BundleConfig.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ public static void RegisterBundles(BundleCollection bundles)
2222
bundles.Add(new ScriptBundle("~/bundles/angular-resource").Include(
2323
"~/Scripts/Lib/angular-resource.min.js"));
2424

25+
bundles.Add(new ScriptBundle("~/bundles/angular-route").Include(
26+
"~/Scripts/Lib/angular-route.min.js"));
27+
28+
bundles.Add(new ScriptBundle("~/bundles/ui-bootstrap").Include(
29+
"~/Scripts/Lib/ui-bootstrap-tpls-0.14.3.min.js"));
30+
2531
bundles.Add(new ScriptBundle("~/bundles/zenergyApp")
2632
.Include("~/Scripts/zenergyApp.js")
2733
.IncludeDirectory("~/Scripts/Controllers", "*.js")
28-
.IncludeDirectory("~/Scripts/Factories", "*.js"));
34+
.IncludeDirectory("~/Scripts/Factories", "*.js")
35+
.IncludeDirectory("~/Scripts/Tools", "*.js"));
2936

3037
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
3138
"~/Scripts/Lib/bootstrap.js",

Diff for: Zenergy/Zenergy/App_Start/Startup.Auth.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public void ConfigureAuth(IAppBuilder app)
6363
appId: "429380533932654",
6464
appSecret: "ce6476f6a182519fee61ee17db94556d");
6565

66-
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
67-
//{
68-
// ClientId = "",
69-
// ClientSecret = ""
70-
//});
66+
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
67+
{
68+
ClientId = "444754422502-l5urcdutcrgoedvdtrrbbvml2boq6eg2.apps.googleusercontent.com",
69+
ClientSecret = "mzj_gvPmB-pkCca_6U1VLkBE"
70+
});
7171
}
7272
}
7373
}

Diff for: Zenergy/Zenergy/Controllers/AccountController.cs

+33-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
using Zenergy.Models;
1717
using Zenergy.Providers;
1818
using Zenergy.Results;
19+
using Zenergy.Services;
20+
using System.Net;
21+
using Newtonsoft.Json;
22+
using System.Web.Http.Results;
1923

2024
namespace Zenergy.Controllers
2125
{
@@ -25,9 +29,12 @@ public class AccountController : ApiController
2529
{
2630
private const string LocalLoginProvider = "Local";
2731
private ApplicationUserManager _userManager;
32+
private ZenergyContext db = new ZenergyContext();
33+
private UserServices userServices;
2834

2935
public AccountController()
3036
{
37+
userServices = new UserServices(db);
3138
}
3239

3340
public AccountController(ApplicationUserManager userManager,
@@ -66,6 +73,11 @@ public UserInfoViewModel GetUserInfo()
6673
};
6774
}
6875

76+
77+
/// <summary>
78+
/// Log out the current user.
79+
/// </summary>
80+
/// <returns></returns>
6981
// POST api/Account/Logout
7082
[Route("Logout")]
7183
public IHttpActionResult Logout()
@@ -318,28 +330,39 @@ public IEnumerable<ExternalLoginViewModel> GetExternalLogins(string returnUrl, b
318330
return logins;
319331
}
320332

333+
334+
/// <summary>
335+
/// Login the user.
336+
/// </summary>
337+
/// <param name="model"></param>
338+
/// <returns></returns>
321339
// POST api/Account/Register
322340
[AllowAnonymous]
323341
[Route("Register")]
324-
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
342+
[HttpPost]
343+
public async Task<IHttpActionResult> Register()
325344
{
326-
if (!ModelState.IsValid)
327-
{
328-
return BadRequest(ModelState);
329-
}
345+
var context = HttpContext.Current;
346+
var data = HttpContext.Current.Request.Form;
347+
string postData = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd();
348+
user user = JsonConvert.DeserializeObject<user>(postData);
330349

331-
var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
332350

333-
IdentityResult result = await UserManager.CreateAsync(user, model.Password);
334-
335-
if (!result.Succeeded)
351+
try {
352+
await userServices.CreateUser(user);
353+
}
354+
catch(InvalidOperationException e)
336355
{
337-
return GetErrorResult(result);
356+
context.Response.Write("Il y a eu une erreur lors de l'opération veuillez réessayer");
357+
context.Response.StatusCode = 500;
358+
return StatusCode(HttpStatusCode.InternalServerError);
338359
}
339360

340361
return Ok();
341362
}
342363

364+
365+
343366
// POST api/Account/RegisterExternal
344367
[OverrideAuthentication]
345368
[HostAuthentication(DefaultAuthenticationTypes.ExternalBearer)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Data;
5+
using System.Data.Entity;
6+
using System.Data.Entity.Infrastructure;
7+
using System.Linq;
8+
using System.Net;
9+
using System.Net.Http;
10+
using System.Threading.Tasks;
11+
using System.Web;
12+
using System.Web.Http;
13+
using System.Web.Http.Description;
14+
using Zenergy.Models;
15+
16+
namespace Zenergy.Controllers.ApiControllers
17+
{
18+
public class accessoriesController : ApiController
19+
{
20+
private ZenergyContext db = new ZenergyContext();
21+
22+
// GET: api/accessories
23+
public IQueryable<accessory> Getaccessory()
24+
{
25+
return db.accessory;
26+
}
27+
28+
// GET: api/accessories/5
29+
[ResponseType(typeof(accessory))]
30+
public async Task<IHttpActionResult> Getaccessory(int id)
31+
{
32+
accessory accessory = await db.accessory.FindAsync(id);
33+
if (accessory == null)
34+
{
35+
return NotFound();
36+
}
37+
38+
return Ok(accessory);
39+
}
40+
41+
// PUT: api/accessories/5
42+
[ResponseType(typeof(void))]
43+
public async Task<IHttpActionResult> Putaccessory(int id, accessory accessory)
44+
{
45+
if (!ModelState.IsValid)
46+
{
47+
return BadRequest(ModelState);
48+
}
49+
50+
if (id != accessory.accessoryId)
51+
{
52+
return BadRequest();
53+
}
54+
55+
db.Entry(accessory).State = EntityState.Modified;
56+
57+
try
58+
{
59+
await db.SaveChangesAsync();
60+
}
61+
catch (DbUpdateConcurrencyException)
62+
{
63+
if (!accessoryExists(id))
64+
{
65+
return NotFound();
66+
}
67+
else
68+
{
69+
throw;
70+
}
71+
}
72+
73+
return StatusCode(HttpStatusCode.NoContent);
74+
}
75+
76+
// POST: api/accessories
77+
[ResponseType(typeof(accessory))]
78+
public async Task<IHttpActionResult> Postaccessory()
79+
{
80+
var context = HttpContext.Current;
81+
var data = HttpContext.Current.Request.Form;
82+
string postData = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd();
83+
accessory accessory = JsonConvert.DeserializeObject<accessory>(postData);
84+
db.accessory.Add(accessory);
85+
await db.SaveChangesAsync();
86+
87+
return CreatedAtRoute("DefaultApi", new { id = accessory.accessoryId }, accessory);
88+
}
89+
90+
// DELETE: api/accessories/5
91+
[ResponseType(typeof(accessory))]
92+
public async Task<IHttpActionResult> Deleteaccessory(int id)
93+
{
94+
accessory accessory = await db.accessory.FindAsync(id);
95+
if (accessory == null)
96+
{
97+
return NotFound();
98+
}
99+
100+
db.accessory.Remove(accessory);
101+
await db.SaveChangesAsync();
102+
103+
return Ok(accessory);
104+
}
105+
106+
protected override void Dispose(bool disposing)
107+
{
108+
if (disposing)
109+
{
110+
db.Dispose();
111+
}
112+
base.Dispose(disposing);
113+
}
114+
115+
private bool accessoryExists(int id)
116+
{
117+
return db.accessory.Count(e => e.accessoryId == id) > 0;
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)