Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eFormAPI/eFormAPI/App_Start/AutofacConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Autofac;
using Autofac.Integration.WebApi;
using eFormAPI.Web.Infrastructure.Data;
using eFormAPI.Web.Infrastructure.Identity;

namespace eFormAPI.Web
{
Expand All @@ -21,6 +22,7 @@ public static void ConfigureContainer()
builder.RegisterWebApiFilterProvider(config);
// Set the dependency resolver to be Autofac.
builder.RegisterType<BaseDbContext>().InstancePerRequest();
builder.RegisterType<EformRoleManager>().InstancePerRequest();
Container = builder.Build();
}
}
Expand Down
65 changes: 49 additions & 16 deletions eFormAPI/eFormAPI/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System.Configuration;
using System.Data.Entity;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using eFormAPI.Common.API;
using eFormAPI.Common.Models.Auth;
using eFormAPI.Common.Models.User;
using eFormAPI.Web.Infrastructure.Consts;
using eFormAPI.Web.Infrastructure.Data;
using eFormAPI.Web.Infrastructure.Data.Entities;
using eFormAPI.Web.Infrastructure.Identity;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;

namespace eFormAPI.Web.Controllers
{
Expand All @@ -20,25 +21,19 @@ namespace eFormAPI.Web.Controllers
public class AccountController : ApiController
{
private EformUserManager _userManager;
private readonly EformRoleManager _eformRoleManager;
private readonly BaseDbContext _dbContext;

public AccountController()
public AccountController(BaseDbContext dbContext)
{
_eformRoleManager = new EformRoleManager(
new EformRoleStore(new BaseDbContext()));
;
_dbContext = dbContext;
}

public AccountController(EformUserManager userManager,
ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
{
UserManager = userManager;
AccessTokenFormat = accessTokenFormat;
}

public EformUserManager UserManager
{
get => _userManager ?? Request.GetOwinContext().GetUserManager<EformUserManager>();
private set => _userManager = value;
}

public ISecureDataFormat<AuthenticationTicket> AccessTokenFormat { get; private set; }
private EformUserManager UserManager =>
_userManager ?? Request.GetOwinContext().GetUserManager<EformUserManager>();

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


[HttpGet]
[AllowAnonymous]
[Route("reset-admin-password")]
public async Task<OperationResult> ResetAdminPassword(string code)
{
var securityCode = ConfigurationManager.AppSettings["restore:securityCode"];
if (string.IsNullOrEmpty(securityCode))
{
return new OperationResult(false, "Please setup security code on server.");
}
var defaultPassword = ConfigurationManager.AppSettings["restore:defaultPassword"];
if (code != securityCode)
{
return new OperationResult(false, "Invalid security code.");
}
var role = await _eformRoleManager.FindByNameAsync(EformRoles.Admin);
var user = _dbContext.Users.Include(x => x.Roles)
.FirstOrDefault(x => x.Roles.Any(y => y.RoleId == role.Id));
if (user == null)
{
return new OperationResult(false, "Admin user not found");
}
var removeResult = await UserManager.RemovePasswordAsync(user.Id);
if (!removeResult.Succeeded)
{
return new OperationResult(false,
"Error while removing old password. \n" + string.Join(" ", removeResult.Errors));
}
var addPasswordResult = await UserManager.AddPasswordAsync(user.Id, defaultPassword);
if (!addPasswordResult.Succeeded)
{
return new OperationResult(false,
"Error while adding new password. \n" + string.Join(" ", addPasswordResult.Errors));
}
return new OperationResult(true, $"Your email: {user.Email}. Password has been reset.");
}

// POST: /account/reset-password
[HttpPost]
[Route("reset-password")]
Expand Down
17 changes: 17 additions & 0 deletions eFormAPI/eFormAPI/Controllers/CasesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ public OperationDataResult<ReplyElement> Edit(int id)
}
}

[HttpGet]
public OperationResult Delete(int id)
{
try
{
var core = _coreHelper.GetCore();

return core.CaseDeleteResult(id)
? new OperationResult(true, $"Case #{id} deleted successfully")
: new OperationResult(false, "Case could not be removed");
}
catch (Exception)
{
return new OperationResult(false, "Case could not be removed");
}
}

[HttpPost]
public OperationResult Update(ReplyRequest model)
{
Expand Down
22 changes: 16 additions & 6 deletions eFormAPI/eFormAPI/Controllers/TemplateFilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http;
using Castle.Components.DictionaryAdapter.Xml;
using eFormAPI.Common.API;
using eFormAPI.Web.Infrastructure.Helpers;

Expand Down Expand Up @@ -73,12 +74,21 @@ public OperationResult RotateImage(string fileName)
{
return new OperationResult(false, "File not found");
}

var img = Image.FromFile(filePath);
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
img.Save(filePath);
img.Dispose();

try
{
var img = Image.FromFile(filePath);
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
img.Save(filePath);
img.Dispose();
}
catch (Exception e)
{
if (e.Message == "A generic error occurred in GDI+.")
{
return new OperationResult(true);
}
return new OperationResult(false, "Error while rotate image.");
}
return new OperationResult(true, "Image rotated successfully.");
}

Expand Down
2 changes: 2 additions & 0 deletions eFormAPI/eFormAPI/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<add key="header:secondaryTextVisible" value="True" />
<add key="header:imageLink" value="" />
<add key="header:imageLinkVisible" value="True" />
<add key="restore:securityCode" value="code" />
<add key="restore:defaultPassword" value="Qq1234567$" />
</appSettings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
Expand Down
1 change: 1 addition & 0 deletions eform-client/e2e/spec.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Header image button', () => {
settingsPage.saveButton.click();
browser.refresh();
expect(browser.isElementPresent(settingsPage.headerImageMatcher)).toBeFalsy();
browser.sleep(2000);
settingsPage.SiteHeader.resetButton.click();
done();
});
Expand Down
38 changes: 35 additions & 3 deletions eform-client/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
const gulp = require('gulp');
const protractor = require('gulp-protractor').protractor;
const gulp = require('gulp');
const runSequence = require('run-sequence');
const spawn = require('child_process').spawn;

