Skip to content

Commit 5c0f23c

Browse files
authored
Merge pull request #70 from Gid733/master
Fixes and enhancements
2 parents b5205e8 + 3d6c6e1 commit 5c0f23c

25 files changed

+350
-65
lines changed

eFormAPI/eFormAPI/App_Start/AutofacConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Autofac;
44
using Autofac.Integration.WebApi;
55
using eFormAPI.Web.Infrastructure.Data;
6+
using eFormAPI.Web.Infrastructure.Identity;
67

78
namespace eFormAPI.Web
89
{
@@ -21,6 +22,7 @@ public static void ConfigureContainer()
2122
builder.RegisterWebApiFilterProvider(config);
2223
// Set the dependency resolver to be Autofac.
2324
builder.RegisterType<BaseDbContext>().InstancePerRequest();
25+
builder.RegisterType<EformRoleManager>().InstancePerRequest();
2426
Container = builder.Build();
2527
}
2628
}

eFormAPI/eFormAPI/Controllers/AccountController.cs

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
using System.Configuration;
2+
using System.Data.Entity;
23
using System.Linq;
34
using System.Net.Http;
45
using System.Threading.Tasks;
56
using System.Web.Http;
67
using eFormAPI.Common.API;
78
using eFormAPI.Common.Models.Auth;
89
using eFormAPI.Common.Models.User;
10+
using eFormAPI.Web.Infrastructure.Consts;
911
using eFormAPI.Web.Infrastructure.Data;
1012
using eFormAPI.Web.Infrastructure.Data.Entities;
1113
using eFormAPI.Web.Infrastructure.Identity;
1214
using Microsoft.AspNet.Identity;
1315
using Microsoft.AspNet.Identity.Owin;
14-
using Microsoft.Owin.Security;
1516

