George Williams пре 5 година
родитељ
комит
492e41d2ef

+ 1
- 2
UnivateProperties_API/Controllers/Users/RegisterController.cs Прегледај датотеку

@@ -43,7 +43,6 @@ namespace UnivateProperties_API.Controllers.Users
43 43
         {
44 44
             var user = _Repo.Authenticate(userDto.Username, userDto.Password);
45 45
 
46
-            //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Unauthorized, "value");
47 46
 
48 47
             if (user == null)
49 48
                 return BadRequest(new { message = "Username or password is incorrect" });
@@ -55,7 +54,7 @@ namespace UnivateProperties_API.Controllers.Users
55 54
                 Subject = new ClaimsIdentity(new Claim[]
56 55
                 {
57 56
                     new Claim(ClaimTypes.Name, user.Id.ToString()),
58
-                    //new Claim(ClaimTypes.Role, user.Role)
57
+                    new Claim(ClaimTypes.Role, user.Role)
59 58
                 }),
60 59
                 Expires = DateTime.UtcNow.AddMinutes(15),
61 60
                 SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)

+ 8
- 1
UnivateProperties_API/Controllers/Users/UserController.cs Прегледај датотеку

@@ -1,13 +1,14 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Authorization;
3 3
 using Microsoft.AspNetCore.Mvc;
4
+using UnivateProperties_API.Containers.Users;
4 5
 using UnivateProperties_API.Model.Users;
5 6
 using UnivateProperties_API.Repository;
6 7
 using UnivateProperties_API.Repository.Users;
7 8
 
8 9
 namespace User_API.Controllers
9 10
 {
10
-    //[Authorize]
11
+    [Authorize]
11 12
     [Route("api/[controller]")]
12 13
     [ApiController]
13 14
     public class UserController : ControllerBase
@@ -19,6 +20,7 @@ namespace User_API.Controllers
19 20
             _Repo = repo;
20 21
         }
21 22
 
23
+        [Authorize(Roles = Role.SuperAdmin)]
22 24
         [HttpGet]
23 25
         public IActionResult Get()
24 26
         {
@@ -28,6 +30,11 @@ namespace User_API.Controllers
28 30
         [HttpGet("{id}")]
29 31
         public IActionResult Get(int id)
30 32
         {
33
+            var currentUserId = int.Parse(User.Identity.Name);
34
+            if (id != currentUserId && !User.IsInRole(Role.SuperAdmin))
35
+            {
36
+                return Forbid();
37
+            }
31 38
             return new OkObjectResult(_Repo.Get(x => x.Id == id));
32 39
         }
33 40
 

+ 1
- 1
UnivateProperties_API/Repository/Users/AgentRepository.cs Прегледај датотеку

@@ -24,7 +24,7 @@ namespace UnivateProperties_API.Repository.Users
24 24
 
25 25
         public List<Agent> GetAll()
26 26
         {
27
-            return _dbContext.Agents.ToList();
27
+            return _dbContext.Agents.Include("User").ToList();
28 28
         }
29 29
 
30 30
         public Agent GetDetailed(Func<Agent, bool> first)

+ 2
- 2
UnivateProperties_API/Repository/Users/IndividualRepository.cs Прегледај датотеку

@@ -18,12 +18,12 @@ namespace UnivateProperties_API.Repository.Users
18 18
 
19 19
         public List<Individual> Get(Func<Individual, bool> where)
20 20
         {
21
-            return _dbContext.Individuals.Where(where).ToList();
21
+            return _dbContext.Individuals.Include("User").Where(where).ToList();
22 22
         }
23 23
 
24 24
         public List<Individual> GetAll()
25 25
         {
26
-            return _dbContext.Individuals.ToList();
26
+            return _dbContext.Individuals.Include("User").ToList();
27 27
         }
28 28
 
29 29
         public Individual GetDetailed(Func<Individual, bool> first)

+ 17
- 1
UnivateProperties_API/Repository/Users/RegisterRepository.cs Прегледај датотеку

@@ -109,7 +109,7 @@ namespace UnivateProperties_API.Repository.Users
109 109
 
110 110
             User createUser = new User(individual.Username, individual.Password);
111 111
 
112
-            Create(createUser, individual.Password, save);
112
+            Create(createUser, individual.Password, false);
113 113
 
114 114
             if (personType == PersonType.Agent)
115 115
             {
@@ -144,6 +144,22 @@ namespace UnivateProperties_API.Repository.Users
144 144
             }
145 145
         }
146 146
 
147
+        //public void InsertPerson(UserDto item)
148
+        //{
149
+        //    Individual i = new Individual()
150
+        //    {
151
+        //        Name = item.Name,
152
+        //        Surname = item.Surname,
153
+        //        User = new User(item.Username, item.Password),
154
+        //        Email = item.Email,
155
+        //        CellNumber = item.CellNumber,
156
+        //        Telephone = item.Telephone
157
+        //    };
158
+
159
+        //    _dbContext.Add(i);
160
+        //    Save();
161
+        //}
162
+
147 163
         public void Update(User userParam, string password = null)
148 164
         {
149 165
             var user = _dbContext.Users.Find(userParam.Id);

Loading…
Откажи
Сачувај