ソースを参照

Change password after first login

master
30117125 4年前
コミット
6bdafe15a7

+ 1
- 0
UnivateProperties_API/Containers/Users/Simple/SimpleUserDto.cs ファイルの表示

@@ -5,5 +5,6 @@
5 5
         public int Id { get; set; }
6 6
         public string Username { get; set; }
7 7
         public string Role { get; set; }
8
+        public bool LoginPasswordChange { get; set; }
8 9
     }
9 10
 }

+ 1
- 0
UnivateProperties_API/Containers/Users/UserDto.cs ファイルの表示

@@ -12,5 +12,6 @@
12 12
         public string Telephone { get; set; }
13 13
         public string CellNumber { get; set; }
14 14
         public bool AcceptedTerms { get; set; }
15
+        public bool LoginPasswordChange { get; set; }
15 16
     }
16 17
 }

+ 2
- 1
UnivateProperties_API/Controllers/Users/RegisterController.cs ファイルの表示

@@ -62,7 +62,8 @@ namespace UnivateProperties_API.Controllers.Users
62 62
                     {
63 63
                         Id = user.Id,
64 64
                         Role = user.Role,
65
-                        Username = user.Username
65
+                        Username = user.Username,
66
+                        LoginPasswordChange = user.LoginPasswordChange
66 67
                     },
67 68
                     Person = _Repo.UserDetails(user.Id),
68 69
                     Token = new SimpleTokenDto()

+ 5
- 5
UnivateProperties_API/Controllers/Users/UserController.cs ファイルの表示

@@ -8,19 +8,19 @@ using UnivateProperties_API.Repository.Users;
8 8
 
9 9
 namespace User_API.Controllers
10 10
 {
11
-    [Authorize]
11
+   
12 12
     [Route("api/[controller]")]
13 13
     [ApiController]
14 14
     public class UserController : ControllerBase
15 15
     {
16
-        private readonly IRepository<User> _Repo;
16
+        private readonly IUserRepository _Repo;
17 17
 
18
-        public UserController(IRepository<User> repo)
18
+        public UserController(IUserRepository repo)
19 19
         {
20 20
             _Repo = repo;
21 21
         }
22 22
 
23
-        [Authorize(Roles = Role.SuperAdmin)]
23
+        
24 24
         [HttpGet]
25 25
         public IActionResult Get()
26 26
         {
@@ -50,7 +50,7 @@ namespace User_API.Controllers
50 50
         }
51 51
 
52 52
         [HttpPut()]
53
-        public IActionResult Put([FromBody] User user)
53
+        public IActionResult Put([FromBody] UserDto user)
54 54
         {
55 55
             if (user != null)
56 56
             {

+ 2
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs ファイルの表示

@@ -1334,6 +1334,8 @@ namespace UnivateProperties_API.Migrations
1334 1334
 
1335 1335
                     b.Property<bool>("IsDeleted");
1336 1336
 
1337
+                    b.Property<bool>("LoginPasswordChange");
1338
+
1337 1339
                     b.Property<DateTime>("Modified");
1338 1340
 
1339 1341
                     b.Property<string>("ModifiedBy");

+ 1
- 0
UnivateProperties_API/Model/Users/User.cs ファイルの表示

@@ -32,6 +32,7 @@ namespace UnivateProperties_API.Model.Users
32 32
         public bool Verified { get; set; }
33 33
         public string Token { get; set; }
34 34
         public bool AcceptedTerms { get; set; }
35
+        public bool LoginPasswordChange { get; set; }
35 36
         #endregion Properties
36 37
 
37 38
         #region Methods

+ 22
- 0
UnivateProperties_API/Repository/Users/IUserRepository.cs ファイルの表示

@@ -0,0 +1,22 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using UnivateProperties_API.Containers.Users;
4
+using UnivateProperties_API.Model.Users;
5
+
6
+namespace UnivateProperties_API.Repository.Users
7
+{
8
+    public interface IUserRepository
9
+    {
10
+        List<User> Get(Func<User, bool> where);
11
+        List<User> GetAll();
12
+        User GetDetailed(Func<User, bool> first);
13
+        void Insert(User item);
14
+        void Insert(IEnumerable<User> item);
15
+        void Remove(User item);
16
+        void Remove(IEnumerable<User> items);
17
+        void RemoveAtId(int item);
18
+        void Update(UserDto userParam);
19
+        void Save();
20
+        List<User> GetDetailedAll();
21
+    }
22
+}

+ 11
- 6
UnivateProperties_API/Repository/Users/UserRepository.cs ファイルの表示

@@ -1,13 +1,14 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4
+using UnivateProperties_API.Containers.Users;
4 5
 using UnivateProperties_API.Context;
5 6
 using UnivateProperties_API.Helpers;
6 7
 using UnivateProperties_API.Model.Users;
7 8
 
8 9
 namespace UnivateProperties_API.Repository.Users
9 10
 {
10
-    public class UserRepository : IRepository<User>
11
+    public class UserRepository : IUserRepository
11 12
     {
12 13
         private readonly DataContext _dbContext;
13 14
 
@@ -83,7 +84,7 @@ namespace UnivateProperties_API.Repository.Users
83 84
             Save();
84 85
         }
85 86
 
86
-        public void Update(User userParam)
87
+        public void Update(UserDto userParam)
87 88
         {
88 89
             var user = _dbContext.Users.Find(userParam.Id);
89 90
 
@@ -96,19 +97,22 @@ namespace UnivateProperties_API.Repository.Users
96 97
                 if (_dbContext.Users.Any(x => x.Username == userParam.Username))
97 98
                     throw new AppException("Username " + userParam.Username + " is already taken");
98 99
             }
99
-
100
+            
100 101
             // update user properties
101 102
             user.Username = userParam.Username;
102
-
103
+            
103 104
             // update password if it was entered
104
-            if (!string.IsNullOrWhiteSpace(userParam.PasswordHash.ToString()))
105
+            if (!string.IsNullOrWhiteSpace(userParam.Password))
105 106
             {
106
-                CreatePasswordHash(userParam.PasswordHash.ToString(), out byte[] passwordHash, out byte[] passwordSalt);
107
+                MyCommon.CreatePasswordHash(userParam.Password, out byte[] passwordHash, out byte[] passwordSalt);
107 108
 
108 109
                 user.PasswordHash = passwordHash;
109 110
                 user.PasswordSalt = passwordSalt;
110 111
             }
111 112
 
113
+            if (userParam.LoginPasswordChange)
114
+                user.LoginPasswordChange = false;
115
+
112 116
             _dbContext.Users.Update(user);
113 117
             _dbContext.SaveChanges();
114 118
         }
@@ -135,6 +139,7 @@ namespace UnivateProperties_API.Repository.Users
135 139
             throw new NotImplementedException();
136 140
         }
137 141
 
142
+
138 143
         //public int NewId()
139 144
         //{
140 145
         //    int id = 0;

+ 1
- 1
UnivateProperties_API/Startup.cs ファイルの表示

@@ -146,7 +146,7 @@ namespace UnivateProperties_API
146 146
             services.AddTransient<IRepository<Agent>, AgentRepository>();
147 147
             services.AddTransient<IRegisterRepository, RegisterRepository>();
148 148
             services.AddTransient<IRepository<Agency>, AgencyRepository>();
149
-            services.AddTransient<IRepository<User>, UserRepository>();
149
+            services.AddTransient<IUserRepository, UserRepository>();
150 150
             services.AddTransient<IRepository<Individual>, IndividualRepository>();
151 151
             #endregion User
152 152
             #region Communication

読み込み中…
キャンセル
保存