Skip to content

Commit c58eb7c

Browse files
committed
Input addon fix, spinner added
1 parent 2a1a511 commit c58eb7c

File tree

5 files changed

+103
-92
lines changed

5 files changed

+103
-92
lines changed
Lines changed: 91 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,92 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Security.Claims;
4-
using System.Threading.Tasks;
5-
using eFormAPI.Web.Infrastructure.Data.Entities;
6-
using eFormAPI.Web.Infrastructure.Identity;
7-
using Microsoft.AspNet.Identity.Owin;
8-
using Microsoft.Owin.Security;
9-
using Microsoft.Owin.Security.Cookies;
10-
using Microsoft.Owin.Security.OAuth;
11-
12-
namespace eFormAPI.Web.Infrastructure.Security
13-
{
14-
public class ApplicationOAuthProvider : OAuthAuthorizationServerProvider
15-
{
16-
private readonly string _publicClientId;
17-
18-
public ApplicationOAuthProvider(string publicClientId)
19-
{
20-
_publicClientId = publicClientId ?? throw new ArgumentNullException($"publicClientId");
21-
}
22-
23-
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
24-
{
25-
var userManager = context.OwinContext.GetUserManager<EformUserManager>();
26-
27-
EformUser user = await userManager.FindAsync(context.UserName, context.Password);
28-
29-
if (user == null)
30-
{
31-
context.SetError("The user name or password is incorrect.", "The user name or password is incorrect.");
32-
return;
33-
}
34-
35-
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
36-
OAuthDefaults.AuthenticationType);
37-
ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
38-
CookieAuthenticationDefaults.AuthenticationType);
39-
40-
AuthenticationProperties properties = CreateProperties(user.UserName);
41-
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
42-
context.Validated(ticket);
43-
context.Request.Context.Authentication.SignIn(cookiesIdentity);
44-
}
45-
46-
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
47-
{
48-
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
49-
{
50-
context.AdditionalResponseParameters.Add(property.Key, property.Value);
51-
}
52-
53-
return Task.FromResult<object>(null);
54-
}
55-
56-
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
57-
{
58-
// Resource owner password credentials does not provide a client ID.
59-
if (context.ClientId == null)
60-
{
61-
context.Validated();
62-
}
63-
64-
return Task.FromResult<object>(null);
65-
}
66-
67-
public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
68-
{
69-
if (context.ClientId == _publicClientId)
70-
{
71-
Uri expectedRootUri = new Uri(context.Request.Uri, "/");
72-
73-
if (expectedRootUri.AbsoluteUri == context.RedirectUri)
74-
{
75-
context.Validated();
76-
}
77-
}
78-
79-
return Task.FromResult<object>(null);
80-
}
81-
82-
public static AuthenticationProperties CreateProperties(string userName)
83-
{
84-
IDictionary<string, string> data = new Dictionary<string, string>
85-
{
86-
{ "userName", userName }
87-
};
88-
return new AuthenticationProperties(data);
89-
}
90-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Security.Claims;
4+
using System.Threading.Tasks;
5+
using eFormAPI.Web.Infrastructure.Data.Entities;
6+
using eFormAPI.Web.Infrastructure.Identity;
7+
using Microsoft.AspNet.Identity.Owin;
8+
using Microsoft.Owin.Security;
9+
using Microsoft.Owin.Security.Cookies;
10+
using Microsoft.Owin.Security.OAuth;
11+
12+
namespace eFormAPI.Web.Infrastructure.Security
13+
{
14+
public class ApplicationOAuthProvider : OAuthAuthorizationServerProvider
15+
{
16+
private readonly string _publicClientId;
17+
18+
public ApplicationOAuthProvider(string publicClientId)
19+
{
20+
_publicClientId = publicClientId ?? throw new ArgumentNullException($"publicClientId");
21+
}
22+
23+
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
24+
{
25+
26+
var userManager = context.OwinContext.GetUserManager<EformUserManager>();
27+
28+
EformUser user = await userManager.FindAsync(context.UserName, context.Password);
29+
30+
if (user == null)
31+
{
32+
context.SetError("The user name or password is incorrect.", "The user name or password is incorrect.");
33+
return;
34+
}
35+
36+
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
37+
OAuthDefaults.AuthenticationType);
38+
ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
39+
CookieAuthenticationDefaults.AuthenticationType);
40+
41+
AuthenticationProperties properties = CreateProperties(user.UserName);
42+
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
43+
context.Validated(ticket);
44+
context.Request.Context.Authentication.SignIn(cookiesIdentity);
45+
}
46+
47+
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
48+
{
49+
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
50+
{
51+
context.AdditionalResponseParameters.Add(property.Key, property.Value);
52+
}
53+
54+
return Task.FromResult<object>(null);
55+
}
56+
57+
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
58+
{
59+
// Resource owner password credentials does not provide a client ID.
60+
if (context.ClientId == null)
61+
{
62+
context.Validated();
63+
}
64+
65+
return Task.FromResult<object>(null);
66+
}
67+
68+
public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
69+
{
70+
if (context.ClientId == _publicClientId)
71+
{
72+
Uri expectedRootUri = new Uri(context.Request.Uri, "/");
73+
74+
if (expectedRootUri.AbsoluteUri == context.RedirectUri)
75+
{
76+
context.Validated();
77+
}
78+
}
79+
80+
return Task.FromResult<object>(null);
81+
}
82+
83+
public static AuthenticationProperties CreateProperties(string userName)
84+
{
85+
IDictionary<string, string> data = new Dictionary<string, string>
86+
{
87+
{ "userName", userName }
88+
};
89+
return new AuthenticationProperties(data);
90+
}
91+
}
9192
}

