summaryrefslogtreecommitdiffstats
path: root/web/react/components/authorize.jsx
blob: 90cbe3289a39c70f3f8eef28f8f56ca622c6ef64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import * as Client from '../utils/client.jsx';

import {FormattedMessage} from 'mm-intl';

export default class Authorize extends React.Component {
    constructor(props) {
        super(props);

        this.handleAllow = this.handleAllow.bind(this);
        this.handleDeny = this.handleDeny.bind(this);

        this.state = {};
    }
    handleAllow() {
        const responseType = this.props.responseType;
        const clientId = this.props.clientId;
        const redirectUri = this.props.redirectUri;
        const state = this.props.state;
        const scope = this.props.scope;

        Client.allowOAuth2(responseType, clientId, redirectUri, state, scope,
            (data) => {
                if (data.redirect) {
                    window.location.replace(data.redirect);
                }
            },
            () => {}
        );
    }
    handleDeny() {
        window.location.replace(this.props.redirectUri + '?error=access_denied');
    }
    render() {
        return (
            <div className='authorize-box'>
                <div className='authorize-inner'>
                    <h3>
                        <FormattedMessage
                            id='authorize.title'
                            defaultMessage='An application would like to connect to your {teamName} account'
                            values={{
                                teamName: this.props.teamName
                            }}
                        />
                    </h3>
                    <label>
                        <FormattedMessage
                            id='authorize.app'
                            defaultMessage='The app {appName} would like the ability to access and modify your basic information.'
                            values={{
                                appName: this.props.appName
                            }}
                        />
                    </label>
                    <br/>
                    <br/>
                    <label>
                        <FormattedMessage
                            id='authorize.access'
                            defaultMessage='Allow {appName} access?'
                            values={{
                                appName: this.props.appName
                            }}
                        />
                    </label>
                    <br/>
                    <button
                        type='submit'
                        className='btn authorize-btn'
                        onClick={this.handleDeny}
                    >
                        <FormattedMessage
                            id='authorize.deny'
                            defaultMessage='Deny'
                        />
                    </button>
                    <button
                        type='submit'
                        className='btn btn-primary authorize-btn'
                        onClick={this.handleAllow}
                    >
                        <FormattedMessage
                            id='authorize.allow'
                            defaultMessage='Allow'
                        />
                    </button>
                </div>
            </div>
        );
    }
}

Authorize.propTypes = {
    appName: React.PropTypes.string,
    teamName: React.PropTypes.string,
    responseType: React.PropTypes.string,
    clientId: React.PropTypes.string,
    redirectUri: React.PropTypes.string,
    state: React.PropTypes.string,
    scope: React.PropTypes.string
};