Browse Source

Login, Reset Password etc

master
Lene Scholtz 5 years ago
parent
commit
4e72bd8c10

+ 13
- 0
UnivateProperties_API/Helpers/MyCommon.cs View File

@@ -120,5 +120,18 @@ namespace UnivateProperties_API.Helpers
120 120
 
121 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 View File

@@ -2,6 +2,7 @@
2 2
 using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5
+using UnivateProperties_API.Containers.Users;
5 6
 using UnivateProperties_API.Context;
6 7
 using UnivateProperties_API.Model.Users;
7 8
 
@@ -38,6 +39,11 @@ namespace UnivateProperties_API.Repository.Users
38 39
         public void Insert(Agent item)
39 40
         {
40 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 47
             _dbContext.Add(item);
42 48
             Save();
43 49
         }

+ 10
- 1
UnivateProperties_API/Repository/Users/IndividualRepository.cs View File

@@ -135,7 +135,6 @@ namespace UnivateProperties_API.Repository.Users
135 135
             Save();
136 136
         }
137 137
 
138
-
139 138
         public void Save()
140 139
         {
141 140
             _dbContext.SaveChanges();
@@ -156,5 +155,15 @@ namespace UnivateProperties_API.Repository.Users
156 155
             id += 1;
157 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 View File

@@ -5,7 +5,9 @@ using UnivateProperties_API.Containers.Users;
5 5
 using UnivateProperties_API.Containers.Users.Simple;
6 6
 using UnivateProperties_API.Context;
7 7
 using UnivateProperties_API.Helpers;
8
+using UnivateProperties_API.Model.Communication;
8 9
 using UnivateProperties_API.Model.Users;
10
+using UnivateProperties_API.Repository.Communication;
9 11
 
10 12
 namespace UnivateProperties_API.Repository.Users
11 13
 {
@@ -99,6 +101,8 @@ namespace UnivateProperties_API.Repository.Users
99 101
 
100 102
             Create(createUser, individual.Password, false);
101 103
 
104
+            Person p = null;
105
+            
102 106
             if (personType == PersonType.Agent)
103 107
             {
104 108
                 Agent agent = new Agent()
@@ -112,6 +116,8 @@ namespace UnivateProperties_API.Repository.Users
112 116
                     Agency = agency
113 117
                 };
114 118
                 agent.Id = NewAgentId();
119
+                agent.User.Role = Role.Agency;
120
+                p = agent;
115 121
                 _dbContext.Agents.Add(agent);
116 122
             }
117 123
             else if (personType == PersonType.Individual)
@@ -126,8 +132,32 @@ namespace UnivateProperties_API.Repository.Users
126 132
                     Telephone = individual.Telephone
127 133
                 };
128 134
                 i.Id = NewIndividualId();
135
+                i.User.Role = Role.PrivateUser;
136
+                p = i;
129 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 161
             if (save)
132 162
             {
133 163
                 Save();

Loading…
Cancel
Save