1617
namespace eFormAPI.Web.Controllers
1718
{
@@ -20,25 +21,19 @@ namespace eFormAPI.Web.Controllers
2021
public class AccountController : ApiController
2122
{
2223
private EformUserManager _userManager;
24+
private readonly EformRoleManager _eformRoleManager;
25+
private readonly BaseDbContext _dbContext;
2326

24-
public AccountController()
27+
public AccountController(BaseDbContext dbContext)
2528
{
29+
_eformRoleManager = new EformRoleManager(
30+
new EformRoleStore(new BaseDbContext()));
31+
;
32+
_dbContext = dbContext;
2633
}
2734

28-
public AccountController(EformUserManager userManager,
29-
ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
30-
{
31-
UserManager = userManager;
32-
AccessTokenFormat = accessTokenFormat;
33-
}
34-
35-
public EformUserManager UserManager
36-
{
37-
get => _userManager ?? Request.GetOwinContext().GetUserManager<EformUserManager>();
38-
private set => _userManager = value;
39-
}
40-
41-
public ISecureDataFormat<AuthenticationTicket> AccessTokenFormat { get; private set; }
35+
private EformUserManager UserManager =>
36+
_userManager ?? Request.GetOwinContext().GetUserManager<EformUserManager>();
4237

4338
// GET api/account/user-info
4439
[Route("user-info")]
@@ -106,6 +101,44 @@ await UserManager.SendEmailAsync(user.Id, "Reset Password",
106101
return new OperationResult(false);
107102
}
108103

104+
105+
[HttpGet]
106+
[AllowAnonymous]
107+
[Route("reset-admin-password")]
108+
public async Task<OperationResult> ResetAdminPassword(string code)
109+
{
110+
var securityCode = ConfigurationManager.AppSettings["restore:securityCode"];
111+
if (string.IsNullOrEmpty(securityCode))
112+
{
113+
return new OperationResult(false, "Please setup security code on server.");
114+
}
115+
var defaultPassword = ConfigurationManager.AppSettings["restore:defaultPassword"];
116+
if (code != securityCode)
117+
{
118+
return new OperationResult(false, "Invalid security code.");
119+
}
120+
var role = await _eformRoleManager.FindByNameAsync(EformRoles.Admin);
121+
var user = _dbContext.Users.Include(x => x.Roles)
122+
.FirstOrDefault(x => x.Roles.Any(y => y.RoleId == role.Id));
123+
if (user == null)
124+
{
125+
return new OperationResult(false, "Admin user not found");
126+
}
127+
var removeResult = await UserManager.RemovePasswordAsync(user.Id);
128+
if (!removeResult.Succeeded)
129+
{
130+
return new OperationResult(false,
131+
"Error while removing old password. \n" + string.Join(" ", removeResult.Errors));
132+
}
133+
var addPasswordResult = await UserManager.AddPasswordAsync(user.Id, defaultPassword);
134+
if (!addPasswordResult.Succeeded)
135+
{
136+
return new OperationResult(false,
137+
"Error while adding new password. \n" + string.Join(" ", addPasswordResult.Errors));
138+
}
139+
return new OperationResult(true, $"Your email: {user.Email}. Password has been reset.");
140+
}
141+
109142
// POST: /account/reset-password
110143
[HttpPost]
111144
[Route("reset-password")]

eFormAPI/eFormAPI/Controllers/CasesController.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public OperationDataResult<ReplyElement> Edit(int id)
5151
}
5252
}
5353

54+
[HttpGet]
55+
public OperationResult Delete(int id)
56+
{
57+
try
58+
{
59+
var core = _coreHelper.GetCore();
60+
61+
return core.CaseDeleteResult(id)
62+
? new OperationResult(true, $"Case #{id} deleted successfully")
63+
: new OperationResult(false, "Case could not be removed");
64+
}
65+
catch (Exception)
66+
{
67+
return new OperationResult(false, "Case could not be removed");
68+
}
69+
}
70+
5471
[HttpPost]
5572
public OperationResult Update(ReplyRequest model)
5673
{

eFormAPI/eFormAPI/Controllers/TemplateFilesController.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net.Http.Headers;
88
using System.Web;
99
using System.Web.Http;
10+
using Castle.Components.DictionaryAdapter.Xml;
1011
using eFormAPI.Common.API;
1112
using eFormAPI.Web.Infrastructure.Helpers;
1213

@@ -73,12 +74,21 @@ public OperationResult RotateImage(string fileName)
7374
{
7475
return new OperationResult(false, "File not found");
7576
}
76-
77-
var img = Image.FromFile(filePath);
78-
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
79-
img.Save(filePath);
80-
img.Dispose();
81-
77+
try
78+
{
79+
var img = Image.FromFile(filePath);
80+
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
81+
img.Save(filePath);
82+
img.Dispose();
83+
}
84+
catch (Exception e)
85+
{
86+
if (e.Message == "A generic error occurred in GDI+.")
87+
{
88+
return new OperationResult(true);
89+
}
90+
return new OperationResult(false, "Error while rotate image.");
91+
}
8292
return new OperationResult(true, "Image rotated successfully.");
8393
}
8494

eFormAPI/eFormAPI/Web.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<add key="header:secondaryTextVisible" value="True" />
3333
<add key="header:imageLink" value="" />
3434
<add key="header:imageLinkVisible" value="True" />
35+
<add key="restore:securityCode" value="code" />
36+
<add key="restore:defaultPassword" value="Qq1234567$" />
3537
</appSettings>
3638
<!--
3739
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

eform-client/e2e/spec.e2e-spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('Header image button', () => {
2424
settingsPage.saveButton.click();
2525
browser.refresh();
2626
expect(browser.isElementPresent(settingsPage.headerImageMatcher)).toBeFalsy();
27+
browser.sleep(2000);
2728
settingsPage.SiteHeader.resetButton.click();
2829
done();
2930
});

eform-client/gulpfile.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
1-
const gulp = require('gulp');
21
const protractor = require('gulp-protractor').protractor;
2+
const gulp = require('gulp');
3+
const runSequence = require('run-sequence');
4+
const spawn = require('child_process').spawn;
5+
6+
const runSpawn = function(done, task, opt_arg, opt_io) {
7+
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
8+
var stdio = 'inherit';
9+
if (opt_io === 'ignore') {
10+
stdio = 'ignore';
11+
}
12+
var child = spawn(task, opt_arg, {stdio: stdio});
13+
var running = false;
14+
child.on('close', function() {
15+
if (!running) {
16+
running = true;
17+
done();
18+
}
19+
});
20+
child.on('error', function() {
21+
if (!running) {
22+
console.error('gulp encountered a child error');
23+
running = true;
24+
done();
25+
}
26+
});
27+
};
328

29+
gulp.task('webdriver:update', function(done) {
30+
runSpawn(done, 'node', ['./node_modules/protractor/bin/webdriver-manager', 'update']);
31+
});
32+
33+
gulp.task('tests', function(done) {
34+
runSequence(['webdriver:update'], "e2e-tests" ,done);
35+
});
436

5-
gulp.task("tests", function (done) {
6-
gulp.src(['e2e/**/*.js'], {read: false})
37+
gulp.task("e2e-tests", function (done) {
38+
gulp.src(['e2e/!**!/!*.js'], {read: false})
739
.pipe(protractor({
840
configFile: 'protractor.conf.js'
941
})

eform-client/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"ngx-gallery": "^3.1.4",
4747
"pnotify": "^3.2.0",
4848
"rxjs": "^5.4.2",
49+
"selenium-standalone-jar": "^3.0.1",
4950
"trumbowyg": "^2.5.1",
5051
"ts-helpers": "^1.1.1",
5152
"wowjs": "^1.1.3",
@@ -72,6 +73,8 @@
7273
"path": "^0.12.7",
7374
"phantomjs-prebuilt": "^2.1.16",
7475
"protractor": "~5.1.0",
76+
"run-sequence": "^2.2.1",
77+
"selenium-server-standalone-jar": "^3.8.1",
7578
"ts-node": "~2.0.0",
7679
"tslint": "~4.5.0",
7780
"typescript": "~2.2.0"

eform-client/protractor.conf.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@
33

44
/*global jasmine */
55
var SpecReporter = require('jasmine-spec-reporter');
6-
76
exports.config = {
8-
allScriptsTimeout: 11000,
7+
allScriptsTimeout: 20000,
98
specs: [
109
'./e2e/**/*.e2e-spec.ts'
1110
],
1211
capabilities: {
1312
'browserName': 'chrome'
1413
},
15-
directConnect: true,
14+
// directConnect: false,
1615
baseUrl: 'http://localhost:4200/',
1716
framework: 'jasmine',
1817
jasmineNodeOpts: {
1918
showColors: true,
2019
defaultTimeoutInterval: 60000,
21-
print: function() {}
20+
print: function () {
21+
}
2222
},
2323
useAllAngular2AppRoots: true,
24-
beforeLaunch: function() {
24+
beforeLaunch: function () {
2525
require('ts-node').register({
2626
project: 'e2e'
2727
});
2828
},
29-
onPrepare: function() {
29+
onPrepare: function () {
3030
jasmine.getEnv().addReporter(new SpecReporter());
3131
}
3232
};

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
.panel {
1212
border: 0;
13-
}
13+
}
1414

1515
.user-addon {
1616
padding-left: 13px;
@@ -22,6 +22,11 @@
2222
padding-right: 12px;
2323
}
2424

25+
.lock-addon {
26+
padding-left: 15px;
27+
padding-right: 14px;
28+
}
29+
2530
.p-header-wrapper {
2631
margin-top: 35px;
2732
margin-bottom: 15px;
@@ -34,3 +39,8 @@
3439
.p-description {
3540
font-weight: 500;
3641
}
42+
43+
.link-block {
44+
margin-bottom: 5px;
45+
display: block;
46+
}

0 commit comments

Comments
 (0)