浏览代码

Change password after first login

master
30117125 4 年前
父节点
当前提交
6bdafe15a7

+ 1
- 0
UnivateProperties_API/Containers/Users/Simple/SimpleUserDto.cs 查看文件

5
         public int Id { get; set; }
5
         public int Id { get; set; }
6
         public string Username { get; set; }
6
         public string Username { get; set; }
7
         public string Role { get; set; }
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
         public string Telephone { get; set; }
12
         public string Telephone { get; set; }
13
         public string CellNumber { get; set; }
13
         public string CellNumber { get; set; }
14
         public bool AcceptedTerms { get; set; }
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
                     {
62
                     {
63
                         Id = user.Id,
63
                         Id = user.Id,
64
                         Role = user.Role,
64
                         Role = user.Role,
65
-                        Username = user.Username
65
+                        Username = user.Username,
66
+                        LoginPasswordChange = user.LoginPasswordChange
66
                     },
67
                     },
67
                     Person = _Repo.UserDetails(user.Id),
68
                     Person = _Repo.UserDetails(user.Id),
68
                     Token = new SimpleTokenDto()
69
                     Token = new SimpleTokenDto()

+ 5
- 5
UnivateProperties_API/Controllers/Users/UserController.cs 查看文件

8
 
8
 
9
 namespace User_API.Controllers
9
 namespace User_API.Controllers
10
 {
10
 {
11
-    [Authorize]
11
+   
12
     [Route("api/[controller]")]
12
     [Route("api/[controller]")]
13
     [ApiController]
13
     [ApiController]
14
     public class UserController : ControllerBase
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
             _Repo = repo;
20
             _Repo = repo;
21
         }
21
         }
22
 
22
 
23
-        [Authorize(Roles = Role.SuperAdmin)]
23
+        
24
         [HttpGet]
24
         [HttpGet]
25
         public IActionResult Get()
25
         public IActionResult Get()
26
         {
26
         {
50
         }
50
         }
51
 
51
 
52
         [HttpPut()]
52
         [HttpPut()]
53
-        public IActionResult Put([FromBody] User user)
53
+        public IActionResult Put([FromBody] UserDto user)
54
         {
54
         {
55
             if (user != null)
55
             if (user != null)
56
             {
56
             {

+ 2
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs 查看文件

1334
 
1334
 
1335
                     b.Property<bool>("IsDeleted");
1335
                     b.Property<bool>("IsDeleted");
1336
 
1336
 
1337
+                    b.Property<bool>("LoginPasswordChange");
1338
+
1337
                     b.Property<DateTime>("Modified");
1339
                     b.Property<DateTime>("Modified");
1338
 
1340
 
1339
                     b.Property<string>("ModifiedBy");
1341
                     b.Property<string>("ModifiedBy");

+ 1
- 0
UnivateProperties_API/Model/Users/User.cs 查看文件

32
         public bool Verified { get; set; }
32
         public bool Verified { get; set; }
33
         public string Token { get; set; }
33
         public string Token { get; set; }
34
         public bool AcceptedTerms { get; set; }
34
         public bool AcceptedTerms { get; set; }
35
+        public bool LoginPasswordChange { get; set; }
35
         #endregion Properties
36
         #endregion Properties
36
 
37
 
37
         #region Methods
38
         #region Methods

+ 22
- 0
UnivateProperties_API/Repository/Users/IUserRepository.cs 查看文件

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

+ 1
- 1
UnivateProperties_API/Startup.cs 查看文件

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

正在加载...
取消
保存