ソースを参照

Login, Reset Password etc

master
Lene Scholtz 5年前
コミット
4e72bd8c10

+ 13
- 0
UnivateProperties_API/Helpers/MyCommon.cs ファイルの表示

120
 
120
 
121
             return true;
121
             return true;
122
         }
122
         }
123
+
124
+        public static string CreateRandomPassword(int length = 6)
125
+        {
126
+            string validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*?_-";
127
+            Random random = new Random();
128
+
129
+            char[] chars = new char[length];
130
+            for (int i = 0; i < length; i++)
131
+            {
132
+                chars[i] = validChars[random.Next(0, validChars.Length)];
133
+            }
134
+            return new string(chars);
135
+        }
123
     }
136
     }
124
 }
137
 }

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

2
 using System;
2
 using System;
3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
+using UnivateProperties_API.Containers.Users;
5
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Model.Users;
7
 using UnivateProperties_API.Model.Users;
7
 
8
 
38
         public void Insert(Agent item)
39
         public void Insert(Agent item)
39
         {
40
         {
40
             item.Id = NewId();
41
             item.Id = NewId();
42
+            item.User.Role = Role.Agent;
43
+            if (_dbContext.Agents.Any(a => a.AgencyId == null))
44
+            {
45
+                item.AgencyId = 10;
46
+            }
41
             _dbContext.Add(item);
47
             _dbContext.Add(item);
42
             Save();
48
             Save();
43
         }
49
         }

+ 10
- 1
UnivateProperties_API/Repository/Users/IndividualRepository.cs ファイルの表示

135
             Save();
135
             Save();
136
         }
136
         }
137
 
137
 
138
-
139
         public void Save()
138
         public void Save()
140
         {
139
         {
141
             _dbContext.SaveChanges();
140
             _dbContext.SaveChanges();
156
             id += 1;
155
             id += 1;
157
             return id;
156
             return id;
158
         }
157
         }
158
+
159
+        //public List<Individual> PasswordReset(Individual item)
160
+        //{
161
+        //    var individual = _dbContext.Individuals.Include("User").FirstOrDefault(x => x.Id == item.Id);
162
+        //    if (individual != null)
163
+        //    {
164
+        //        individual.User.PasswordHash = MyCommon.CreateRandomPassword(item);
165
+        //    }
166
+        //    return item;
167
+        //}
159
     }
168
     }
160
 }
169
 }

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

5
 using UnivateProperties_API.Containers.Users.Simple;
5
 using UnivateProperties_API.Containers.Users.Simple;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Helpers;
7
 using UnivateProperties_API.Helpers;
8
+using UnivateProperties_API.Model.Communication;
8
 using UnivateProperties_API.Model.Users;
9
 using UnivateProperties_API.Model.Users;
10
+using UnivateProperties_API.Repository.Communication;
9
 
11
 
10
 namespace UnivateProperties_API.Repository.Users
12
 namespace UnivateProperties_API.Repository.Users
11
 {
13
 {
99
 
101
 
100
             Create(createUser, individual.Password, false);
102
             Create(createUser, individual.Password, false);
101
 
103
 
104
+            Person p = null;
105
+            
102
             if (personType == PersonType.Agent)
106
             if (personType == PersonType.Agent)
103
             {
107
             {
104
                 Agent agent = new Agent()
108
                 Agent agent = new Agent()
112
                     Agency = agency
116
                     Agency = agency
113
                 };
117
                 };
114
                 agent.Id = NewAgentId();
118
                 agent.Id = NewAgentId();
119
+                agent.User.Role = Role.Agency;
120
+                p = agent;
115
                 _dbContext.Agents.Add(agent);
121
                 _dbContext.Agents.Add(agent);
116
             }
122
             }
117
             else if (personType == PersonType.Individual)
123
             else if (personType == PersonType.Individual)
126
                     Telephone = individual.Telephone
132
                     Telephone = individual.Telephone
127
                 };
133
                 };
128
                 i.Id = NewIndividualId();
134
                 i.Id = NewIndividualId();
135
+                i.User.Role = Role.PrivateUser;
136
+                p = i;
129
                 _dbContext.Individuals.Add(i);
137
                 _dbContext.Individuals.Add(i);
138
+
139
+            }
140
+            Template template = _dbContext.Templates.FirstOrDefault(x => x.Name == "IndivRegEmail");
141
+            if (template != null && personType == PersonType.Individual)
142
+            {
143
+                    TemplateRepository templateRepository = new TemplateRepository(_dbContext);
144
+                    templateRepository.SendEmailTemplate(template, p, new List<Model.BaseEntity>() { p });
145
+            }
146
+
147
+            Template templ = _dbContext.Templates.FirstOrDefault(x => x.Name == "AgencyRegEmail");
148
+            if (templ != null)
149
+            {
150
+                TemplateRepository templateRepository = new TemplateRepository(_dbContext);
151
+                templateRepository.SendEmailTemplate(templ, p, new List<Model.BaseEntity>() { p });
130
             }
152
             }
153
+
154
+            Template temp = _dbContext.Templates.FirstOrDefault(x => x.Name == "VerificationEmail");
155
+            if (temp != null)
156
+            {
157
+                TemplateRepository templateRepository = new TemplateRepository(_dbContext);
158
+                templateRepository.SendEmailTemplate(temp, p, new List<Model.BaseEntity>() { p });
159
+            }
160
+
131
             if (save)
161
             if (save)
132
             {
162
             {
133
                 Save();
163
                 Save();

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