George Williams 5 gadus atpakaļ
vecāks
revīzija
492e41d2ef

+ 1
- 2
UnivateProperties_API/Controllers/Users/RegisterController.cs Parādīt failu

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

+ 8
- 1
UnivateProperties_API/Controllers/Users/UserController.cs Parādīt failu

1
 using System.Transactions;
1
 using System.Transactions;
2
 using Microsoft.AspNetCore.Authorization;
2
 using Microsoft.AspNetCore.Authorization;
3
 using Microsoft.AspNetCore.Mvc;
3
 using Microsoft.AspNetCore.Mvc;
4
+using UnivateProperties_API.Containers.Users;
4
 using UnivateProperties_API.Model.Users;
5
 using UnivateProperties_API.Model.Users;
5
 using UnivateProperties_API.Repository;
6
 using UnivateProperties_API.Repository;
6
 using UnivateProperties_API.Repository.Users;
7
 using UnivateProperties_API.Repository.Users;
7
 
8
 
8
 namespace User_API.Controllers
9
 namespace User_API.Controllers
9
 {
10
 {
10
-    //[Authorize]
11
+    [Authorize]
11
     [Route("api/[controller]")]
12
     [Route("api/[controller]")]
12
     [ApiController]
13
     [ApiController]
13
     public class UserController : ControllerBase
14
     public class UserController : ControllerBase
19
             _Repo = repo;
20
             _Repo = repo;
20
         }
21
         }
21
 
22
 
23
+        [Authorize(Roles = Role.SuperAdmin)]
22
         [HttpGet]
24
         [HttpGet]
23
         public IActionResult Get()
25
         public IActionResult Get()
24
         {
26
         {
28
         [HttpGet("{id}")]
30
         [HttpGet("{id}")]
29
         public IActionResult Get(int id)
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
             return new OkObjectResult(_Repo.Get(x => x.Id == id));
38
             return new OkObjectResult(_Repo.Get(x => x.Id == id));
32
         }
39
         }
33
 
40
 

+ 1
- 1
UnivateProperties_API/Repository/Users/AgentRepository.cs Parādīt failu

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

+ 2
- 2
UnivateProperties_API/Repository/Users/IndividualRepository.cs Parādīt failu

18
 
18
 
19
         public List<Individual> Get(Func<Individual, bool> where)
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
         public List<Individual> GetAll()
24
         public List<Individual> GetAll()
25
         {
25
         {
26
-            return _dbContext.Individuals.ToList();
26
+            return _dbContext.Individuals.Include("User").ToList();
27
         }
27
         }
28
 
28
 
29
         public Individual GetDetailed(Func<Individual, bool> first)
29
         public Individual GetDetailed(Func<Individual, bool> first)

+ 17
- 1
UnivateProperties_API/Repository/Users/RegisterRepository.cs Parādīt failu

109
 
109
 
110
             User createUser = new User(individual.Username, individual.Password);
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
             if (personType == PersonType.Agent)
114
             if (personType == PersonType.Agent)
115
             {
115
             {
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
         public void Update(User userParam, string password = null)
163
         public void Update(User userParam, string password = null)
148
         {
164
         {
149
             var user = _dbContext.Users.Find(userParam.Id);
165
             var user = _dbContext.Users.Find(userParam.Id);

Notiek ielāde…
Atcelt
Saglabāt