eform-client/src/app/components/auth/auth.component.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@
1111
.panel {
1212
border: 0;
1313
}
14+
15+
.user-addon {
16+
padding-left: 13px;
17+
padding-right: 14px;
18+
}

eform-client/src/app/components/auth/auth.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h3 class="text-center">eForm Angular</h3>
88

99
<form [formGroup]="form">
1010
<div class="input-group input-group-md">
11-
<span class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></span>
11+
<span class="input-group-addon user-addon"><i class="fa fa-user" aria-hidden="true"></i></span>
1212
<input formControlName="username" type="text" name="username" id="username" class="form-control" placeholder="Username" required>
1313
</div>
1414
<br>

eform-client/src/app/modules/eform/components/eform-table/eform-table.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ <h4 class="modal-title">{{deploymentModalTitle}}</h4>
130130
</tr>
131131
</tbody>
132132
</table>
133+
<eform-spinner [middleActive]="isDeploying"></eform-spinner>
133134
</div>
134135
</modal-body>
135136
<modal-footer>
136137
<button type="button" class="btn btn-default" data-dismiss="deploymentModal" (click)="deploymentModal.dismiss()">
137138
Cancel
138139
</button>
139-
<button type="button" class="btn btn-success" (click)="submitDeploymentModal()">Save deployment</button>
140+
<button type="button" class="btn btn-success" [disabled]="isDeploying" (click)="submitDeploymentModal()">Save deployment</button>
140141
</modal-footer>
141142
</modal>
142143

eform-client/src/app/modules/eform/components/eform-table/eform-table.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class EFormTableComponent implements OnInit {
2828
deployModel: DeployModel = new DeployModel();
2929
deployViewModel: DeployModel = new DeployModel();
3030
deploymentModalTitle: String = 'Edit deployment';
31+
isDeploying = false;
3132

3233
constructor(private eFormService: EFormService, private notifyService: NotifyService, private sitesService: SitesService) {
3334
}
@@ -169,11 +170,14 @@ export class EFormTableComponent implements OnInit {
169170

170171
submitDeploymentModal() {
171172
if (this.deployModel.id != null) {
173+
this.isDeploying = true;
172174
this.eFormService.deploySingle(this.deployModel).subscribe(operation => {
173175
if (operation && operation.success) {
174176
this.loadAllTemplates();
177+
this.isDeploying = false;
175178
this.notifyService.success({text: operation.message || 'Error'});
176179
} else {
180+
this.isDeploying = false;
177181
this.notifyService.error({text: operation.message || 'Error'});
178182
}
179183
this.deploymentModal.close();

0 commit comments

Comments
 (0)