Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add password reset link to login page #3329

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/password-reset-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Add password reset link to login page

Added a configurable passwort reset link to the login page.
It can be set via `IDP_PASSWORD_RESET_URI`. If the option is not set
the link will not be shown.

https://github.com/owncloud/ocis/pull/3329
3 changes: 2 additions & 1 deletion idp/pkg/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package config

// Service defines the available service configuration.
type Service struct {
Name string `ocisConfig:"-" yaml:"-"`
Name string `ocisConfig:"-" yaml:"-"`
PasswordResetURI string `ocisConfig:"password_reset_uri" env:"IDP_PASSWORD_RESET_URI" desc:"The URI where a user can reset their password."`
}
2 changes: 2 additions & 0 deletions idp/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func (idp IDP) Index() http.HandlerFunc {
nonce := rndm.GenerateRandomString(32)
indexHTML = bytes.Replace(indexHTML, []byte("__CSP_NONCE__"), []byte(nonce), 1)

indexHTML = bytes.Replace(indexHTML, []byte("__PASSWORD_RESET_LINK__"), []byte(idp.config.Service.PasswordResetURI), 1)

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
if _, err := w.Write(indexHTML); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion idp/ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<main id="root" class="oc-login-bg" data-path-prefix="__PATH_PREFIX__"></main>
<main id="root" class="oc-login-bg" data-path-prefix="__PATH_PREFIX__" passwort-reset-link="__PASSWORD_RESET_LINK__"></main>
</body>
</html>
12 changes: 9 additions & 3 deletions idp/ui/src/containers/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Button from '@material-ui/core/Button';
import CircularProgress from '@material-ui/core/CircularProgress';
import green from '@material-ui/core/colors/green';
import Typography from '@material-ui/core/Typography';
import Link from '@material-ui/core/Link';

import TextInput from '../../components/TextInput'

Expand Down Expand Up @@ -55,7 +56,8 @@ class Login extends React.PureComponent {
}

render() {
const { loading, errors, classes, username } = this.props;
const { loading, errors, classes, username, passwordResetLink } = this.props;
const loginFailed = errors.http;
const hasError = errors.http || errors.username || errors.password;
const errorMessage = errors.http
? <ErrorMessage error={errors.http}></ErrorMessage>
Expand Down Expand Up @@ -109,6 +111,8 @@ class Login extends React.PureComponent {
{hasError && <Typography id="oc-login-error-message" variant="subtitle2" component="span" color="error"
className={classes.message}>{errorMessage}</Typography>}
<div className={classes.wrapper}>
{loginFailed && passwordResetLink && <Link id="oc-login-password-reset" href={passwordResetLink} variant="subtitle2">{"Reset password?"}</Link>}
<br />
<Button
type="submit"
color="primary"
Expand Down Expand Up @@ -150,6 +154,7 @@ Login.propTypes = {
loading: PropTypes.string.isRequired,
username: PropTypes.string.isRequired,
password: PropTypes.string.isRequired,
passwordResetLink: PropTypes.string.isRequired,
errors: PropTypes.object.isRequired,
hello: PropTypes.object,
query: PropTypes.object.isRequired,
Expand All @@ -160,15 +165,16 @@ Login.propTypes = {

const mapStateToProps = (state) => {
const { loading, username, password, errors} = state.login;
const { hello, query } = state.common;
const { hello, query, passwordResetLink } = state.common;

return {
loading,
username,
password,
errors,
hello,
query
query,
passwordResetLink
};
};

Expand Down
13 changes: 12 additions & 1 deletion idp/ui/src/reducers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ const defaultPathPrefix = (() => {
return pathPrefix;
})();

const defaultPasswordResetLink = (() => {
const root = document.getElementById('root');
let link = root ? root.getAttribute('passwort-reset-link') : null;
if (!link || link === '__PASSWORD_RESET_LINK__') {
// Not replaced, probably we are running in debug mode or whatever. Use sane default.
link = '';
}
return link;
})();

const defaultState = {
hello: null,
error: null,
flow: flow,
query: query,
updateAvailable: false,
pathPrefix: defaultPathPrefix
pathPrefix: defaultPathPrefix,
passwordResetLink: defaultPasswordResetLink
};

function commonReducer(state = defaultState, action) {
Expand Down