Skip to content

Commit 8c474e9

Browse files
damienmoulardClement-Roque
authored andcommitted
findByMail
1 parent 2027f19 commit 8c474e9

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

Diff for: Zenergy/Zenergy/Controllers/ApiControllers/usersController.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public IQueryable<user> Getuser()
3232
}
3333

3434
// GET: api/users/5
35+
//[Authorize(Roles = "Admin")]
3536
[ResponseType(typeof(user))]
3637
public async Task<IHttpActionResult> Getuser(int id)
3738
{
@@ -44,12 +45,26 @@ public async Task<IHttpActionResult> Getuser(int id)
4445
return Ok(user);
4546
}
4647

48+
[Route("api/users/findByMail")]
49+
[HttpGet]
50+
[ResponseType(typeof(user))]
51+
public async Task<IHttpActionResult> findByMail(string userMail)
52+
{
53+
user user = await userServices.findByMail(userMail);
54+
if (user == null)
55+
{
56+
return NotFound();
57+
}
58+
59+
return Ok(user);
60+
}
61+
4762
// GET: api/users/findByRole
4863
// Return all the users of a role
4964
[Route("api/users/findByRole")]
5065
[HttpGet]
5166
[ResponseType(typeof(user[]))]
52-
public async Task<IHttpActionResult> FindByRole(string role) {
67+
public async Task<IHttpActionResult> findByRole(string role) {
5368
user[] users = null;
5469

5570
if (role == "Administrator")

Diff for: Zenergy/Zenergy/Providers/ApplicationOAuthProvider.cs

+17
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner
5151
identity.AddClaim(new Claim("mail", context.UserName));
5252
identity.AddClaim(new Claim("role", "user"));
5353
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
54+
/*
55+
if (user.member != null)
56+
{
57+
identity.AddClaim(new Claim(ClaimTypes.Role, "Member"));
58+
}
59+
if (user.contributor != null)
60+
{
61+
identity.AddClaim(new Claim(ClaimTypes.Role, "Contributor"));
62+
}
63+
if (user.manager != null)
64+
{
65+
identity.AddClaim(new Claim(ClaimTypes.Role, "Manager"));
66+
}
67+
if (user.admin != null)
68+
{
69+
identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
70+
} */
5471

5572
AuthenticationProperties properties = CreateProperties(user.mail);
5673
AuthenticationTicket ticket = new AuthenticationTicket(identity, properties);

Diff for: Zenergy/Zenergy/Services/UserServices.cs

+13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@ public async Task<user> findByMailAndPassword(string userMail, string userPass)
5353
System.Diagnostics.Debug.WriteLine(e.StackTrace);
5454
return null;
5555
}
56+
}
5657

58+
public async Task<user> findByMail(string userMail)
59+
{
60+
try
61+
{
62+
user user = await db.user.Where(u => u.mail == userMail).FirstAsync();
63+
return user;
64+
}
65+
catch (Exception e)
66+
{
67+
System.Diagnostics.Debug.WriteLine(e.StackTrace);
68+
return null;
69+
}
5770
}
5871

5972
public async Task CreateUser(user u)

0 commit comments

Comments
 (0)