mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 08:50:45 +08:00
Merge pull request #1538 from coralproject/gdpr-email
[GDPR] Change Email (Local)
This commit is contained in:
+2
-1
@@ -38,6 +38,7 @@ plugins/*
|
||||
!plugins/talk-plugin-google-auth
|
||||
!plugins/talk-plugin-ignore-user
|
||||
!plugins/talk-plugin-like
|
||||
!plugins/talk-plugin-local-auth
|
||||
!plugins/talk-plugin-love
|
||||
!plugins/talk-plugin-member-since
|
||||
!plugins/talk-plugin-mod
|
||||
@@ -53,6 +54,7 @@ plugins/*
|
||||
!plugins/talk-plugin-profile-data
|
||||
!plugins/talk-plugin-remember-sort
|
||||
!plugins/talk-plugin-respect
|
||||
!plugins/talk-plugin-rich-text
|
||||
!plugins/talk-plugin-slack-notifications
|
||||
!plugins/talk-plugin-sort-most-downvoted
|
||||
!plugins/talk-plugin-sort-most-liked
|
||||
@@ -66,7 +68,6 @@ plugins/*
|
||||
!plugins/talk-plugin-toxic-comments
|
||||
!plugins/talk-plugin-upvote
|
||||
!plugins/talk-plugin-viewing-options
|
||||
!plugins/talk-plugin-rich-text
|
||||
|
||||
**/node_modules/*
|
||||
yarn-error.log
|
||||
|
||||
@@ -46,7 +46,7 @@ ProfileContainer.propTypes = {
|
||||
currentUser: PropTypes.object,
|
||||
};
|
||||
|
||||
const slots = ['profileSections'];
|
||||
const slots = ['profileSections', 'profileSettings', 'profileHeader'];
|
||||
|
||||
const withProfileQuery = withQuery(
|
||||
gql`
|
||||
|
||||
@@ -26,6 +26,7 @@ export default {
|
||||
'UpdateAssetSettingsResponse',
|
||||
'UpdateAssetStatusResponse',
|
||||
'UpdateSettingsResponse',
|
||||
'ChangePasswordResponse'
|
||||
'ChangePasswordResponse',
|
||||
'UpdateEmailAddressResponse'
|
||||
),
|
||||
};
|
||||
|
||||
+3
-1
@@ -41,7 +41,7 @@ relative_link: false
|
||||
future: true
|
||||
highlight:
|
||||
enable: false
|
||||
|
||||
|
||||
# Home page setting
|
||||
# path: Root path for your blogs index page. (default = '')
|
||||
# per_page: Posts displayed per page. (0 = disable pagination)
|
||||
@@ -114,6 +114,8 @@ sidebar:
|
||||
url: /integrating/styling-css/
|
||||
- title: Translations and i18n
|
||||
url: /integrating/translations-i18n/
|
||||
- title: GDPR Compliance
|
||||
url: /integrating/gdpr/
|
||||
- title: Product Guide
|
||||
children:
|
||||
- title: How Talk Works
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: GDPR Compliance
|
||||
permalink: /integrating/gdpr/
|
||||
---
|
||||
|
||||
In order to facilitate compliance with the
|
||||
[EU General Data Protection Regulation (GDPR)](https://www.eugdpr.org/), you
|
||||
can enable the following plugins:
|
||||
|
||||
- [talk-plugin-auth](/talk/plugin/talk-plugin-auth) - to facilitate username and password changes
|
||||
- [talk-plugin-local-auth](/talk/plugin/talk-plugin-local-auth) - to facilitate email changes and email association
|
||||
- [talk-plugin-profile-data](/talk/plugin/talk-plugin-profile-data) - to facilitate account download and deletion
|
||||
|
||||
Even if you don't reside in a location where GDPR will apply, it is recommended
|
||||
to enable these features as a best practice to provide your users with control over their
|
||||
own data.
|
||||
|
||||
## GPDR Feature Overview
|
||||
|
||||
Integrating our GDPR tools will give your users and organizations the following benefits:
|
||||
|
||||
- **Download my comment data**: Users can request a download of their comments. An email with a link is emailed to them to download a CSV with each comment they've made, what story it was made on, and the comment's ID and timestamp.
|
||||
- **Delete my acccount**: Users can request deletion of their account. Deleted account requests are pending for 24 hours to allow the user to download their comments, or to change their mind and reactivate their account before the expiry. Account deletions remove all of their comments from the site, all their comments and actions from the database, and their account info from our system.
|
||||
- **Add an email to an Oauth/external account**: Users are prompted to add an email to their non-Talk account (Facebook, Google, external, etc) so that they can take part in GDPR and other features requiring email communication.
|
||||
- **Change my username**: Users can update their username. This is capped at once every 2 weeks.
|
||||
- **Change my email**: Users can change their email.
|
||||
|
||||
## Custom Authentication Solutions
|
||||
|
||||
As many of the newsrooms who have integrated Talk have followed our guides on
|
||||
[Integrating Authentication](/talk/integrating/authentication/), we have also
|
||||
provided tools for those newsrooms to integrate GDPR features into their
|
||||
existing workflows.
|
||||
|
||||
### Account Data
|
||||
|
||||
Through the [talk-plugin-profile-data](/talk/plugin/talk-plugin-profile-data)
|
||||
plugin we allow users to download and delete their account data easily. For
|
||||
custom integrations, this isn't always possible, so we instead provide some
|
||||
GraphQL mutations designed to allow you to integrate it into your existing user
|
||||
interfaces or exports.
|
||||
|
||||
- `downloadUser(id: ID!)` - lets you grab the direct link to download a users
|
||||
account in a zip format. From there, you can integrate it into your existing
|
||||
data export or simply proxy it to the user to allow them to download it
|
||||
elsewhere in your UI.
|
||||
- `delUser(id: ID!)` - lets you delete the specified user
|
||||
|
||||
**Note: These mutations require an administrative token**
|
||||
|
||||
If you would prefer to write your own user interfaces or integrate it into your
|
||||
own, you can disable the client plugin for [talk-plugin-profile-data](/talk/plugin/talk-plugin-profile-data)
|
||||
but keep the server side plugin active (See [Server and Client Plugins](/talk/plugins/#server-and-client-plugins) for more information).
|
||||
@@ -3,10 +3,17 @@
|
||||
tags:
|
||||
- moderation
|
||||
- name: talk-plugin-auth
|
||||
description: Enables internal authentication from Coral.
|
||||
description: Enables internal sign-in authentication.
|
||||
tags:
|
||||
- default
|
||||
- auth
|
||||
- gdpr
|
||||
- name: talk-plugin-local-auth
|
||||
description: Enables email and password based authentication.
|
||||
tags:
|
||||
- default
|
||||
- auth
|
||||
- gdpr
|
||||
- name: talk-plugin-author-menu
|
||||
description: Enables the comment author name plugin area.
|
||||
tags:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../plugins/talk-plugin-local-auth/README.md
|
||||
@@ -9,11 +9,16 @@ functionality. We provide methods to inject behavior into the server side and
|
||||
the client side application to affect different parts of the application
|
||||
life cycle.
|
||||
|
||||
## Recipes
|
||||
## Server and Client Plugins
|
||||
|
||||
Recipes are plugin templates provided by the Coral Core team. Developers can use
|
||||
these recipes to build their own plugins. You can find all the Talk recipes
|
||||
here: [github.com/coralproject/talk-recipes](https://github.com/coralproject/talk-recipes/).
|
||||
When you're adding a plugin to Talk, you can specify it in the `client` and/or
|
||||
the `server` section. If you only want to enable the server side component of a
|
||||
plugin, you simply only specify the plugin in the `server` section. If you only
|
||||
want the client side plugin, the `client` section.
|
||||
|
||||
Plugins listed in the [Plugins Directory](/talk/plugins-directory/) will
|
||||
indicate if they have/support a client/server plugin, and should be activated
|
||||
accordingly.
|
||||
|
||||
## Plugin Registration
|
||||
|
||||
@@ -117,3 +122,9 @@ assets inside the image as well.
|
||||
|
||||
For more information on the onbuild image, refer to the
|
||||
[Installation from Docker](/talk/installation-from-docker/) documentation.
|
||||
|
||||
## Recipes
|
||||
|
||||
Recipes are plugin templates provided by the Coral Core team. Developers can use
|
||||
these recipes to build their own plugins. You can find all the Talk recipes
|
||||
here: [github.com/coralproject/talk-recipes](https://github.com/coralproject/talk-recipes/).
|
||||
|
||||
@@ -3,8 +3,9 @@ title: Plugins Directory
|
||||
permalink: /plugins-directory/
|
||||
layout: plugins
|
||||
data: plugins
|
||||
class: plugins
|
||||
---
|
||||
|
||||
Talk provides a growing ecosystem of plugins that interact with our extensive
|
||||
Server and Client API's. Below you can search for a plugin to use with Talk and
|
||||
discover what their requirements and configuration are.
|
||||
discover what their requirements and configuration are.
|
||||
|
||||
+5
-4
@@ -4,9 +4,9 @@
|
||||
<h1>{{ page.title }}</h1>
|
||||
<hr/>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{{ page.content }}
|
||||
|
||||
|
||||
<div class="form-group mt-5">
|
||||
<div class="clearfix">
|
||||
<label for="exampleInputEmail1">Plugin Search</label>
|
||||
@@ -15,6 +15,7 @@
|
||||
<input type="text" class="form-control" id="plugin-search-input" aria-describedby="pluginSearchHelp">
|
||||
<small id="pluginSearchHelp" class="form-text text-muted">Enter a few keywords about the plugin to filter the list</small>
|
||||
</div>
|
||||
|
||||
<div class="row plugins">
|
||||
{% for plugin in _.sortBy(site.data[page.data], 'name') %}
|
||||
<div class="col-sm-6 plugin d-block">
|
||||
@@ -25,7 +26,7 @@
|
||||
{% if plugin.tags %}
|
||||
<p class="card-text">
|
||||
{% for tag in plugin.tags %}
|
||||
<span class="badge badge-{% if tag == "default" %}success{% else %}light{% endif %}">{{ tag }}</span>
|
||||
<a class="plain-link" title="Search for plugins with the {{ tag }} tag" href="?q={{ tag }}"><span class="badge badge-light badge-tag badge-tag-{{ _.kebabCase(tag) }}">{{ tag }}</span></a>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
@@ -35,4 +36,4 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</article>
|
||||
<script>window.SEARCH_INDEX = {{ lunr_index(site.data[page.data]) }}</script>
|
||||
<script>window.SEARCH_INDEX = {{ lunr_index(site.data[page.data]) }}</script>
|
||||
|
||||
+14
@@ -448,3 +448,17 @@ a.brand {
|
||||
.plugin {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.badge-tag {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.badge-tag-default {
|
||||
background: #28a745;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.badge-tag-gdpr {
|
||||
background: rgb(0, 102, 176);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
+17
@@ -1,6 +1,17 @@
|
||||
/* global lunr */
|
||||
/* eslint-env browser */
|
||||
|
||||
// Sourced from https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
|
||||
function getParameterByName(name, url) {
|
||||
if (!url) url = window.location.href;
|
||||
name = name.replace(/[\[\]]/g, '\\$&');
|
||||
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
|
||||
results = regex.exec(url);
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
// Sourced from https://github.com/hexojs/site/blob/8e8ed4901769abbf76263125f82832df76ced58b/themes/navy/source/js/plugins.js.
|
||||
(function() {
|
||||
'use strict';
|
||||
@@ -60,6 +71,12 @@
|
||||
updateCount(elements.length);
|
||||
}
|
||||
|
||||
var searchParam = getParameterByName('q');
|
||||
if (searchParam && searchParam.length > 0) {
|
||||
$input.value = searchParam;
|
||||
search(searchParam);
|
||||
}
|
||||
|
||||
$input.addEventListener('input', function() {
|
||||
var value = this.value;
|
||||
|
||||
|
||||
+2
-1
@@ -250,8 +250,9 @@ en:
|
||||
ALREADY_EXISTS: "Resource already exists"
|
||||
INVALID_ASSET_URL: "Assert URL is invalid"
|
||||
CANNOT_IGNORE_STAFF: "Cannot ignore Staff members."
|
||||
INCORRECT_PASSWORD: "Incorrect Password"
|
||||
email: "Please enter a valid email."
|
||||
DELETION_NOT_SCHEDULED: "Deletion was not scheduled"
|
||||
email: "Not a valid E-Mail"
|
||||
confirm_password: "Passwords don't match. Please check again"
|
||||
network_error: "Failed to connect to server. Check your internet connection and try again."
|
||||
email_not_verified: "Email address {0} not verified."
|
||||
|
||||
@@ -243,6 +243,7 @@ es:
|
||||
ALREADY_EXISTS: "Resource already exists"
|
||||
INVALID_ASSET_URL: "La URL del articulo no es valida"
|
||||
CANNOT_IGNORE_STAFF: "Cannot ignore Staff members."
|
||||
INCORRECT_PASSWORD: "Contraseña Incorrecta"
|
||||
email: "No es un correo válido"
|
||||
confirm_password: "Las contraseñas no coinciden. Inténtelo nuevamente"
|
||||
network_error: "Error al conectar con el servidor. Compruebe su conexión a Internet y vuelva a intentarlo."
|
||||
|
||||
@@ -27,5 +27,6 @@ export {
|
||||
withSetCommentStatus,
|
||||
withChangePassword,
|
||||
withChangeUsername,
|
||||
withUpdateEmailAddress,
|
||||
} from 'coral-framework/graphql/mutations';
|
||||
export { compose } from 'recompose';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"server": [
|
||||
"talk-plugin-auth",
|
||||
"talk-plugin-featured-comments",
|
||||
"talk-plugin-respect",
|
||||
"talk-plugin-profile-data"
|
||||
"talk-plugin-local-auth",
|
||||
"talk-plugin-profile-data",
|
||||
"talk-plugin-respect"
|
||||
],
|
||||
"client": [
|
||||
"talk-plugin-auth",
|
||||
@@ -11,15 +11,16 @@
|
||||
"talk-plugin-featured-comments",
|
||||
"talk-plugin-flag-details",
|
||||
"talk-plugin-ignore-user",
|
||||
"talk-plugin-local-auth",
|
||||
"talk-plugin-member-since",
|
||||
"talk-plugin-moderation-actions",
|
||||
"talk-plugin-permalink",
|
||||
"talk-plugin-profile-data",
|
||||
"talk-plugin-respect",
|
||||
"talk-plugin-sort-most-replied",
|
||||
"talk-plugin-sort-most-respected",
|
||||
"talk-plugin-sort-newest",
|
||||
"talk-plugin-sort-oldest",
|
||||
"talk-plugin-viewing-options",
|
||||
"talk-plugin-profile-data"
|
||||
"talk-plugin-viewing-options"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -14,3 +14,9 @@ utilize our internal authentication system.
|
||||
|
||||
To sync Talk auth with your own auth systems, you can use this plugin as a
|
||||
template.
|
||||
|
||||
## GDPR Compliance
|
||||
|
||||
In order to facilitate compliance with the
|
||||
[EU General Data Protection Regulation (GDPR)](https://www.eugdpr.org/), you
|
||||
should review our [GDPR Compliance](/talk/integrating/gdpr/) guidelines.
|
||||
|
||||
@@ -154,8 +154,20 @@ en:
|
||||
bottom_note: "Note: You will not be able to change your username again for 14 days"
|
||||
confirm_changes: "Confirm Changes"
|
||||
username_does_not_match: "Username does not match"
|
||||
changed_username_success_msg: "Username Changed - Your username has been successfully changed. You will not be able to change your user name for 14 days."
|
||||
cant_be_equal: "Your new {0} must be different to your current one"
|
||||
change_username_attempt: "Username can't be updated. Usernames can be changed every 14 days"
|
||||
change_email:
|
||||
confirm_email_change: "Confirm Email Address Change"
|
||||
description: "You are attempting to change your email address. Your new email address will be used for your login and to receive account notifications."
|
||||
old_email: "Old Email Address"
|
||||
new_email: "New Email Address"
|
||||
enter_password: "Enter Password"
|
||||
incorrect_password: "Incorrect Password"
|
||||
confirm_change: "Confirm Change"
|
||||
cancel: "Cancel"
|
||||
change_email_msg: "Email Address Changed - Your email address has been successfully changed. This email address will now be used for signing in and email notifications."
|
||||
changed_username_success_msg: "Username Changed - Your username has been successfully changed. You will not be able to change your user name for 14 days."
|
||||
change_username_attempt: "Username can't be updated. Usernames can only be changed every 14 days."
|
||||
de:
|
||||
talk-plugin-auth:
|
||||
login:
|
||||
|
||||
@@ -27,4 +27,10 @@ Configuration:
|
||||
or by visiting the
|
||||
[Creating an App ID](https://developers.facebook.com/docs/apps/register)
|
||||
guide. This is only required while the `talk-plugin-facebook-auth` plugin is
|
||||
enabled.
|
||||
enabled.
|
||||
|
||||
## GDPR Compliance
|
||||
|
||||
In order to facilitate compliance with the
|
||||
[EU General Data Protection Regulation (GDPR)](https://www.eugdpr.org/), you
|
||||
should review our [GDPR Compliance](/talk/integrating/gdpr/) guidelines.
|
||||
|
||||
@@ -27,3 +27,9 @@ Configuration:
|
||||
- `TALK_GOOGLE_CLIENT_SECRET` (**required**) - The Google OAuth2 client ID for
|
||||
your Google login web app. You can learn more about getting a Google Client
|
||||
ID at the [Google API Console](https://console.developers.google.com/apis/).
|
||||
|
||||
## GDPR Compliance
|
||||
|
||||
In order to facilitate compliance with the
|
||||
[EU General Data Protection Regulation (GDPR)](https://www.eugdpr.org/), you
|
||||
should review our [GDPR Compliance](/talk/integrating/gdpr/) guidelines.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
title: talk-plugin-local-auth
|
||||
permalink: /plugin/talk-plugin-local-auth/
|
||||
layout: plugin
|
||||
plugin:
|
||||
name: talk-plugin-local-auth
|
||||
default: true
|
||||
provides:
|
||||
- Client
|
||||
- Server
|
||||
---
|
||||
|
||||
This plugin will eventually contain all the local authentication code that is
|
||||
responsible for creating, resetting, and managing accounts provided locally
|
||||
through an email and password based login.
|
||||
|
||||
## Features
|
||||
|
||||
- *Email Change*: Allows users to change their existing email address on their account.
|
||||
- *Local Account Association*: Allows users that have signed up with an external auth strategy (such as Google) the ability to associate a email address and password for login. **Note: Existing users with external authentication will be prompted to setup a local account when they sign in and when new users create an account.**
|
||||
|
||||
## GDPR Compliance
|
||||
|
||||
In order to facilitate compliance with the
|
||||
[EU General Data Protection Regulation (GDPR)](https://www.eugdpr.org/), you
|
||||
should review our [GDPR Compliance](/talk/integrating/gdpr/) guidelines.
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "@coralproject/eslint-config-talk/client"
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
.dialog {
|
||||
border: none;
|
||||
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
|
||||
width: 320px;
|
||||
top: 10px;
|
||||
font-family: Helvetica, 'Helvetica Neue', Verdana, sans-serif;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
padding: 12px 20px;
|
||||
}
|
||||
|
||||
.close {
|
||||
font-size: 20px;
|
||||
line-height: 14px;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
color: #363636;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: #6b6b6b;
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.3em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 1em;
|
||||
line-height: 20px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
color: #4C4C4D;
|
||||
font-size: 1em;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.bottomActions {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.emailChange {
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.cancel {
|
||||
border: 1px solid #787d80;
|
||||
background-color: transparent;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
line-height: normal;
|
||||
|
||||
&:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
}
|
||||
|
||||
.confirmChanges {
|
||||
background-color: #3498DB;
|
||||
border-color: #3498DB;
|
||||
color: white;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
|
||||
&:hover {
|
||||
background-color: #3ba3ec;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styles from './ChangeEmailContentDialog.css';
|
||||
import InputField from './InputField';
|
||||
import { Button } from 'plugin-api/beta/client/components/ui';
|
||||
import { t } from 'plugin-api/beta/client/services';
|
||||
|
||||
class ChangeEmailContentDialog extends React.Component {
|
||||
state = {
|
||||
showError: false,
|
||||
};
|
||||
|
||||
showError = () => {
|
||||
this.setState({
|
||||
showError: true,
|
||||
});
|
||||
};
|
||||
|
||||
confirmChanges = async () => {
|
||||
await this.props.save();
|
||||
this.props.next();
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<span className={styles.close} onClick={this.props.cancel}>
|
||||
×
|
||||
</span>
|
||||
<h1 className={styles.title}>
|
||||
{t('talk-plugin-local-auth.change_email.confirm_email_change')}
|
||||
</h1>
|
||||
<div className={styles.content}>
|
||||
<p className={styles.description}>
|
||||
{t('talk-plugin-local-auth.change_email.description')}
|
||||
</p>
|
||||
<div className={styles.emailChange}>
|
||||
<span className={styles.item}>
|
||||
{t('talk-plugin-local-auth.change_email.old_email')}:{' '}
|
||||
{this.props.email}
|
||||
</span>
|
||||
<span className={styles.item}>
|
||||
{t('talk-plugin-local-auth.change_email.new_email')}:{' '}
|
||||
{this.props.formData.newEmail}
|
||||
</span>
|
||||
</div>
|
||||
<form>
|
||||
<InputField
|
||||
id="confirmPassword"
|
||||
label={t('talk-plugin-local-auth.change_email.enter_password')}
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
onChange={this.props.onChange}
|
||||
defaultValue=""
|
||||
hasError={
|
||||
!this.props.formData.confirmPassword && this.state.showError
|
||||
}
|
||||
errorMsg={t(
|
||||
'talk-plugin-local-auth.change_email.incorrect_password'
|
||||
)}
|
||||
showError={this.state.showError}
|
||||
columnDisplay
|
||||
showSuccess={false}
|
||||
/>
|
||||
</form>
|
||||
<div className={styles.bottomActions}>
|
||||
<Button className={styles.cancel} onClick={this.props.cancel}>
|
||||
{t('talk-plugin-local-auth.change_email.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
className={styles.confirmChanges}
|
||||
onClick={this.confirmChanges}
|
||||
>
|
||||
{t('talk-plugin-local-auth.change_email.confirm_change')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ChangeEmailContentDialog.propTypes = {
|
||||
save: PropTypes.func,
|
||||
next: PropTypes.func,
|
||||
cancel: PropTypes.func,
|
||||
onChange: PropTypes.func,
|
||||
formData: PropTypes.object,
|
||||
email: PropTypes.string,
|
||||
};
|
||||
|
||||
export default ChangeEmailContentDialog;
|
||||
@@ -0,0 +1,92 @@
|
||||
.container {
|
||||
position: relative;
|
||||
color: #202020;
|
||||
border-radius: 2px;
|
||||
border: solid 1px transparent;
|
||||
box-sizing: border-box;
|
||||
justify-content: space-between;
|
||||
|
||||
&.editing {
|
||||
padding: 10px;
|
||||
border-color: #979797;
|
||||
background-color: #EDEDED;
|
||||
|
||||
.actions {
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.actions {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: #202020;
|
||||
margin: 0 0 20px;
|
||||
}
|
||||
|
||||
.detailBottomBox {
|
||||
display: block;
|
||||
padding-top: 4px;
|
||||
text-align: right;
|
||||
width: 230px;
|
||||
}
|
||||
|
||||
.detailLink {
|
||||
color: #00538A;
|
||||
text-decoration: none;
|
||||
font-size: 0.9em;
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.button {
|
||||
border: 1px solid #787d80;
|
||||
background-color: transparent;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.saveButton {
|
||||
background-color: #3498DB;
|
||||
border-color: #3498DB;
|
||||
color: white;
|
||||
|
||||
> i {
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #399ee2;
|
||||
color: white;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
border-color: #e0e0e0;
|
||||
|
||||
&:hover {
|
||||
background-color: #e0e0e0;
|
||||
color: #4f5c67;
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cancelButton {
|
||||
color:#787D80;
|
||||
margin-top: 6px;
|
||||
font-size: 0.9em;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import cn from 'classnames';
|
||||
import styles from './ChangePassword.css';
|
||||
import { Button } from 'plugin-api/beta/client/components/ui';
|
||||
import validate from 'coral-framework/helpers/validate';
|
||||
import errorMsj from 'coral-framework/helpers/error';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import { t } from 'plugin-api/beta/client/services';
|
||||
import InputField from './InputField';
|
||||
import { getErrorMessages } from 'coral-framework/utils';
|
||||
|
||||
const initialState = {
|
||||
editing: false,
|
||||
showErrors: true,
|
||||
errors: {},
|
||||
formData: {},
|
||||
};
|
||||
|
||||
class ChangePassword extends React.Component {
|
||||
state = initialState;
|
||||
validKeys = ['oldPassword', 'newPassword', 'confirmNewPassword'];
|
||||
|
||||
onChange = e => {
|
||||
const { name, value, type } = e.target;
|
||||
this.setState(
|
||||
state => ({
|
||||
formData: {
|
||||
...state.formData,
|
||||
[name]: value,
|
||||
},
|
||||
}),
|
||||
() => {
|
||||
this.fieldValidation(value, type, name);
|
||||
|
||||
// Perform equality validation if password fields have changed
|
||||
if (name === 'newPassword' || name === 'confirmNewPassword') {
|
||||
this.equalityValidation('newPassword', 'confirmNewPassword');
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
equalityValidation = (field, field2) => {
|
||||
const cond = this.state.formData[field] === this.state.formData[field2];
|
||||
if (!cond) {
|
||||
this.addError({
|
||||
[field2]: t(
|
||||
'talk-plugin-local-auth.change_password.passwords_dont_match'
|
||||
),
|
||||
});
|
||||
} else {
|
||||
this.removeError(field2);
|
||||
}
|
||||
return cond;
|
||||
};
|
||||
|
||||
fieldValidation = (value, type, name) => {
|
||||
if (!value.length) {
|
||||
this.addError({
|
||||
[name]: t('talk-plugin-local-auth.change_password.required_field'),
|
||||
});
|
||||
} else if (!validate[type](value)) {
|
||||
this.addError({ [name]: errorMsj[type] });
|
||||
} else {
|
||||
this.removeError(name);
|
||||
}
|
||||
};
|
||||
|
||||
hasError = err => {
|
||||
return Object.keys(this.state.errors).indexOf(err) !== -1;
|
||||
};
|
||||
|
||||
addError = err => {
|
||||
this.setState(({ errors }) => ({
|
||||
errors: { ...errors, ...err },
|
||||
}));
|
||||
};
|
||||
|
||||
removeError = errKey => {
|
||||
this.setState(state => {
|
||||
const { [errKey]: _, ...errors } = state.errors;
|
||||
return {
|
||||
errors,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
enableEditing = () => {
|
||||
this.setState({
|
||||
editing: true,
|
||||
});
|
||||
};
|
||||
|
||||
isSubmitBlocked = () => {
|
||||
const formHasErrors = !!Object.keys(this.state.errors).length;
|
||||
const formIncomplete = !isEqual(
|
||||
Object.keys(this.state.formData),
|
||||
this.validKeys
|
||||
);
|
||||
return formHasErrors || formIncomplete;
|
||||
};
|
||||
|
||||
clearForm = () => {
|
||||
this.setState(initialState);
|
||||
};
|
||||
|
||||
onSave = async () => {
|
||||
const { oldPassword, newPassword } = this.state.formData;
|
||||
|
||||
try {
|
||||
await this.props.changePassword({
|
||||
oldPassword,
|
||||
newPassword,
|
||||
});
|
||||
this.props.notify(
|
||||
'success',
|
||||
t('talk-plugin-local-auth.change_password.changed_password_msg')
|
||||
);
|
||||
} catch (err) {
|
||||
this.props.notify('error', getErrorMessages(err));
|
||||
}
|
||||
|
||||
this.clearForm();
|
||||
this.disableEditing();
|
||||
};
|
||||
|
||||
disableEditing = () => {
|
||||
this.setState({
|
||||
editing: false,
|
||||
});
|
||||
};
|
||||
|
||||
cancel = () => {
|
||||
this.clearForm();
|
||||
this.disableEditing();
|
||||
};
|
||||
|
||||
render() {
|
||||
const { editing, errors } = this.state;
|
||||
|
||||
return (
|
||||
<section
|
||||
className={cn(
|
||||
'talk-plugin-local-auth--change-password',
|
||||
styles.container,
|
||||
{
|
||||
[styles.editing]: editing,
|
||||
}
|
||||
)}
|
||||
>
|
||||
<h3 className={styles.title}>
|
||||
{t('talk-plugin-local-auth.change_password.change_password')}
|
||||
</h3>
|
||||
{editing && (
|
||||
<form className="talk-plugin-local-auth--change-password-form">
|
||||
<InputField
|
||||
id="oldPassword"
|
||||
label="Old Password"
|
||||
name="oldPassword"
|
||||
type="password"
|
||||
onChange={this.onChange}
|
||||
value={this.state.formData.oldPassword}
|
||||
hasError={this.hasError('oldPassword')}
|
||||
errorMsg={errors['oldPassword']}
|
||||
showErrors
|
||||
>
|
||||
<span className={styles.detailBottomBox}>
|
||||
<a className={styles.detailLink}>
|
||||
{t('talk-plugin-local-auth.change_password.forgot_password')}
|
||||
</a>
|
||||
</span>
|
||||
</InputField>
|
||||
<InputField
|
||||
id="newPassword"
|
||||
label="New Password"
|
||||
name="newPassword"
|
||||
type="password"
|
||||
onChange={this.onChange}
|
||||
value={this.state.formData.newPassword}
|
||||
hasError={this.hasError('newPassword')}
|
||||
errorMsg={errors['newPassword']}
|
||||
showErrors
|
||||
/>
|
||||
<InputField
|
||||
id="confirmNewPassword"
|
||||
label="Confirm New Password"
|
||||
name="confirmNewPassword"
|
||||
type="password"
|
||||
onChange={this.onChange}
|
||||
value={this.state.formData.confirmNewPassword}
|
||||
hasError={this.hasError('confirmNewPassword')}
|
||||
errorMsg={errors['confirmNewPassword']}
|
||||
showErrors
|
||||
/>
|
||||
</form>
|
||||
)}
|
||||
{editing ? (
|
||||
<div className={styles.actions}>
|
||||
<Button
|
||||
className={cn(styles.button, styles.saveButton)}
|
||||
icon="save"
|
||||
onClick={this.onSave}
|
||||
disabled={this.isSubmitBlocked()}
|
||||
>
|
||||
{t('talk-plugin-local-auth.change_password.save')}
|
||||
</Button>
|
||||
<a className={styles.cancelButton} onClick={this.cancel}>
|
||||
{t('talk-plugin-local-auth.change_password.cancel')}
|
||||
</a>
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.actions}>
|
||||
<Button className={styles.button} onClick={this.enableEditing}>
|
||||
{t('talk-plugin-local-auth.change_password.edit')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ChangePassword.propTypes = {
|
||||
changePassword: PropTypes.func.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default ChangePassword;
|
||||
@@ -0,0 +1,73 @@
|
||||
.close {
|
||||
font-size: 20px;
|
||||
line-height: 14px;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
color: #363636;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: #6b6b6b;
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.3em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 1em;
|
||||
line-height: 20px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
color: #4C4C4D;
|
||||
font-size: 1em;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.bottomNote {
|
||||
font-size: 0.9em;
|
||||
line-height: 20px;
|
||||
padding-top: 10px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.bottomActions {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.usernamesChange {
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.cancel {
|
||||
border: 1px solid #787d80;
|
||||
background-color: transparent;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
line-height: normal;
|
||||
|
||||
&:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
}
|
||||
|
||||
.confirmChanges {
|
||||
background-color: #3498DB;
|
||||
border-color: #3498DB;
|
||||
color: white;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
|
||||
&:hover {
|
||||
background-color: #3ba3ec;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styles from './ChangeUsernameContentDialog.css';
|
||||
import InputField from './InputField';
|
||||
import { Button } from 'plugin-api/beta/client/components/ui';
|
||||
import { t } from 'plugin-api/beta/client/services';
|
||||
|
||||
class ChangeUsernameContentDialog extends React.Component {
|
||||
state = {
|
||||
showError: false,
|
||||
};
|
||||
|
||||
showError = () => {
|
||||
this.setState({
|
||||
showError: true,
|
||||
});
|
||||
};
|
||||
|
||||
confirmChanges = async () => {
|
||||
if (this.formHasError()) {
|
||||
this.showError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.props.canUsernameBeUpdated) {
|
||||
this.props.notify(
|
||||
'error',
|
||||
t('talk-plugin-local-auth.change_username.change_username_attempt')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.props.save();
|
||||
this.props.next();
|
||||
};
|
||||
|
||||
formHasError = () =>
|
||||
this.props.formData.confirmNewUsername !== this.props.formData.newUsername;
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<span className={styles.close} onClick={this.props.cancel}>
|
||||
×
|
||||
</span>
|
||||
<h1 className={styles.title}>
|
||||
{t('talk-plugin-local-auth.change_username.confirm_username_change')}
|
||||
</h1>
|
||||
<div className={styles.content}>
|
||||
<p className={styles.description}>
|
||||
{t('talk-plugin-local-auth.change_username.description')}
|
||||
</p>
|
||||
<div className={styles.usernamesChange}>
|
||||
<span className={styles.item}>
|
||||
{t('talk-plugin-local-auth.change_username.old_username')}:{' '}
|
||||
{this.props.username}
|
||||
</span>
|
||||
<span className={styles.item}>
|
||||
{t('talk-plugin-local-auth.change_username.new_username')}:{' '}
|
||||
{this.props.formData.newUsername}
|
||||
</span>
|
||||
</div>
|
||||
<form>
|
||||
<InputField
|
||||
id="confirmNewUsername"
|
||||
label="Re-enter new username"
|
||||
name="confirmNewUsername"
|
||||
type="text"
|
||||
onChange={this.props.onChange}
|
||||
defaultValue=""
|
||||
hasError={this.formHasError() && this.state.showError}
|
||||
errorMsg={t(
|
||||
'talk-plugin-local-auth.change_username.username_does_not_match'
|
||||
)}
|
||||
showError={this.state.showError}
|
||||
columnDisplay
|
||||
showSuccess={false}
|
||||
validationType="username"
|
||||
>
|
||||
<span className={styles.bottomNote}>
|
||||
{t('talk-plugin-local-auth.change_username.bottom_note')}
|
||||
</span>
|
||||
</InputField>
|
||||
</form>
|
||||
<div className={styles.bottomActions}>
|
||||
<Button className={styles.cancel} onClick={this.props.cancel}>
|
||||
{t('talk-plugin-local-auth.change_username.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
className={styles.confirmChanges}
|
||||
onClick={this.confirmChanges}
|
||||
>
|
||||
{t('talk-plugin-local-auth.change_username.confirm_changes')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ChangeUsernameContentDialog.propTypes = {
|
||||
save: PropTypes.func,
|
||||
next: PropTypes.func,
|
||||
cancel: PropTypes.func,
|
||||
onChange: PropTypes.func,
|
||||
formData: PropTypes.object,
|
||||
username: PropTypes.string,
|
||||
canUsernameBeUpdated: PropTypes.bool.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default ChangeUsernameContentDialog;
|
||||
@@ -0,0 +1,84 @@
|
||||
.dialog {
|
||||
border: none;
|
||||
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
|
||||
width: 320px;
|
||||
top: 10px;
|
||||
font-family: Helvetica, 'Helvetica Neue', Verdana, sans-serif;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
padding: 12px 20px;
|
||||
}
|
||||
|
||||
.close {
|
||||
font-size: 20px;
|
||||
line-height: 14px;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
color: #363636;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: #6b6b6b;
|
||||
}
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.3em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 1em;
|
||||
line-height: 20px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
color: #4C4C4D;
|
||||
font-size: 1em;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.bottomNote {
|
||||
font-size: 0.9em;
|
||||
line-height: 20px;
|
||||
padding-top: 10px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.bottomActions {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.usernamesChange {
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.cancel {
|
||||
border: 1px solid #787d80;
|
||||
background-color: transparent;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
line-height: normal;
|
||||
|
||||
&:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
}
|
||||
|
||||
.confirmChanges {
|
||||
background-color: #3498DB;
|
||||
border-color: #3498DB;
|
||||
color: white;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
|
||||
&:hover {
|
||||
background-color: #3ba3ec;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import cn from 'classnames';
|
||||
import styles from './ChangeUsernameDialog.css';
|
||||
import InputField from './InputField';
|
||||
import { Button, Dialog } from 'plugin-api/beta/client/components/ui';
|
||||
import { t } from 'plugin-api/beta/client/services';
|
||||
|
||||
class ChangeUsernameDialog extends React.Component {
|
||||
state = {
|
||||
showError: false,
|
||||
};
|
||||
|
||||
showError = () => {
|
||||
this.setState({
|
||||
showError: true,
|
||||
});
|
||||
};
|
||||
|
||||
confirmChanges = async () => {
|
||||
if (this.formHasError()) {
|
||||
this.showError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.props.canUsernameBeUpdated) {
|
||||
this.props.notify(
|
||||
'error',
|
||||
t('talk-plugin-local-auth.change_username.change_username_attempt')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.props.saveChanges();
|
||||
this.props.closeDialog();
|
||||
};
|
||||
|
||||
formHasError = () =>
|
||||
this.props.formData.confirmNewUsername !== this.props.formData.newUsername;
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Dialog
|
||||
open={this.props.showDialog}
|
||||
className={cn(
|
||||
styles.dialog,
|
||||
'talk-plugin-local-auth--edit-profile-dialog'
|
||||
)}
|
||||
>
|
||||
<span className={styles.close} onClick={this.props.closeDialog}>
|
||||
×
|
||||
</span>
|
||||
<h1 className={styles.title}>
|
||||
{t('talk-plugin-local-auth.change_username.confirm_username_change')}
|
||||
</h1>
|
||||
<div className={styles.content}>
|
||||
<p className={styles.description}>
|
||||
{t('talk-plugin-local-auth.change_username.description')}
|
||||
</p>
|
||||
<div className={styles.usernamesChange}>
|
||||
<span className={styles.item}>
|
||||
{t('talk-plugin-local-auth.change_username.old_username')}:{' '}
|
||||
{this.props.username}
|
||||
</span>
|
||||
<span className={styles.item}>
|
||||
{t('talk-plugin-local-auth.change_username.new_username')}:{' '}
|
||||
{this.props.formData.newUsername}
|
||||
</span>
|
||||
</div>
|
||||
<form>
|
||||
<InputField
|
||||
id="confirmNewUsername"
|
||||
label="Re-enter new username"
|
||||
name="confirmNewUsername"
|
||||
type="text"
|
||||
onChange={this.props.onChange}
|
||||
defaultValue=""
|
||||
hasError={this.formHasError() && this.state.showError}
|
||||
errorMsg={t(
|
||||
'talk-plugin-local-auth.change_username.username_does_not_match'
|
||||
)}
|
||||
showError={this.state.showError}
|
||||
columnDisplay
|
||||
showSuccess={false}
|
||||
validationType="username"
|
||||
>
|
||||
<span className={styles.bottomNote}>
|
||||
{t('talk-plugin-local-auth.change_username.bottom_note')}
|
||||
</span>
|
||||
</InputField>
|
||||
</form>
|
||||
<div className={styles.bottomActions}>
|
||||
<Button className={styles.cancel}>
|
||||
{t('talk-plugin-local-auth.change_username.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
className={styles.confirmChanges}
|
||||
onClick={this.confirmChanges}
|
||||
>
|
||||
{t('talk-plugin-local-auth.change_username.confirm_changes')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ChangeUsernameDialog.propTypes = {
|
||||
saveChanges: PropTypes.func,
|
||||
closeDialog: PropTypes.func,
|
||||
showDialog: PropTypes.bool,
|
||||
onChange: PropTypes.func,
|
||||
username: PropTypes.string,
|
||||
formData: PropTypes.object,
|
||||
canUsernameBeUpdated: PropTypes.bool.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default ChangeUsernameDialog;
|
||||
@@ -0,0 +1,10 @@
|
||||
.dialog {
|
||||
border: none;
|
||||
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
|
||||
width: 320px;
|
||||
top: 10px;
|
||||
font-family: Helvetica, 'Helvetica Neue', Verdana, sans-serif;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
padding: 12px 20px;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import React from 'react';
|
||||
import cn from 'classnames';
|
||||
import PropTypes from 'prop-types';
|
||||
import styles from './ConfirmChangesDialog.css';
|
||||
import { Dialog } from 'plugin-api/beta/client/components/ui';
|
||||
|
||||
const initialState = { step: 0 };
|
||||
|
||||
class ConfirmChangesDialog extends React.Component {
|
||||
state = initialState;
|
||||
|
||||
goToNextStep = () => {
|
||||
this.setState(({ step }) => ({
|
||||
step: step + 1,
|
||||
}));
|
||||
};
|
||||
|
||||
clear = () => {
|
||||
this.setState(initialState);
|
||||
};
|
||||
|
||||
cancel = () => {
|
||||
this.clear();
|
||||
this.props.closeDialog();
|
||||
};
|
||||
|
||||
continue = () => {
|
||||
this.goToNextStep();
|
||||
};
|
||||
|
||||
finish = () => {
|
||||
this.clear();
|
||||
this.props.closeDialog();
|
||||
this.props.finish();
|
||||
};
|
||||
|
||||
renderSteps = () => {
|
||||
const steps = React.Children.toArray(this.props.children)
|
||||
.filter(child => child.props.enable)
|
||||
.filter((_, i) => i === this.state.step);
|
||||
|
||||
return steps.map(child => {
|
||||
return React.cloneElement(child, {
|
||||
goToNextStep: this.goToNextStep,
|
||||
clear: this.clear,
|
||||
cancel: this.cancel,
|
||||
next:
|
||||
this.state.step === steps.length - 1 ? this.finish : this.continue,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Dialog
|
||||
open={this.props.showDialog}
|
||||
className={cn(
|
||||
styles.dialog,
|
||||
'talk-plugin-local-auth--edit-profile-dialog'
|
||||
)}
|
||||
>
|
||||
{this.renderSteps()}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ConfirmChangesDialog.propTypes = {
|
||||
children: PropTypes.node,
|
||||
closeDialog: PropTypes.func,
|
||||
showDialog: PropTypes.bool,
|
||||
finish: PropTypes.func,
|
||||
};
|
||||
|
||||
export default ConfirmChangesDialog;
|
||||
@@ -0,0 +1,8 @@
|
||||
.errorMsg {
|
||||
color: #FA4643;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.warningIcon {
|
||||
color: #FA4643;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styles from './ErrorMessage.css';
|
||||
import { Icon } from 'plugin-api/beta/client/components/ui';
|
||||
|
||||
const ErrorMessage = ({ children }) => (
|
||||
<div className={styles.errorMsg}>
|
||||
<Icon className={styles.warningIcon} name="warning" />
|
||||
<span>{children}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
ErrorMessage.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default ErrorMessage;
|
||||
@@ -0,0 +1,84 @@
|
||||
|
||||
.detailItem {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.detailItemContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.columnDisplay {
|
||||
flex-direction: column;
|
||||
|
||||
.detailItemMessage {
|
||||
padding: 4px 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
.detailItemContent {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.detailInput {
|
||||
border: solid 1px #787D80;
|
||||
border-radius: 2px;
|
||||
background-color: white;
|
||||
height: 30px;
|
||||
display: inline-block;
|
||||
width: 230px;
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
|
||||
> .detailIcon {
|
||||
font-size: 1.2em;
|
||||
padding: 0 5px;
|
||||
color: #787D80;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
&.error {
|
||||
border: solid 2px #FA4643;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
background-color: #E0E0E0;
|
||||
}
|
||||
}
|
||||
|
||||
.detailLabel {
|
||||
color: #4C4C4D;
|
||||
font-size: 1em;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.detailValue {
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 1em;
|
||||
color: #000;
|
||||
outline: none;
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.detailItemMessage {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: 6px;
|
||||
|
||||
.warningIcon, .checkIcon {
|
||||
font-size: 17px;
|
||||
}
|
||||
}
|
||||
|
||||
.checkIcon {
|
||||
color: #00CD73;
|
||||
}
|
||||
|
||||
.warningIcon {
|
||||
color: #FA4643;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import cn from 'classnames';
|
||||
import styles from './InputField.css';
|
||||
import ErrorMessage from './ErrorMessage';
|
||||
import { Icon } from 'plugin-api/beta/client/components/ui';
|
||||
|
||||
const InputField = ({
|
||||
id = '',
|
||||
label = '',
|
||||
type = 'text',
|
||||
name = '',
|
||||
onChange = () => {},
|
||||
showError = true,
|
||||
hasError = false,
|
||||
errorMsg = '',
|
||||
children,
|
||||
columnDisplay = false,
|
||||
showSuccess = false,
|
||||
validationType = '',
|
||||
icon = '',
|
||||
value = '',
|
||||
defaultValue = '',
|
||||
disabled = false,
|
||||
}) => {
|
||||
const inputValue = {
|
||||
...(value ? { value } : {}),
|
||||
...(defaultValue ? { defaultValue } : {}),
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.detailItem}>
|
||||
<div className={cn(styles.detailItemContainer)}>
|
||||
{label && (
|
||||
<label className={styles.detailLabel} id={id}>
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<div
|
||||
className={cn(styles.detailItemContent, {
|
||||
[styles.columnDisplay]: columnDisplay,
|
||||
})}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
styles.detailInput,
|
||||
{ [styles.error]: hasError },
|
||||
{ [styles.disabled]: disabled }
|
||||
)}
|
||||
>
|
||||
{icon && <Icon name={icon} className={styles.detailIcon} />}
|
||||
<input
|
||||
id={id}
|
||||
type={type}
|
||||
name={name}
|
||||
className={styles.detailValue}
|
||||
onChange={onChange}
|
||||
autoComplete="off"
|
||||
data-validation-type={validationType}
|
||||
disabled={disabled}
|
||||
{...inputValue}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.detailItemMessage}>
|
||||
{!hasError &&
|
||||
showSuccess &&
|
||||
value && (
|
||||
<Icon className={styles.checkIcon} name="check_circle" />
|
||||
)}
|
||||
{hasError && showError && <ErrorMessage>{errorMsg}</ErrorMessage>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
InputField.propTypes = {
|
||||
id: PropTypes.string,
|
||||
disabled: PropTypes.bool,
|
||||
label: PropTypes.string,
|
||||
type: PropTypes.string,
|
||||
name: PropTypes.string.isRequired,
|
||||
onChange: PropTypes.func,
|
||||
value: PropTypes.string,
|
||||
defaultValue: PropTypes.string,
|
||||
icon: PropTypes.string,
|
||||
showError: PropTypes.bool,
|
||||
hasError: PropTypes.bool,
|
||||
errorMsg: PropTypes.string,
|
||||
children: PropTypes.node,
|
||||
columnDisplay: PropTypes.bool,
|
||||
showSuccess: PropTypes.bool,
|
||||
validationType: PropTypes.string,
|
||||
};
|
||||
|
||||
export default InputField;
|
||||
@@ -0,0 +1,122 @@
|
||||
.container {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
position: relative;
|
||||
color: #202020;
|
||||
padding: 10px;
|
||||
border-radius: 2px;
|
||||
box-sizing: border-box;
|
||||
justify-content: space-between;
|
||||
|
||||
&.editing {
|
||||
background-color: #EDEDED;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.actions {
|
||||
flex-grow: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.email {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.username {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.button {
|
||||
border: 1px solid #787d80;
|
||||
background-color: transparent;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.saveButton {
|
||||
background-color: #3498DB;
|
||||
border-color: #3498DB;
|
||||
color: white;
|
||||
|
||||
> i {
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #399ee2;
|
||||
color: white;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
border-color: #e0e0e0;
|
||||
|
||||
&:hover {
|
||||
background-color: #e0e0e0;
|
||||
color: #4f5c67;
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cancelButton {
|
||||
color:#787D80;
|
||||
margin-top: 6px;
|
||||
font-size: 0.9em;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.detailLabel {
|
||||
border: solid 1px #787D80;
|
||||
border-radius: 2px;
|
||||
background-color: white;
|
||||
height: 30px;
|
||||
display: inline-block;
|
||||
width: 230px;
|
||||
display: flex;
|
||||
|
||||
> .detailLabelIcon {
|
||||
font-size: 1.2em;
|
||||
padding: 0 5px;
|
||||
color: #787D80;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
background-color: #E0E0E0;
|
||||
}
|
||||
}
|
||||
|
||||
.detailValue {
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 1em;
|
||||
color: #000;
|
||||
height: 30px;
|
||||
outline: none;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.bottomText {
|
||||
color: #474747;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.detailList {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.detailItem {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
import React from 'react';
|
||||
import cn from 'classnames';
|
||||
import PropTypes from 'prop-types';
|
||||
import styles from './Profile.css';
|
||||
import { Button } from 'plugin-api/beta/client/components/ui';
|
||||
import { t } from 'plugin-api/beta/client/services';
|
||||
import InputField from './InputField';
|
||||
import { getErrorMessages } from 'coral-framework/utils';
|
||||
import validate from 'coral-framework/helpers/validate';
|
||||
import errorMsj from 'coral-framework/helpers/error';
|
||||
import ConfirmChangesDialog from './ConfirmChangesDialog';
|
||||
import ChangeUsernameContentDialog from './ChangeUsernameContentDialog';
|
||||
import ChangeEmailContentDialog from './ChangeEmailContentDialog';
|
||||
import { canUsernameBeUpdated } from 'coral-framework/utils/user';
|
||||
|
||||
const initialState = {
|
||||
editing: false,
|
||||
showDialog: false,
|
||||
formData: {},
|
||||
errors: {},
|
||||
};
|
||||
|
||||
class Profile extends React.Component {
|
||||
state = initialState;
|
||||
|
||||
clearForm = () => {
|
||||
this.setState(initialState);
|
||||
};
|
||||
|
||||
enableEditing = () => {
|
||||
this.setState({
|
||||
editing: true,
|
||||
});
|
||||
};
|
||||
|
||||
disableEditing = () => {
|
||||
this.setState({
|
||||
editing: false,
|
||||
});
|
||||
};
|
||||
|
||||
cancel = () => {
|
||||
this.clearForm();
|
||||
this.disableEditing();
|
||||
};
|
||||
|
||||
showDialog = () => {
|
||||
this.setState({
|
||||
showDialog: true,
|
||||
});
|
||||
};
|
||||
|
||||
onSave = async () => {
|
||||
this.showDialog();
|
||||
};
|
||||
|
||||
addError = err => {
|
||||
this.setState(({ errors }) => ({
|
||||
errors: { ...errors, ...err },
|
||||
}));
|
||||
};
|
||||
|
||||
removeError = errKey => {
|
||||
this.setState(state => {
|
||||
const { [errKey]: _, ...errors } = state.errors;
|
||||
return {
|
||||
errors,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
fieldValidation = (value, type, name) => {
|
||||
if (!value.length) {
|
||||
this.addError({
|
||||
[name]: t('talk-plugin-local-auth.change_password.required_field'),
|
||||
});
|
||||
} else if (!validate[type](value)) {
|
||||
this.addError({ [name]: errorMsj[type] });
|
||||
} else {
|
||||
this.removeError(name);
|
||||
}
|
||||
};
|
||||
|
||||
onChange = e => {
|
||||
const { name, value, type, dataset } = e.target;
|
||||
const validationType = dataset.validationType || type;
|
||||
|
||||
this.setState(
|
||||
state => ({
|
||||
formData: {
|
||||
...state.formData,
|
||||
[name]: value,
|
||||
},
|
||||
}),
|
||||
() => {
|
||||
this.fieldValidation(value, validationType, name);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
closeDialog = () => {
|
||||
this.setState({
|
||||
showDialog: false,
|
||||
});
|
||||
};
|
||||
|
||||
hasError = err => {
|
||||
return Object.keys(this.state.errors).indexOf(err) !== -1;
|
||||
};
|
||||
|
||||
isSaveEnabled = () => {
|
||||
const { formData } = this.state;
|
||||
const { emailAddress, username } = this.props;
|
||||
const formHasErrors = !!Object.keys(this.state.errors).length;
|
||||
const validUsername =
|
||||
formData.newUsername && formData.newUsername !== username;
|
||||
const validEmail = formData.newEmail && formData.newEmail !== emailAddress;
|
||||
|
||||
return !formHasErrors && (validUsername || validEmail);
|
||||
};
|
||||
|
||||
saveUsername = async () => {
|
||||
const { newUsername } = this.state.formData;
|
||||
const { changeUsername } = this.props;
|
||||
|
||||
try {
|
||||
await changeUsername(this.props.root.me.id, newUsername);
|
||||
this.props.notify(
|
||||
'success',
|
||||
t('talk-plugin-local-auth.change_username.changed_username_success_msg')
|
||||
);
|
||||
} catch (err) {
|
||||
this.props.notify('error', getErrorMessages(err));
|
||||
}
|
||||
};
|
||||
|
||||
saveEmail = async () => {
|
||||
const { newEmail, confirmPassword } = this.state.formData;
|
||||
|
||||
try {
|
||||
await this.props.updateEmailAddress({
|
||||
email: newEmail,
|
||||
confirmPassword,
|
||||
});
|
||||
this.props.notify(
|
||||
'success',
|
||||
t('talk-plugin-local-auth.change_email.change_email_msg')
|
||||
);
|
||||
} catch (err) {
|
||||
this.props.notify('error', getErrorMessages(err));
|
||||
}
|
||||
};
|
||||
|
||||
finish = () => {
|
||||
this.clearForm();
|
||||
this.disableEditing();
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
root: { me: { username, email, state: { status } } },
|
||||
notify,
|
||||
} = this.props;
|
||||
const { editing, formData, showDialog } = this.state;
|
||||
|
||||
return (
|
||||
<section
|
||||
className={cn(
|
||||
'talk-plugin-local-auth--edit-profile',
|
||||
styles.container,
|
||||
{
|
||||
[styles.editing]: editing,
|
||||
}
|
||||
)}
|
||||
>
|
||||
<ConfirmChangesDialog
|
||||
showDialog={showDialog}
|
||||
closeDialog={this.closeDialog}
|
||||
finish={this.finish}
|
||||
>
|
||||
<ChangeUsernameContentDialog
|
||||
notify={notify}
|
||||
canUsernameBeUpdated={canUsernameBeUpdated(status)}
|
||||
save={this.saveUsername}
|
||||
onChange={this.onChange}
|
||||
formData={this.state.formData}
|
||||
username={username}
|
||||
enable={formData.newUsername && username !== formData.newUsername}
|
||||
/>
|
||||
<ChangeEmailContentDialog
|
||||
save={this.saveEmail}
|
||||
onChange={this.onChange}
|
||||
formData={this.state.formData}
|
||||
email={email}
|
||||
enable={formData.newEmail && email !== formData.newEmail}
|
||||
/>
|
||||
</ConfirmChangesDialog>
|
||||
|
||||
{editing ? (
|
||||
<div className={styles.content}>
|
||||
<div className={styles.detailList}>
|
||||
<InputField
|
||||
icon="person"
|
||||
id="newUsername"
|
||||
name="newUsername"
|
||||
onChange={this.onChange}
|
||||
defaultValue={username}
|
||||
validationType="username"
|
||||
columnDisplay
|
||||
>
|
||||
<span className={styles.bottomText}>
|
||||
{t(
|
||||
'talk-plugin-local-auth.change_username.change_username_note'
|
||||
)}
|
||||
</span>
|
||||
</InputField>
|
||||
<InputField
|
||||
icon="email"
|
||||
id="newEmail"
|
||||
name="newEmail"
|
||||
onChange={this.onChange}
|
||||
defaultValue={email}
|
||||
validationType="email"
|
||||
columnDisplay
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.content}>
|
||||
<h2 className={styles.username}>{username}</h2>
|
||||
{email ? <p className={styles.email}>{email}</p> : null}
|
||||
</div>
|
||||
)}
|
||||
{editing ? (
|
||||
<div className={styles.actions}>
|
||||
<Button
|
||||
className={cn(styles.button, styles.saveButton)}
|
||||
icon="save"
|
||||
onClick={this.onSave}
|
||||
disabled={!this.isSaveEnabled()}
|
||||
>
|
||||
{t('talk-plugin-local-auth.change_username.save')}
|
||||
</Button>
|
||||
<a className={styles.cancelButton} onClick={this.cancel}>
|
||||
{t('talk-plugin-local-auth.change_username.cancel')}
|
||||
</a>
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.actions}>
|
||||
<Button
|
||||
className={styles.button}
|
||||
icon="settings"
|
||||
onClick={this.enableEditing}
|
||||
>
|
||||
{t('talk-plugin-local-auth.change_username.edit_profile')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Profile.propTypes = {
|
||||
updateEmailAddress: PropTypes.func.isRequired,
|
||||
changeUsername: PropTypes.func.isRequired,
|
||||
root: PropTypes.object.isRequired,
|
||||
changeUsername: PropTypes.func.isRequired,
|
||||
notify: PropTypes.func.isRequired,
|
||||
username: PropTypes.string,
|
||||
emailAddress: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Profile;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { compose } from 'react-apollo';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'plugin-api/beta/client/hocs';
|
||||
import ChangePassword from '../components/ChangePassword';
|
||||
import { notify } from 'coral-framework/actions/notification';
|
||||
import { withChangePassword } from 'plugin-api/beta/client/hocs';
|
||||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch);
|
||||
|
||||
export default compose(connect(null, mapDispatchToProps), withChangePassword)(
|
||||
ChangePassword
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
import { compose, gql } from 'react-apollo';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { connect, withFragments } from 'plugin-api/beta/client/hocs';
|
||||
import Profile from '../components/Profile';
|
||||
import { notify } from 'coral-framework/actions/notification';
|
||||
import { withChangeUsername } from 'plugin-api/beta/client/hocs';
|
||||
import { withUpdateEmailAddress } from '../hocs';
|
||||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({ notify }, dispatch);
|
||||
|
||||
const withData = withFragments({
|
||||
root: gql`
|
||||
fragment TalkPluginLocalAuth_Profile_root on RootQuery {
|
||||
me {
|
||||
id
|
||||
email
|
||||
username
|
||||
state {
|
||||
status {
|
||||
username {
|
||||
status
|
||||
history {
|
||||
status
|
||||
created_at
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
});
|
||||
|
||||
export default compose(
|
||||
connect(null, mapDispatchToProps),
|
||||
withChangeUsername,
|
||||
withUpdateEmailAddress,
|
||||
withData
|
||||
)(Profile);
|
||||
@@ -0,0 +1,35 @@
|
||||
import update from 'immutability-helper';
|
||||
import get from 'lodash/get';
|
||||
import findIndex from 'lodash/findIndex';
|
||||
|
||||
export default {
|
||||
mutations: {
|
||||
UpdateEmailAddress: () => ({
|
||||
updateQueries: {
|
||||
CoralEmbedStream_Profile: previousData => {
|
||||
// Find the local profile (if they have one).
|
||||
const localIndex = findIndex(get(previousData, 'me.profiles', []), {
|
||||
provider: 'local',
|
||||
});
|
||||
if (localIndex < 0) {
|
||||
return previousData;
|
||||
}
|
||||
|
||||
// Mutate the confirmedAt, because we changed the email address, they
|
||||
// can't possibly be confirmed now as well.
|
||||
return update(previousData, {
|
||||
me: {
|
||||
profiles: {
|
||||
[localIndex]: {
|
||||
confirmedAt: {
|
||||
$set: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
import { gql } from 'react-apollo';
|
||||
import update from 'immutability-helper';
|
||||
import withMutation from 'coral-framework/hocs/withMutation';
|
||||
|
||||
export const withUpdateEmailAddress = withMutation(
|
||||
gql`
|
||||
mutation UpdateEmailAddress($input: UpdateEmailAddressInput!) {
|
||||
updateEmailAddress(input: $input) {
|
||||
...UpdateEmailAddressResponse
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
props: ({ mutate }) => ({
|
||||
updateEmailAddress: input => {
|
||||
return mutate({
|
||||
variables: {
|
||||
input,
|
||||
},
|
||||
update: proxy => {
|
||||
const UpdateEmailAddressQuery = gql`
|
||||
query Talk_UpdateEmailAddress {
|
||||
me {
|
||||
id
|
||||
email
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const prev = proxy.readQuery({ query: UpdateEmailAddressQuery });
|
||||
|
||||
const data = update(prev, {
|
||||
me: {
|
||||
email: { $set: input.email },
|
||||
},
|
||||
});
|
||||
|
||||
proxy.writeQuery({
|
||||
query: UpdateEmailAddressQuery,
|
||||
data,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,13 @@
|
||||
import ChangePassword from './containers/ChangePassword';
|
||||
import Profile from './containers/Profile';
|
||||
import translations from './translations.yml';
|
||||
import graphql from './graphql';
|
||||
|
||||
export default {
|
||||
translations,
|
||||
slots: {
|
||||
profileHeader: [Profile],
|
||||
profileSettings: [ChangePassword],
|
||||
},
|
||||
...graphql,
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
en:
|
||||
talk-plugin-local-auth:
|
||||
change_password:
|
||||
change_password: "Change Password"
|
||||
passwords_dont_match: "Passwords don`t match"
|
||||
required_field: "This field is required"
|
||||
forgot_password: "Forgot your password?"
|
||||
save: "Save"
|
||||
cancel: "Cancel"
|
||||
edit: "Edit"
|
||||
changed_password_msg: "Changed Password - Your password has been successfully changed"
|
||||
change_username:
|
||||
change_username_note: "Usernames can be changed every 14 days"
|
||||
save: "Save"
|
||||
edit_profile: "Edit Profile"
|
||||
cancel: "Cancel"
|
||||
confirm_username_change: "Confirm Username Change"
|
||||
description: "You are attempting to change your username. Your new username will appear on all of your past and future comments."
|
||||
old_username: "Old Username"
|
||||
new_username: "New Username"
|
||||
bottom_note: "Note: You will not be able to change your username again for 14 days"
|
||||
confirm_changes: "Confirm Changes"
|
||||
username_does_not_match: "Username does not match"
|
||||
cant_be_equal: "Your new {0} must be different to your current one"
|
||||
change_username_attempt: "Username can't be updated. Usernames can be changed every 14 days"
|
||||
change_email:
|
||||
confirm_email_change: "Confirm Email Address Change"
|
||||
description: "You are attempting to change your email address. Your new email address will be used for your login and to receive account notifications."
|
||||
old_email: "Old Email Address"
|
||||
new_email: "New Email Address"
|
||||
enter_password: "Enter Password"
|
||||
incorrect_password: "Incorrect Password"
|
||||
confirm_change: "Confirm Change"
|
||||
cancel: "Cancel"
|
||||
change_email_msg: "Email Address Changed - Your email address has been successfully changed. This email address will now be used for signing in and email notifications."
|
||||
changed_username_success_msg: "Username Changed - Your username has been successfully changed. You will not be able to change your user name for 14 days."
|
||||
change_username_attempt: "Username can't be updated. Usernames can only be changed every 14 days."
|
||||
es:
|
||||
talk-plugin-local-auth:
|
||||
change_password:
|
||||
change_password: "Cambiar Contraseña"
|
||||
passwords_dont_match: "Las contraseñas no coinciden"
|
||||
required_field: "Este campo es requerido"
|
||||
forgot_password: "Olvidaste tu contraseña?"
|
||||
save: "Guardar"
|
||||
cancel: "Cancelar"
|
||||
edit: "Editar"
|
||||
changed_password_msg: "Contraseña Actualizada - Tu contraseña ha sido exitosamente actualizada"
|
||||
change_username:
|
||||
change_username_note: "El usuario puede ser cambiado cada 14 días"
|
||||
save: "Guardar"
|
||||
edit_profile: "Editar Perfil"
|
||||
cancel: "Cancelar"
|
||||
confirm_username_change: "Confirmar Cambio de Usuario"
|
||||
description: "Estás intentando cambiar tu usuario. Tu nuevo usuario aparecerá en todos tus pasados y futuros comentarios."
|
||||
old_username: "Usuario viejo"
|
||||
new_username: "Usuario nuevo"
|
||||
bottom_note: "Nota: No podrás cambiar tu usuario por 14 días"
|
||||
confirm_changes: "Confirmar Cambios"
|
||||
username_does_not_match: "El usuario no coincide"
|
||||
changed_username_success_msg: "Usuario Actualizado - Tu usuario ha sido exitosamente actualizado. No podrás cambiar el usuario por 14 días."
|
||||
change_username_attempt: "El usuario no puede ser actualizado. Los usuarios pueden ser cambiados cada 14 días."
|
||||
@@ -0,0 +1,11 @@
|
||||
const typeDefs = require('./server/typeDefs');
|
||||
const resolvers = require('./server/resolvers');
|
||||
const mutators = require('./server/mutators');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
translations: path.join(__dirname, 'server', 'translations.yml'),
|
||||
typeDefs,
|
||||
mutators,
|
||||
resolvers,
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
const { TalkError } = require('errors');
|
||||
|
||||
// ErrNoLocalProfile is returned when there is no existing local profile
|
||||
// attached to a user.
|
||||
class ErrNoLocalProfile extends TalkError {
|
||||
constructor() {
|
||||
super('No local profile associated with account', {
|
||||
translation_key: 'NO_LOCAL_PROFILE',
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ErrLocalProfile is returned when a profile is already attached to a user and
|
||||
// the user is trying to attach a new profile to it.
|
||||
class ErrLocalProfile extends TalkError {
|
||||
constructor() {
|
||||
super('Local profile already associated with account', {
|
||||
translation_key: 'LOCAL_PROFILE',
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ErrIncorrectPassword is returned when the password passed was incorrect.
|
||||
class ErrIncorrectPassword extends TalkError {
|
||||
constructor() {
|
||||
super('Password was incorrect', {
|
||||
translation_key: 'INCORRECT_PASSWORD',
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { ErrLocalProfile, ErrNoLocalProfile, ErrIncorrectPassword };
|
||||
@@ -0,0 +1,156 @@
|
||||
const { ErrNotAuthorized, ErrNotFound, ErrEmailTaken } = require('errors');
|
||||
const {
|
||||
ErrNoLocalProfile,
|
||||
ErrLocalProfile,
|
||||
ErrIncorrectPassword,
|
||||
} = require('./errors');
|
||||
const { get } = require('lodash');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
// hasLocalProfile checks a user's profiles to see if they already have a local
|
||||
// profile associated with their account.
|
||||
const hasLocalProfile = user =>
|
||||
get(user, 'profiles', []).some(({ provider }) => provider === 'local');
|
||||
|
||||
// updateUserEmailAddress will verify that the user has sent the correct
|
||||
// password followed by executing the email change and notifying the emails
|
||||
// about that change.
|
||||
async function updateUserEmailAddress(ctx, email, confirmPassword) {
|
||||
const {
|
||||
user,
|
||||
loaders: { Settings },
|
||||
connectors: { models: { User }, services: { Mailer, I18n, Users } },
|
||||
} = ctx;
|
||||
|
||||
// Ensure that the user has a local profile associated with their account.
|
||||
if (!hasLocalProfile(user)) {
|
||||
throw new ErrNoLocalProfile();
|
||||
}
|
||||
|
||||
// Ensure that the password provided matches what we have on file.
|
||||
if (!await user.verifyPassword(confirmPassword)) {
|
||||
throw new ErrIncorrectPassword();
|
||||
}
|
||||
|
||||
// Cleanup the email address.
|
||||
email = email.toLowerCase().trim();
|
||||
|
||||
// Update the Users email address.
|
||||
await User.update(
|
||||
{
|
||||
id: user.id,
|
||||
profiles: { $elemMatch: { provider: 'local' } },
|
||||
},
|
||||
{
|
||||
$set: { 'profiles.$.id': email },
|
||||
$unset: { 'profiles.$.metadata.confirmed_at': 1 },
|
||||
}
|
||||
);
|
||||
|
||||
// Get some context for the email to be sent.
|
||||
const { organizationContactEmail } = await Settings.load([
|
||||
'organizationContactEmail',
|
||||
]);
|
||||
|
||||
// Send off the email to the old email address that we have changed it.
|
||||
await Mailer.send({
|
||||
email: user.firstEmail,
|
||||
template: 'plain',
|
||||
locals: {
|
||||
body: I18n.t(
|
||||
'email.email_change_original.body',
|
||||
user.firstEmail,
|
||||
email,
|
||||
organizationContactEmail
|
||||
),
|
||||
},
|
||||
subject: I18n.t('email.email_change_original.subject'),
|
||||
});
|
||||
|
||||
// Send off the email to the new email address that we need to verify the new
|
||||
// address.
|
||||
await Users.sendEmailConfirmation(user, email);
|
||||
}
|
||||
|
||||
// attachUserLocalAuth will attach a new local profile to an existing user.
|
||||
async function attachUserLocalAuth(ctx, email, password) {
|
||||
const { user, connectors: { models: { User }, services: { Users } } } = ctx;
|
||||
|
||||
// Ensure that the current user doesn't already have a local account
|
||||
// associated with them.
|
||||
if (hasLocalProfile(user)) {
|
||||
throw new ErrLocalProfile();
|
||||
}
|
||||
|
||||
// Cleanup the email address.
|
||||
email = email.toLowerCase().trim();
|
||||
|
||||
// Validate the password.
|
||||
await Users.isValidPassword(password);
|
||||
|
||||
// Hash the new password.
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
|
||||
try {
|
||||
// Associate the account with the user.
|
||||
const updatedUser = await User.findOneAndUpdate(
|
||||
{
|
||||
id: user.id,
|
||||
'profiles.provider': { $ne: 'local' },
|
||||
},
|
||||
{
|
||||
$push: {
|
||||
profiles: {
|
||||
provider: 'local',
|
||||
id: email,
|
||||
},
|
||||
},
|
||||
$set: {
|
||||
password: hashedPassword,
|
||||
},
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
if (!updatedUser) {
|
||||
const foundUser = await User.findOne({ id: user.id });
|
||||
if (!foundUser) {
|
||||
throw new ErrNotFound();
|
||||
}
|
||||
|
||||
// Check to see if this was the result of a race.
|
||||
if (hasLocalProfile(foundUser)) {
|
||||
throw new ErrLocalProfile();
|
||||
}
|
||||
|
||||
throw new Error('local auth attachment failed due to unexpected reason');
|
||||
}
|
||||
|
||||
// Send off the email to the new email address that we need to verify the
|
||||
// new address.
|
||||
await Users.sendEmailConfirmation(updatedUser, email);
|
||||
} catch (err) {
|
||||
if (err.code === 11000) {
|
||||
throw new ErrEmailTaken();
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ctx => {
|
||||
const mutators = {
|
||||
User: {
|
||||
updateEmailAddress: () => Promise.reject(new ErrNotAuthorized()),
|
||||
attachLocalAuth: () => Promise.reject(new ErrNotAuthorized()),
|
||||
},
|
||||
};
|
||||
|
||||
if (ctx.user) {
|
||||
mutators.User.updateEmailAddress = ({ email, confirmPassword }) =>
|
||||
updateUserEmailAddress(ctx, email, confirmPassword);
|
||||
|
||||
mutators.User.attachLocalAuth = ({ email, password }) =>
|
||||
attachUserLocalAuth(ctx, email, password);
|
||||
}
|
||||
|
||||
return mutators;
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
RootMutation: {
|
||||
updateEmailAddress: async (root, { input }, { mutators: { User } }) => {
|
||||
await User.updateEmailAddress(input);
|
||||
},
|
||||
attachLocalAuth: async (root, { input }, { mutators: { User } }) => {
|
||||
await User.attachLocalAuth(input);
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
en:
|
||||
email:
|
||||
email_change_original:
|
||||
subject: Email change
|
||||
body: Your email address has been changed from {0} to {1}. If you did not initiate this change, please contact {2}. # TODO: update translation
|
||||
error:
|
||||
NO_LOCAL_PROFILE: No existing email address is associated with this account.
|
||||
LOCAL_PROFILE: An email address is already associated with this account.
|
||||
INCORRECT_PASSWORD: Provided password was incorrect.
|
||||
@@ -0,0 +1,47 @@
|
||||
# UpdateEmailAddressInput provides input for changing a users email address
|
||||
# associated with their account.
|
||||
input UpdateEmailAddressInput {
|
||||
|
||||
# email is the Users email address that they want to update to.
|
||||
email: String!
|
||||
|
||||
# confirmPassword is the Users current password.
|
||||
confirmPassword: String!
|
||||
}
|
||||
|
||||
# UpdateEmailAddressResponse is returned when you try to update a users email
|
||||
# address.
|
||||
type UpdateEmailAddressResponse implements Response {
|
||||
|
||||
# An array of errors relating to the mutation that occurred.
|
||||
errors: [UserError!]
|
||||
}
|
||||
|
||||
# AttachLocalAuthInput provides the input for attaching a new local
|
||||
# authentication profile.
|
||||
input AttachLocalAuthInput {
|
||||
|
||||
# email is the Users email address that they want to add.
|
||||
email: String!
|
||||
|
||||
# password is the Users password that they want to add.
|
||||
password: String!
|
||||
}
|
||||
|
||||
# AttachLocalAuthResponse returns any errors for when the user attempts to
|
||||
# attach a new local authentication profile.
|
||||
type AttachLocalAuthResponse implements Response {
|
||||
|
||||
# An array of errors relating to the mutation that occurred.
|
||||
errors: [UserError!]
|
||||
}
|
||||
|
||||
type RootMutation {
|
||||
|
||||
# updateEmailAddress changes the email address of the current logged in user.
|
||||
updateEmailAddress(input: UpdateEmailAddressInput!): UpdateEmailAddressResponse
|
||||
|
||||
# attachLocalAuth will attach a new local authentication profile to an
|
||||
# account.
|
||||
attachLocalAuth(input: AttachLocalAuthInput!): AttachLocalAuthResponse
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = fs.readFileSync(
|
||||
path.join(__dirname, 'typeDefs.graphql'),
|
||||
'utf8'
|
||||
);
|
||||
@@ -21,4 +21,13 @@ that contains a download link. Only one link can be generated every 7 days, and
|
||||
the link will be valid for 24 hours.
|
||||
|
||||
The downloaded zip file will contain all the users comments in a CSV format
|
||||
including those that have been rejected, withheld, or still in premod.
|
||||
including those that have been rejected, withheld, or still in pre-moderation.
|
||||
|
||||
## GDPR Compliance
|
||||
|
||||
In order to facilitate compliance with the
|
||||
[EU General Data Protection Regulation (GDPR)](https://www.eugdpr.org/), you
|
||||
should review our [GDPR Compliance](/talk/integrating/gdpr/) guidelines. This
|
||||
plugin can work with its client plugin disabled and then directly integrated
|
||||
with existing workflows for an organization of any size through use of the API
|
||||
that this plugin provides.
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
.button {
|
||||
color: #787D80;
|
||||
border-radius: 2px;
|
||||
border: 1px solid #787d80;
|
||||
background-color: transparent;
|
||||
height: 30px;
|
||||
font-size: 0.9em;
|
||||
line-height: normal;
|
||||
|
||||
&:hover {
|
||||
background-color: #eaeaea;
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background-color: #787D80;
|
||||
color: white;
|
||||
}
|
||||
|
||||
> i {
|
||||
font-size: 1.2em;
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import cn from 'classnames';
|
||||
import moment from 'moment';
|
||||
import styles from './DeleteMyAccount.css';
|
||||
import { Button } from 'plugin-api/beta/client/components/ui';
|
||||
import DeleteMyAccountDialog from './DeleteMyAccountDialog';
|
||||
import { getErrorMessages } from 'coral-framework/utils';
|
||||
@@ -59,28 +57,13 @@ class DeleteMyAccount extends React.Component {
|
||||
scheduledDeletionDate={scheduledDeletionDate}
|
||||
organizationContactEmail={organizationContactEmail}
|
||||
/>
|
||||
<h3
|
||||
className={cn(
|
||||
styles.title,
|
||||
'talk-plugin-auth--delete-my-account-description'
|
||||
)}
|
||||
>
|
||||
<h3 className="talk-plugin-auth--delete-my-account-description">
|
||||
{t('delete_request.delete_my_account')}
|
||||
</h3>
|
||||
<p
|
||||
className={cn(
|
||||
styles.description,
|
||||
'talk-plugin-auth--delete-my-account-description'
|
||||
)}
|
||||
>
|
||||
<p className="talk-plugin-auth--delete-my-account-description">
|
||||
{t('delete_request.delete_my_account_description')}
|
||||
</p>
|
||||
<p
|
||||
className={cn(
|
||||
styles.description,
|
||||
'talk-plugin-auth--delete-my-account-description'
|
||||
)}
|
||||
>
|
||||
<p className="talk-plugin-auth--delete-my-account-description">
|
||||
{scheduledDeletionDate &&
|
||||
t(
|
||||
'delete_request.already_submitted_request_description',
|
||||
@@ -88,18 +71,11 @@ class DeleteMyAccount extends React.Component {
|
||||
)}
|
||||
</p>
|
||||
{scheduledDeletionDate ? (
|
||||
<Button
|
||||
className={cn(styles.button, styles.secondary)}
|
||||
onClick={this.cancelAccountDeletion}
|
||||
>
|
||||
<Button onClick={this.cancelAccountDeletion}>
|
||||
{t('delete_request.cancel_account_deletion_request')}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
className={cn(styles.button)}
|
||||
icon="delete"
|
||||
onClick={this.showDialog}
|
||||
>
|
||||
<Button icon="delete" onClick={this.showDialog}>
|
||||
{t('delete_request.delete_my_account')}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -97,7 +97,7 @@ DeleteMyAccountDialog.propTypes = {
|
||||
showDialog: PropTypes.bool.isRequired,
|
||||
closeDialog: PropTypes.func.isRequired,
|
||||
requestAccountDeletion: PropTypes.func.isRequired,
|
||||
scheduledDeletionDate: PropTypes.any.isRequired,
|
||||
scheduledDeletionDate: PropTypes.any,
|
||||
organizationContactEmail: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { compose, gql } from 'react-apollo';
|
||||
import DownloadCommentHistory from '../components/DownloadCommentHistory';
|
||||
import { connect, withFragments } from 'plugin-api/beta/client/hocs';
|
||||
import { withRequestDownloadLink } from '../hocs';
|
||||
import { connect, withFragments } from 'plugin-api/beta/client/hocs';
|
||||
import { notify } from 'coral-framework/actions/notification';
|
||||
|
||||
class DownloadCommentHistoryContainer extends Component {
|
||||
|
||||
@@ -10,7 +10,7 @@ export default {
|
||||
),
|
||||
},
|
||||
mutations: {
|
||||
RequestDownloadLink: () => ({
|
||||
DownloadCommentHistory: () => ({
|
||||
updateQueries: {
|
||||
CoralEmbedStream_Profile: previousData =>
|
||||
update(previousData, {
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import { withMutation } from 'plugin-api/beta/client/hocs';
|
||||
import { gql } from 'react-apollo';
|
||||
import update from 'immutability-helper';
|
||||
import moment from 'moment';
|
||||
import update from 'immutability-helper';
|
||||
|
||||
export const withRequestDownloadLink = withMutation(
|
||||
gql`
|
||||
mutation RequestDownloadLink {
|
||||
mutation DownloadCommentHistory {
|
||||
requestDownloadLink {
|
||||
...RequestDownloadLinkResponse
|
||||
errors {
|
||||
translation_key
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
props: ({ mutate }) => ({
|
||||
requestDownloadLink: () => mutate({}),
|
||||
requestDownloadLink: () => mutate({ variables: {} }),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
+4
-1
@@ -32,6 +32,7 @@ const i18n = require('./i18n');
|
||||
const Wordlist = require('./wordlist');
|
||||
const DomainList = require('./domain_list');
|
||||
const Limit = require('./limit');
|
||||
const { get } = require('lodash');
|
||||
|
||||
const EMAIL_CONFIRM_JWT_SUBJECT = 'email_confirm';
|
||||
const PASSWORD_RESET_JWT_SUBJECT = 'password_reset';
|
||||
@@ -965,7 +966,9 @@ class Users {
|
||||
throw new ErrNotFound();
|
||||
}
|
||||
|
||||
if (profile.metadata && profile.metadata.confirmed_at !== null) {
|
||||
// Check to see if the profile has already been confirmed.
|
||||
const confirmedAt = get(profile, 'metadata.confirmed_at', null);
|
||||
if (confirmedAt && confirmedAt < Date.now()) {
|
||||
throw new ErrEmailAlreadyVerified();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user