Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yserz committed Apr 23, 2019
2 parents e7791fd + 6869edb commit 4a586b8
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 321 deletions.
2 changes: 1 addition & 1 deletion app/server/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Server {
this.app.use(helmet.xssFilter());
this.app.use(
helmet.hsts({
includeSubdomains: true,
includeSubDomains: true,
maxAge: 31536000,
preload: true,
}),
Expand Down
3 changes: 3 additions & 0 deletions app/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface ServerConfig {
ENABLE_DEBUG: boolean;
ENFORCE_HTTPS: boolean;
};
NEW_PASSWORD_MINIMUM_LENGTH: number;
PIWIK_HOSTNAME: string;
PIWIK_ID: string;
PORT_HTTP: number;
Expand Down Expand Up @@ -147,6 +148,8 @@ const config: ServerConfig = {
ENABLE_DEBUG: process.env.FEATURE_ENABLE_DEBUG == 'true' ? true : false,
ENFORCE_HTTPS: process.env.FEATURE_ENFORCE_HTTPS == 'false' ? false : true,
},
NEW_PASSWORD_MINIMUM_LENGTH:
(process.env.NEW_PASSWORD_MINIMUM_LENGTH && Number(process.env.NEW_PASSWORD_MINIMUM_LENGTH)) || 8,
PIWIK_HOSTNAME: process.env.PIWIK_HOSTNAME,
PIWIK_ID: process.env.PIWIK_ID,
PORT_HTTP: Number(process.env.PORT) || 21080,
Expand Down
6 changes: 6 additions & 0 deletions app/server/controller/ForgotController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ describe('ForgotController', () => {
await controller.handlePost(req as Request, res as Response);
expect(renderSpy.calls.mostRecent().args[1].status).toEqual('error');
expect(renderSpy.calls.mostRecent().args[1].error).toEqual('forgot.errorUnknown');

controller['resetPassword'] = (): Promise<AxiosResponse> =>
Promise.reject(new Error('error')) as Promise<AxiosResponse>;
await controller.handlePost(req as Request, res as Response);
expect(renderSpy.calls.mostRecent().args[1].status).toEqual('error');
expect(renderSpy.calls.mostRecent().args[1].error).toEqual('forgot.errorUnknown');
});
});
});
6 changes: 4 additions & 2 deletions app/server/controller/ForgotController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export class ForgotController {
this.trackingController.trackEvent(req.originalUrl, 'account.forgot', 'success', result.status, 1);
status = 'success';
} catch (requestError) {
this.trackingController.trackEvent(req.originalUrl, 'account.forgot', 'fail', requestError.response.status, 1);
switch (requestError.response.status) {
const responseStatus = requestError.response && requestError.response.status;
this.trackingController.trackEvent(req.originalUrl, 'account.forgot', 'fail', responseStatus, 1);
switch (responseStatus) {
case ForgotController.HTTP_STATUS_EMAIL_NOT_IN_USE: {
error = _('forgot.errorUnusedEmail');
status = 'error';
Expand All @@ -88,6 +89,7 @@ export class ForgotController {
default: {
error = _('forgot.errorUnknown');
status = 'error';
console.error('Internal error', requestError);
}
}
}
Expand Down
38 changes: 32 additions & 6 deletions app/server/controller/ResetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import {ValidationUtil} from '@wireapp/commons';
import {Request, Response, Router} from 'express';
import {ServerConfig} from '../config';
import {ROUTES} from '../routes/Root';
Expand Down Expand Up @@ -58,6 +59,7 @@ export class ResetController {
error,
html_class: 'account forgot',
key,
passwordInfo: _('reset.passwordInfo', {minPasswordLength: this.config.NEW_PASSWORD_MINIMUM_LENGTH}),
status: req.query.success === '' ? 'success' : status,
title: _('forgot.title'),
user_agent: () => BrowserUtil.parseUserAgent(req.header('User-Agent')),
Expand All @@ -73,23 +75,47 @@ export class ResetController {
const code = req.fields.code as string;
const key = req.fields.key as string;
const password = req.fields.password as string;

if (!password || password.length < 8) {
error = _('reset.errorInvalidPassword');
const passwordCheck = new RegExp(
ValidationUtil.getNewPasswordPattern(this.config.NEW_PASSWORD_MINIMUM_LENGTH),
'u',
);
const isExceedingMaxPasswordLength = [...password].length > ValidationUtil.DEFAULT_PASSWORD_MAX_LENGTH;
const isInvalidPasswordFormat = !passwordCheck.test(password);
if (isExceedingMaxPasswordLength || isInvalidPasswordFormat) {
error = _('reset.passwordInfo', {minPasswordLength: this.config.NEW_PASSWORD_MINIMUM_LENGTH});
status = 'fail';
} else if (key && code) {
try {
const result = await this.postPasswordReset(key, code, password);
this.trackingController.trackEvent(req.originalUrl, 'account.reset', 'success', result.status, 1);
status = 'success';
} catch (requestError) {
this.trackingController.trackEvent(req.originalUrl, 'account.reset', 'fail', requestError.status, 1);
switch (requestError.status) {
const response = requestError && requestError.response;
const responseStatus = response && response.status;
const responseData = response && response.data;
this.trackingController.trackEvent(req.originalUrl, 'account.reset', 'fail', responseStatus, 1);
switch (responseStatus) {
case 400: {
status = 'error';
/*
* Invalid password reset code
* {
* code: 400,
* message: 'Invalid password reset code.',
* label: 'invalid-code'
* }
*/

error = _('reset.errorUnknown');
status = 'fail';
break;
}
case 409: {
error = _('reset.errorPasswordAlreadyUsed');
status = 'fail';
break;
}
default: {
console.error('Unknown reset password error', responseData);
error = _('reset.errorUnknown');
status = 'fail';
}
Expand Down
4 changes: 2 additions & 2 deletions app/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ server
process.on('uncaughtException', error =>
console.error(`[${formatDate()}] Uncaught exception: ${error.message}`, error),
);
process.on('unhandledRejection', error =>
console.error(`[${formatDate()}] Uncaught rejection "${error.constructor.name}": ${error.message}`, error),
process.on('unhandledRejection', (reason, promise) =>
console.error(`[${formatDate()}] Unhandled Rejection at:`, promise, 'reason:', reason),
);
98 changes: 52 additions & 46 deletions dist/templates/account/reset.html
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
{% extends 'base.html' %}
{% import 'macro/utils.html' as utils %}

{% block content %}
{% if status == 'success' %}
<h1>{{_('reset.title')}}</h1>
<p>{{_('reset.successDescription')}}</p>
{% if user_agent().is.mobile %}
{{utils.download_btn(config, _('open.downloadButton', {company: config.COMPANY_NAME}), user_agent, 'wbtn green', 'verify')}}
{% elif user_agent().is.desktop %}
<p>{{_('open.description', {company: config.COMPANY_NAME})}}</p>
{% if user_agent().is.linux or user_agent().is.windows %}
<a class="wbtn green" href="{{config.URL.WEBSITE_BASE}}/download">{{_('open.downloadButton', {company: config.COMPANY_NAME})}}</a>
{% elif user_agent().is.osx %}
<a class="wbtn green no-capital" href="{{config.URL.DOWNLOAD_OSX_BASE}}">{{_('open.openMac')}}</a>
{% endif %}
<a class="wbtn blue" href="{{config.URL.WEBAPP_BASE}}/auth/#login">{{_('open.openWeb')}}</a>
{% else %}
<a class="wbtn blue" href="{{config.URL.WEBAPP_BASE}}/auth/#login">{{_('open.openWire', {company: config.COMPANY_NAME})}}</a>
{% endif %}
{% elif status == 'error' %}
<h1>{{_('reset.errorTitle')}}</h1>
<p>{{_('reset.errorDescription')}}</p>
<a class="wbtn green" href="{{ROUTES.ROUTE_RESET}}?key={{key}}&code={{code}}">{{_('reset.button')}}</a>
{% extends 'base.html' %} {% import 'macro/utils.html' as utils %} {% block content %} {% if status == 'success' %}
<h1>{{ _('reset.title') }}</h1>
<p>{{ _('reset.successDescription') }}</p>
{% if user_agent().is.mobile %}
{{
utils.download_btn(
config,
_('open.downloadButton', {company: config.COMPANY_NAME}),
user_agent,
'wbtn green',
'verify'
)
}}
{% elif user_agent().is.desktop %}
<p>{{ _('open.description', {company: config.COMPANY_NAME}) }}</p>
{% if user_agent().is.linux or user_agent().is.windows %}
<a class="wbtn green" href="{{ config.URL.WEBSITE_BASE }}/download">{{
_('open.downloadButton', {company: config.COMPANY_NAME})
}}</a>
{% elif user_agent().is.osx %}
<a class="wbtn green no-capital" href="{{ config.URL.DOWNLOAD_OSX_BASE }}">{{ _('open.openMac') }}</a>
{% endif %}
<a class="wbtn blue" href="{{ config.URL.WEBAPP_BASE }}/auth/#login">{{ _('open.openWeb') }}</a>
{% else %}
<a class="wbtn blue" href="{{ config.URL.WEBAPP_BASE }}/auth/#login">{{
_('open.openWire', {company: config.COMPANY_NAME})
}}</a>
{% endif %} {% elif status == 'error' %}
<h1>{{ _('reset.errorTitle') }}</h1>
<p>{{ _('reset.errorDescription') }}</p>
<a class="wbtn green" href="{{ ROUTES.ROUTE_RESET }}?key={{ key }}&code={{ code }}">{{ _('reset.button') }}</a>
{% else %}
<h1>{{ title }}</h1>
<form method="POST" action="{{ ROUTES.ROUTE_RESET }}">
<input name="key" type="hidden" value="{{ key }}" />
<input name="code" type="hidden" value="{{ code }}" />
<input name="password" type="password" placeholder="{{ _('reset.passwordPlaceholder') }}" autofocus />
{% if error %}
<p class="error" data-uie-name="error-message">{{ error }}</p>
{% else %}
<h1>{{title}}</h1>
<form method="POST" action="{{ROUTES.ROUTE_RESET}}">
<input name="key" type="hidden" value="{{key}}">
<input name="code" type="hidden" value="{{code}}">
<input name="password" type="password" placeholder="{{_('reset.passwordPlaceholder')}}" autofocus>
<p>{{error}}</p>
<button type="submit" class="wbtn btn-block" data-loading-text="{{_('general.loading')}}">
{{_('reset.button')}}
</button>
</form>
<p data-uie-name="element-password-help">{{ passwordInfo }}</p>
{% endif %}
{% endblock %}


{% block scripts %}
{% if (user_agent().is.ios or user_agent().is.android) and status == 'success' %}
<script>
$(function() {
window.location.href = "{{config.URL.REDIRECT_RESET_BASE}}";
});
</script>
{% endif %}
{% endblock %}
<button type="submit" class="wbtn btn-block" data-loading-text="{{ _('general.loading') }}">
{{ _('reset.button') }}
</button>
</form>
{% endif %} {% endblock %} {% block scripts %} {% if (user_agent().is.ios or user_agent().is.android) and status ==
'success' %}
<script>
$(function() {
window.location.href = '{{config.URL.REDIRECT_RESET_BASE}}';
});
</script>
{% endif %} {% endblock %}
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
{
"dependencies": {
"@wireapp/commons": "1.0.11",
"@wireapp/commons": "1.6.3",
"axios": "0.18.0",
"dotenv": "6.2.0",
"dotenv": "7.0.0",
"dotenv-extended": "2.4.0",
"express": "4.16.4",
"express-formidable": "1.2.0",
"express-useragent": "1.0.12",
"fs-extra": "7.0.1",
"helmet": "3.15.1",
"i18next": "15.0.5",
"i18next-express-middleware": "1.7.1",
"i18next-node-fs-backend": "2.1.1",
"helmet": "3.16.0",
"i18next": "15.0.9",
"i18next-express-middleware": "1.7.3",
"i18next-node-fs-backend": "2.1.2",
"intl": "1.2.5",
"jquery": "3.3.1",
"logdown": "3.2.7",
"logdown": "3.2.8",
"moment": "2.24.0",
"normalize.css": "8.0.1",
"nunjucks": "3.1.7",
"nunjucks": "3.2.0",
"nunjucks-autoescape": "1.0.1",
"pm2": "3.3.1",
"wire-web-config-default-master": "https://github.com/wireapp/wire-web-config-wire#v0.14.0",
"wire-web-config-default-staging": "https://github.com/wireapp/wire-web-config-default#v0.14.0"
"pm2": "3.4.1",
"wire-web-config-default-master": "https://github.com/wireapp/wire-web-config-wire#v0.17.25-0",
"wire-web-config-default-staging": "https://github.com/wireapp/wire-web-config-default#v0.17.24"
},
"devDependencies": {
"@types/dotenv": "6.1.0",
"@types/dotenv": "6.1.1",
"@types/express": "4.16.1",
"@types/express-formidable": "1.0.3",
"@types/express-useragent": "0.2.21",
"@types/fs-extra": "5.0.5",
"@types/helmet": "0.0.42",
"@types/helmet": "0.0.43",
"@types/i18next": "12.1.0",
"@types/i18next-node-fs-backend": "0.0.30",
"@types/jasmine": "3.3.9",
"@types/node": "11.9.5",
"@types/jasmine": "3.3.12",
"@types/node": "11.13.0",
"@types/nunjucks": "3.1.1",
"@wireapp/copy-config": "0.3.1",
"@wireapp/copy-config": "0.5.3",
"babel-eslint": "10.0.1",
"concurrently": "4.1.0",
"cross-env": "5.2.0",
"del": "4.0.0",
"eslint": "5.15.1",
"del": "4.1.0",
"eslint": "5.16.0",
"eslint-config-prettier": "4.1.0",
"eslint-plugin-es5": "1.3.1",
"eslint-plugin-jasmine": "2.10.1",
"eslint-plugin-jsdoc": "4.1.1",
"eslint-plugin-jsdoc": "4.8.0",
"eslint-plugin-no-unsanitized": "3.0.2",
"eslint-plugin-prettier": "3.0.1",
"gulp": "4.0.0",
Expand All @@ -62,18 +62,18 @@
"gulp-util": "3.0.8",
"gulp-zip": "4.2.0",
"husky": "1.3.1",
"i18next-scanner": "2.9.2",
"jasmine": "3.3.1",
"i18next-scanner": "2.10.1",
"jasmine": "3.4.0",
"less": "3.9.0",
"lint-staged": "8.1.5",
"nodemon": "1.18.10",
"prettier": "1.16.4",
"tslint": "5.13.1",
"tslint": "5.15.0",
"tslint-config-prettier": "1.18.0",
"tslint-eslint-rules": "5.4.0",
"tslint-plugin-prettier": "2.0.1",
"typescript": "3.3.3333",
"uglify-js": "3.4.9"
"typescript": "3.4.1",
"uglify-js": "3.5.3"
},
"husky": {
"hooks": {
Expand Down
4 changes: 4 additions & 0 deletions src/style/type.less
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ a {
}
}

.error {
color: @w-red;
}

.special-link {
color: @w-graphite-dark;
text-transform: uppercase;
Expand Down
Loading

0 comments on commit 4a586b8

Please sign in to comment.