const runSpawn = function(done, task, opt_arg, opt_io) {
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
var stdio = 'inherit';
if (opt_io === 'ignore') {
stdio = 'ignore';
}
var child = spawn(task, opt_arg, {stdio: stdio});
var running = false;
child.on('close', function() {
if (!running) {
running = true;
done();
}
});
child.on('error', function() {
if (!running) {
console.error('gulp encountered a child error');
running = true;
done();
}
});
};

gulp.task('webdriver:update', function(done) {
runSpawn(done, 'node', ['./node_modules/protractor/bin/webdriver-manager', 'update']);
});

gulp.task('tests', function(done) {
runSequence(['webdriver:update'], "e2e-tests" ,done);
});

gulp.task("tests", function (done) {
gulp.src(['e2e/**/*.js'], {read: false})
gulp.task("e2e-tests", function (done) {
gulp.src(['e2e/!**!/!*.js'], {read: false})
.pipe(protractor({
configFile: 'protractor.conf.js'
})
Expand Down
3 changes: 3 additions & 0 deletions eform-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"ngx-gallery": "^3.1.4",
"pnotify": "^3.2.0",
"rxjs": "^5.4.2",
"selenium-standalone-jar": "^3.0.1",
"trumbowyg": "^2.5.1",
"ts-helpers": "^1.1.1",
"wowjs": "^1.1.3",
Expand All @@ -72,6 +73,8 @@
"path": "^0.12.7",
"phantomjs-prebuilt": "^2.1.16",
"protractor": "~5.1.0",
"run-sequence": "^2.2.1",
"selenium-server-standalone-jar": "^3.8.1",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
Expand Down
12 changes: 6 additions & 6 deletions eform-client/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@

/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');

exports.config = {
allScriptsTimeout: 11000,
allScriptsTimeout: 20000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
// directConnect: false,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 60000,
print: function() {}
print: function () {
}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
beforeLaunch: function () {
require('ts-node').register({
project: 'e2e'
});
},
onPrepare: function() {
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter());
}
};
12 changes: 11 additions & 1 deletion eform-client/src/app/components/auth/auth.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.panel {
border: 0;
}
}

.user-addon {
padding-left: 13px;
Expand All @@ -22,6 +22,11 @@
padding-right: 12px;
}

.lock-addon {
padding-left: 15px;
padding-right: 14px;
}

.p-header-wrapper {
margin-top: 35px;
margin-bottom: 15px;
Expand All @@ -34,3 +39,8 @@
.p-description {
font-weight: 500;
}

.link-block {
margin-bottom: 5px;
display: block;
}
41 changes: 30 additions & 11 deletions eform-client/src/app/components/auth/auth.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,36 @@
</ng-container>

<ng-container *ngIf="!showLoginForm">
<form [formGroup]="formRestore">
<div class="input-group input-group-md">
<span class="input-group-addon envelope-addon"><i class="fa fa-envelope" aria-hidden="true"></i></span>
<input formControlName="email" type="text" name="email" id="email" class="form-control" placeholder="Email" required>
</div>
<br>
<button type="submit" class="btn btn-ar btn-success btn-block" [disabled]="!email.valid" (click)="submitRestoreForm()">Restore password</button>
</form>
<a (click)="toggleLoginForm(true)" class="forgot-password" style="cursor: pointer">
Back to login
</a>
<ng-container *ngIf="!showAdminResetForm">
<form [formGroup]="formRestore">
<div class="input-group input-group-md">
<span class="input-group-addon envelope-addon"><i class="fa fa-envelope" aria-hidden="true"></i></span>
<input formControlName="email" type="text" name="email" id="email" class="form-control" placeholder="Email" required>
</div>
<br>
<button type="submit" class="btn btn-ar btn-success btn-block" [disabled]="!email.valid" (click)="submitRestoreForm()">Restore password</button>
</form>
<a (click)="showAdminResetForm = !showAdminResetForm" class="forgot-password link-block" style="cursor: pointer">
Reset admin password
</a>
<a (click)="toggleLoginForm(true)" class="forgot-password link-block" style="cursor: pointer">
Back to login
</a>
</ng-container>
<ng-container *ngIf="showAdminResetForm">
<form [formGroup]="formReset">
<div class="input-group input-group-md">
<span class="input-group-addon lock-addon"><i class="fa fa-unlock-alt" aria-hidden="true"></i></span>
<input formControlName="secretKey" type="text" name="secretKey" id="secretKey" class="form-control" placeholder="Secret code" required>
</div>
<br>
<button type="submit" class="btn btn-ar btn-success btn-block" [disabled]="!secretKey.valid" (click)="submitResetAdminForm()">Reset password</button>
</form>
<a (click)="toggleLoginForm(true)" class="forgot-password" style="cursor: pointer">
Back to login
</a>
</ng-container>

</ng-container>

</div>
Expand Down
Loading