Skip to content

Commit 4a7baa2

Browse files
Account Pre-Seeding
1 parent 8e2bc20 commit 4a7baa2

7 files changed

+146
-3
lines changed

Backend/Data/Migrations/20221215202855_InitialMigration.Designer.cs Backend/Data/Migrations/20221215213135_InitialMigration.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Backend/Interfaces/IAuthenticationService.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public interface IAuthenticationService
1616
Task CreateRoles();
1717
Task<IdentityResult> ChangePassword(AppUser user, string currentPassword, string newPassword);
1818
Task<IdentityResult> ForceChangePassword(AppUser user, string newPassword);
19+
Task<bool> UserExists(string username, string email);
1920
}
2021
}

Backend/Services/AuthenticationService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public Task<IdentityResult> ForceChangePassword(AppUser user, string newPassword
213213
return _userManager.AddPasswordAsync(user, newPassword);
214214
}
215215

216-
private async Task<bool> UserExists(string username, string email)
216+
public async Task<bool> UserExists(string username, string email)
217217
{
218218
return await _userManager.Users.AnyAsync(x => (x.UserName == username.ToLower() || x.Email == email.ToLower()));
219219
}

Backend/Startup.cs

+106-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.AspNetCore.Authentication.JwtBearer;
2121
using Microsoft.IdentityModel.Tokens;
2222
using System.Text;
23+
using Backend.DTOs;
2324

2425
namespace Backend
2526
{
@@ -85,7 +86,7 @@ public void ConfigureServices(IServiceCollection services)
8586
}
8687

8788
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
88-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
89+
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
8990
{
9091
using (var scope = app.ApplicationServices.CreateScope())
9192
{
@@ -114,6 +115,110 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
114115
endpoints.MapControllers();
115116
});
116117

118+
119+
using (var scope = app.ApplicationServices.CreateScope())
120+
{
121+
var authService = scope.ServiceProvider.GetRequiredService<IAuthenticationService>();
122+
123+
if (!authService.UserExists("22002900", "oisep@bilkent.edu.tr").GetAwaiter().GetResult())
124+
{
125+
authService.Register(new DTOs.RegisterDto
126+
{
127+
ActorType = "Office of International Students and Exchange Programs",
128+
UserName = "22002900",
129+
Email = "oisep@bilkent.edu.tr",
130+
Password = "Test123_",
131+
FirstName = "Erkin",
132+
LastName = "Tarhan",
133+
}
134+
).Wait();
135+
}
136+
137+
if (!authService.UserExists("22002901", "instructor@bilkent.edu.tr").GetAwaiter().GetResult())
138+
{
139+
authService.Register(new DTOs.RegisterDto
140+
{
141+
ActorType = "Course Coordinator Instructor",
142+
UserName = "22002901",
143+
Email = "instructor@bilkent.edu.tr",
144+
Password = "Test123_",
145+
FirstName = "Eray",
146+
LastName = "Tüzün",
147+
Department = new DTOs.DepartmentInfoDto
148+
{
149+
DepartmentName = "Department of Computer Engineering",
150+
FacultyName = "Faculty of Engineering",
151+
}
152+
}).Wait();
153+
}
154+
155+
if (!authService.UserExists("1", "admin@bilkent.edu.tr").GetAwaiter().GetResult())
156+
{
157+
authService.Register(new DTOs.RegisterDto
158+
{
159+
ActorType = "Admin",
160+
UserName = "1",
161+
Email = "admin@bilkent.edu.tr",
162+
Password = "Test123_",
163+
FirstName = "Edward",
164+
LastName = "Snowden"
165+
}).Wait();
166+
}
167+
168+
if (!authService.UserExists("22002902", "coordinator@bilkent.edu.tr").GetAwaiter().GetResult())
169+
{
170+
authService.Register(new DTOs.RegisterDto
171+
{
172+
ActorType = "Exchange Coordinator",
173+
UserName = "22002902",
174+
Email = "coordinator@bilkent.edu.tr",
175+
Password = "Test123_",
176+
FirstName = "Can",
177+
LastName = "Alkan",
178+
Department = new DTOs.DepartmentInfoDto
179+
{
180+
DepartmentName = "Department of Computer Engineering",
181+
FacultyName = "Faculty of Engineering",
182+
}
183+
}).Wait();
184+
}
185+
186+
if (!authService.UserExists("22002903", "dean@bilkent.edu.tr").GetAwaiter().GetResult())
187+
{
188+
authService.Register(new DTOs.RegisterDto
189+
{
190+
ActorType = "Dean Department Chair",
191+
UserName = "22002903",
192+
Email = "dean@bilkent.edu.tr",
193+
Password = "Test123_",
194+
FirstName = "Nail",
195+
LastName = "Akar",
196+
Department = new DTOs.DepartmentInfoDto
197+
{
198+
DepartmentName = "Department of Computer Engineering",
199+
FacultyName = "Faculty of Engineering",
200+
}
201+
}).Wait();
202+
}
203+
204+
if (!authService.UserExists("22002904", "chair@bilkent.edu.tr").GetAwaiter().GetResult())
205+
{
206+
authService.Register(new DTOs.RegisterDto
207+
{
208+
ActorType = "Dean Department Chair",
209+
UserName = "22002904",
210+
Email = "chair@bilkent.edu.tr",
211+
Password = "Test123_",
212+
FirstName = "Selim",
213+
LastName = "Aksoy",
214+
Department = new DTOs.DepartmentInfoDto
215+
{
216+
DepartmentName = "Department of Computer Engineering",
217+
FacultyName = "Faculty of Engineering",
218+
}
219+
}).Wait();
220+
}
221+
}
117222
}
118223
}
119224
}

Backend/ersms.sqlite

-48 KB
Binary file not shown.

SeededAccountDetails.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Account Details of Pre-Seeded Accounts
2+
3+
## OISEP
4+
5+
- UserName = 22002900
6+
- Email = oisep@bilkent.edu.tr
7+
- Password = Test123\_
8+
9+
## Admin
10+
11+
- UserName = 1
12+
- Email = admin@bilkent.edu.tr
13+
- Password = Test123\_
14+
15+
## Course Coordinator Instructor
16+
17+
- UserName = 22002901
18+
- Email = instructor@bilkent.edu.tr
19+
- Password = Test123\_
20+
21+
## Exchange Coordinator
22+
23+
- UserName = 22002902
24+
- Email = coordinator@bilkent.edu.tr
25+
- Password = Test123\_
26+
27+
## Dean
28+
29+
- UserName = 22002903
30+
- Email = dean@bilkent.edu.tr
31+
- Password = Test123\_
32+
33+
## Department Chair
34+
35+
- UserName = 22002904
36+
- Email = chair@bilkent.edu.tr
37+
- Password = Test123\_

0 commit comments

Comments
 (0)