Skip to content

Commit 505e47a

Browse files
committed
defect fixes
1 parent 74d3275 commit 505e47a

File tree

12 files changed

+148
-137
lines changed

12 files changed

+148
-137
lines changed
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { ErrorHandler, Injectable, ApplicationRef, Injector } from '@angular/core';
2-
3-
import { NotificationsService } from '../simple-notifications';
4-
import { UtilityService } from './utility.service';
2+
import { NotificationsService } from '../simple-notifications/simple-notifications.module';
53

64
@Injectable()
75
export class GlobalErrorHandler implements ErrorHandler {
86

9-
constructor(private ns: NotificationsService, private inj: Injector) { }
7+
constructor(
8+
private ns: NotificationsService,
9+
private inj: Injector
10+
) { }
1011

1112
handleError(errorResponse: any): void {
1213
if (errorResponse.status === 401) {
1314
this.ns.error('Unauthorised', 'Pleae login again.');
1415
this.inj.get(ApplicationRef).tick();
15-
this.inj.get(UtilityService).navigateToSignIn();
1616
} else if (errorResponse.status === 400) {
1717
console.log('***** HANDLE ERROR *****');
18-
const us = this.inj.get(UtilityService);
19-
this.ns.error(errorResponse.error.message, us.formatErrors(errorResponse.error.errors));
18+
this.ns.error(errorResponse.error.message,
19+
this.formatErrors(errorResponse.error.errors)
20+
);
2021
this.inj.get(ApplicationRef).tick();
2122
}
2223
this.ns.error(errorResponse);
@@ -26,4 +27,8 @@ export class GlobalErrorHandler implements ErrorHandler {
2627
// throw errorResponse;
2728
}
2829

30+
private formatErrors(errors: any) {
31+
return errors ? errors.map((err: any) => err.message).join('/n') : '';
32+
}
33+
2934
}

Migrations/20171116231347_Initial.Designer.cs renamed to Migrations/20171219214524_Initial.Designer.cs

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 86 additions & 86 deletions
Large diffs are not rendered by default.

Migrations/ApplicationDbContextModelSnapshot.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
1717
{
1818
#pragma warning disable 612, 618
1919
modelBuilder
20-
.HasAnnotation("ProductVersion", "2.0.0-rtm-26452");
20+
.HasAnnotation("ProductVersion", "2.0.1-rtm-125");
2121

2222
modelBuilder.Entity("AspNetCoreSpa.Server.Entities.ApplicationRole", b =>
2323
{
@@ -320,16 +320,16 @@ protected override void BuildModel(ModelBuilder modelBuilder)
320320

321321
b.Property<string>("AuthorizationId");
322322

323-
b.Property<string>("Ciphertext");
324-
325323
b.Property<string>("ConcurrencyToken")
326324
.IsConcurrencyToken();
327325

328326
b.Property<DateTimeOffset?>("CreationDate");
329327

330328
b.Property<DateTimeOffset?>("ExpirationDate");
331329

332-
b.Property<string>("Hash");
330+
b.Property<string>("Payload");
331+
332+
b.Property<string>("ReferenceId");
333333

334334
b.Property<string>("Status");
335335

@@ -345,7 +345,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
345345

346346
b.HasIndex("AuthorizationId");
347347

348-
b.HasIndex("Hash")
348+
b.HasIndex("ReferenceId")
349349
.IsUnique();
350350

351351
b.ToTable("OpenIddictTokens");
@@ -422,13 +422,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
422422
{
423423
b.HasOne("OpenIddict.Models.OpenIddictApplication", "Application")
424424
.WithMany("Tokens")
425-
.HasForeignKey("ApplicationId")
426-
.OnDelete(DeleteBehavior.Cascade);
425+
.HasForeignKey("ApplicationId");
427426

428427
b.HasOne("OpenIddict.Models.OpenIddictAuthorization", "Authorization")
429428
.WithMany("Tokens")
430-
.HasForeignKey("AuthorizationId")
431-
.OnDelete(DeleteBehavior.Cascade);
429+
.HasForeignKey("AuthorizationId");
432430
});
433431
#pragma warning restore 612, 618
434432
}

Server/Controllers/api/AuthorizationController.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public async Task<IActionResult> Authorize(OpenIdConnectRequest request)
142142
return Challenge(properties, provider);
143143
}
144144

145-
return Render(ExternalLoginStatus.Error);
145+
return this.Render(ExternalLoginStatus.Error);
146146
}
147147

148148
// Sign in the user with this external login provider if the user already has a login.
@@ -155,7 +155,7 @@ public async Task<IActionResult> Authorize(OpenIdConnectRequest request)
155155

156156
if (user == null)
157157
{
158-
return Render(ExternalLoginStatus.Error);
158+
return this.Render(ExternalLoginStatus.Error);
159159
}
160160

161161
_logger.LogInformation(5, $"User logged in with ${info.LoginProvider} provider.");
@@ -189,21 +189,21 @@ public async Task<IActionResult> Authorize(OpenIdConnectRequest request)
189189
else
190190
{
191191
// External account doesn't have a local account so ask to create one
192-
return Render(ExternalLoginStatus.CreateAccount);
192+
return this.Render(ExternalLoginStatus.CreateAccount);
193193
}
194194

195195
}
196196

197197

198-
return Render(ExternalLoginStatus.Error);
198+
return this.Render(ExternalLoginStatus.Error);
199199

200200
// if (result.RequiresTwoFactor)
201201
// {
202-
// return Render(ExternalLoginStatus.TwoFactor);
202+
// return this.Render(ExternalLoginStatus.TwoFactor);
203203
// }
204204
// if (result.IsLockedOut)
205205
// {
206-
// return Render(ExternalLoginStatus.Lockout);
206+
// return this.Render(ExternalLoginStatus.Lockout);
207207
// }
208208
// else
209209
// {
@@ -212,7 +212,7 @@ public async Task<IActionResult> Authorize(OpenIdConnectRequest request)
212212
// // ViewData["LoginProvider"] = info.LoginProvider;
213213
// // var email = info.Principal.FindFirstValue(ClaimTypes.Email);
214214
// // return RedirectToAction("Index", "Home", new ExternalLoginCreateAccountViewModel { Email = email });
215-
// return Render(ExternalLoginStatus.CreateAccount);
215+
// return this.Render(ExternalLoginStatus.CreateAccount);
216216
// }
217217

218218
// if (!User.Identity.IsAuthenticated)

Server/Controllers/api/BaseController.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ public class BaseController : Controller
1414
public BaseController()
1515
{
1616
}
17-
public IActionResult Render(ExternalLoginStatus status)
18-
{
19-
return RedirectToAction("Index", "Home", new { externalLoginStatus = (int)status });
20-
}
17+
2118
}
2219

2320

Server/Controllers/api/ManageController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public async Task<IActionResult> UserInfo([FromBody]IndexViewModel model)
6969

7070
user.FirstName = model.FirstName;
7171
user.LastName = model.LastName;
72-
user.UserName = model.Username;
73-
user.Email = model.Email;
72+
user.UserName = string.IsNullOrEmpty(model.Username) ? user.UserName : model.Username;
73+
user.Email = string.IsNullOrEmpty(model.Email) ? user.Email : model.Email;
7474
user.PhoneNumber = model.PhoneNumber;
7575

7676
var result = await _userManager.UpdateAsync(user);

Server/Helpers/Helpers.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using AspNetCoreSpa.Server.Entities;
4+
using Microsoft.AspNetCore.Mvc;
35
using Newtonsoft.Json;
46
using Newtonsoft.Json.Serialization;
57
using Serilog;
@@ -16,7 +18,7 @@ public static string JsonSerialize(object obj)
1618
new JsonSerializerSettings
1719
{
1820
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
19-
StringEscapeHandling = StringEscapeHandling.EscapeHtml,
21+
StringEscapeHandling = StringEscapeHandling.EscapeHtml,
2022
ContractResolver = new CamelCasePropertyNamesContractResolver()
2123
});
2224
}
@@ -36,5 +38,10 @@ public static void SetupSerilog()
3638
"image/svg+xml",
3739
"application/font-woff2"
3840
});
41+
42+
public static IActionResult Render(this Controller ctrl, ExternalLoginStatus status)
43+
{
44+
return ctrl.RedirectToAction("Index", "Home", new { externalLoginStatus = (int)status });
45+
}
3946
}
4047
}

Server/SeedDbData.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private async Task AddOpenIdConnectOptions(IServiceScope services, CancellationT
105105

106106
if (await manager.FindByClientIdAsync("aspnetcorespa", cancellationToken) == null)
107107
{
108-
var host = _hostingEnv.IsDevelopment() ? "http://localhost:5000" : "http://aspnetcorespa.azurewebsites.net";
108+
var host = Startup.Configuration["HostUrl"].ToString();
109+
109110
var descriptor = new OpenIddictApplicationDescriptor
110111
{
111112
ClientId = "aspnetcorespa",

Server/ViewModels/ManageViewModels/IndexViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ public class IndexViewModel
1111
public string Username { get; set; }
1212

1313
public bool IsEmailConfirmed { get; set; }
14-
15-
[Required]
16-
[EmailAddress]
1714
public string Email { get; set; }
1815

1916
[Phone]

0 commit comments

Comments
 (0)