|
1 |
| -import { Form, Col, Input, Icon, Row, Checkbox, Button, Card, Modal, message } from 'antd'; |
| 1 | +import { Form, Col, Input, Icon, Row, Checkbox, Button, Card, Modal } from 'antd'; |
2 | 2 | import * as React from 'react';
|
3 | 3 | import { inject, observer } from 'mobx-react';
|
4 |
| -import accountService from 'src/services/account/accountService'; |
5 | 4 | import Stores from 'src/stores/storeIdentifier';
|
6 | 5 | import AuthenticationStore from 'src/stores/authenticationStore';
|
7 | 6 | import { FormComponentProps } from 'antd/lib/form';
|
8 | 7 | import { Redirect } from 'react-router-dom';
|
| 8 | +import { L } from 'src/lib/abpUtility'; |
| 9 | +import SessionStore from 'src/stores/sessionStore'; |
| 10 | +import AccountStore from 'src/stores/accountStore'; |
| 11 | +import TenantAvailabilityState from 'src/services/account/dto/tenantAvailabilityState'; |
9 | 12 |
|
10 | 13 | const FormItem = Form.Item;
|
11 | 14 |
|
12 | 15 | export interface ILoginProps extends FormComponentProps {
|
13 | 16 | authenticationStore?: AuthenticationStore;
|
| 17 | + sessionStore?: SessionStore; |
| 18 | + accountStore?: AccountStore; |
14 | 19 | history: any;
|
15 | 20 | location: any;
|
16 | 21 | }
|
17 | 22 |
|
18 |
| -@inject(Stores.AuthenticationStore) |
| 23 | +@inject(Stores.AuthenticationStore, Stores.SessionStore, Stores.AccountStore) |
19 | 24 | @observer
|
20 |
| -class Login extends React.Component<ILoginProps, any> { |
21 |
| - constructor(props: ILoginProps) { |
22 |
| - super(props); |
23 |
| - this.state = { |
24 |
| - modalVisible: false, |
25 |
| - rememberMe: true, |
26 |
| - tenancyName: '', |
27 |
| - }; |
28 |
| - } |
29 |
| - |
30 |
| - rememberMeCheck = () => { |
31 |
| - this.setState({ rememberMe: !this.state.rememberMe }); |
32 |
| - }; |
| 25 | +class Login extends React.Component<ILoginProps> { |
| 26 | + changeTenant = async () => { |
| 27 | + debugger; |
| 28 | + let tenancyName = this.props.form.getFieldValue('tenancyName'); |
| 29 | + const { loginModel } = this.props.authenticationStore!; |
33 | 30 |
|
34 |
| - isTenantAvaible = async () => { |
35 |
| - var tenancyName = this.props.form.getFieldValue('tenancyName'); |
36 |
| - var result = await accountService.isTenantAvailable({ tenancyName: tenancyName }); |
37 |
| - |
38 |
| - console.log(result); |
39 |
| - if (result.tenantId != null) { |
40 |
| - this.setState({ tenancyName: tenancyName }); |
41 |
| - this.onModal(); |
| 31 | + if (!tenancyName) { |
| 32 | + abp.multiTenancy.setTenantIdCookie(undefined); |
| 33 | + window.location.href = '/'; |
| 34 | + return; |
42 | 35 | } else {
|
43 |
| - message.error('Tenant Bulunamadı'); |
| 36 | + await this.props.accountStore!.isTenantAvailable(tenancyName); |
| 37 | + const { tenant } = this.props.accountStore!; |
| 38 | + switch (tenant.state) { |
| 39 | + case TenantAvailabilityState.Available: |
| 40 | + abp.multiTenancy.setTenantIdCookie(tenant.tenantId); |
| 41 | + loginModel.tenancyName = tenancyName; |
| 42 | + loginModel.toggleShowModal(); |
| 43 | + window.location.href = '/'; |
| 44 | + return; |
| 45 | + case TenantAvailabilityState.InActive: |
| 46 | + Modal.error({ title: L('Error'), content: L('TenantIsNotActive') }); |
| 47 | + break; |
| 48 | + case TenantAvailabilityState.NotFound: |
| 49 | + Modal.error({ title: L('Error'), content: L('ThereIsNoTenantDefinedWithName{0}', tenancyName) }); |
| 50 | + break; |
| 51 | + } |
44 | 52 | }
|
45 | 53 | };
|
46 | 54 |
|
47 | 55 | handleSubmit = async (e: any) => {
|
48 | 56 | e.preventDefault();
|
| 57 | + const { loginModel } = this.props.authenticationStore!; |
49 | 58 | await this.props.form.validateFields(async (err: any, values: any) => {
|
50 | 59 | if (!err) {
|
51 | 60 | await this.props.authenticationStore!.login(values);
|
52 |
| - sessionStorage.setItem('rememberMe', this.state.rememberMe ? '1' : '0'); |
| 61 | + sessionStorage.setItem('rememberMe', loginModel.rememberMe ? '1' : '0'); |
53 | 62 | const { state } = this.props.location;
|
54 | 63 | window.location = state ? state.from.pathname : '/';
|
55 | 64 | }
|
56 | 65 | });
|
57 | 66 | };
|
58 |
| - onModal = () => { |
59 |
| - this.setState({ modalVisible: !this.state.modalVisible }); |
60 |
| - }; |
61 | 67 |
|
62 | 68 | public render() {
|
63 | 69 | let { from } = this.props.location.state || { from: { pathname: '/' } };
|
64 | 70 | if (this.props.authenticationStore!.isAuthenticated) return <Redirect to={from} />;
|
65 | 71 |
|
66 |
| - const { getFieldDecorator } = this.props.form; |
| 72 | + const { loginModel } = this.props.authenticationStore!; |
| 73 | + const { getFieldDecorator, getFieldValue } = this.props.form; |
| 74 | + debugger; |
67 | 75 | return (
|
68 | 76 | <Form className="login-form" onSubmit={this.handleSubmit}>
|
69 | 77 | <Row style={{ height: '100vh', backgroundColor: '#00bcd4' }}>
|
70 | 78 | <Row style={{ marginTop: 100 }}>
|
71 |
| - <Col |
72 |
| - xs={{ span: 8, offset: 8 }} |
73 |
| - sm={{ span: 8, offset: 8 }} |
74 |
| - md={{ span: 8, offset: 8 }} |
75 |
| - lg={{ span: 8, offset: 8 }} |
76 |
| - xl={{ span: 8, offset: 8 }} |
77 |
| - xxl={{ span: 8, offset: 8 }} |
78 |
| - > |
| 79 | + <Col span={8} offset={8}> |
79 | 80 | <Card>
|
80 | 81 | <Row>
|
81 |
| - <Col |
82 |
| - xs={{ span: 24, offset: 0 }} |
83 |
| - sm={{ span: 24, offset: 0 }} |
84 |
| - md={{ span: 24, offset: 0 }} |
85 |
| - lg={{ span: 24, offset: 0 }} |
86 |
| - xl={{ span: 24, offset: 0 }} |
87 |
| - xxl={{ span: 24, offset: 0 }} |
88 |
| - style={{ textAlign: 'center' }} |
89 |
| - > |
90 |
| - Current Tenant : {this.state.tenancyName} <a onClick={this.onModal}>(Change)</a> |
91 |
| - </Col> |
| 82 | + {!!this.props.sessionStore!.currentLogin.tenant ? ( |
| 83 | + <Col span={24} offset={0} style={{ textAlign: 'center' }}> |
| 84 | + <a onClick={loginModel.toggleShowModal}> |
| 85 | + {L('CurrentTenant')} : {this.props.sessionStore!.currentLogin.tenant.tenancyName} |
| 86 | + </a> |
| 87 | + </Col> |
| 88 | + ) : ( |
| 89 | + <Col span={24} offset={0} style={{ textAlign: 'center' }}> |
| 90 | + <a onClick={loginModel.toggleShowModal}> {L('NotSelected')}</a> |
| 91 | + </Col> |
| 92 | + )} |
92 | 93 | </Row>
|
93 | 94 | </Card>
|
94 | 95 | </Col>
|
95 | 96 | </Row>
|
96 | 97 |
|
97 | 98 | <Row>
|
98 |
| - <Modal visible={this.state.modalVisible} onCancel={this.onModal} onOk={this.isTenantAvaible}> |
| 99 | + <Modal |
| 100 | + visible={loginModel.showModal} |
| 101 | + onCancel={loginModel.toggleShowModal} |
| 102 | + onOk={this.changeTenant} |
| 103 | + title={L('ChangeTenant')} |
| 104 | + okText={L('OK')} |
| 105 | + cancelText={L('Cancel')} |
| 106 | + > |
99 | 107 | <Row>
|
100 |
| - <Col |
101 |
| - xs={{ span: 8, offset: 8 }} |
102 |
| - sm={{ span: 8, offset: 8 }} |
103 |
| - md={{ span: 8, offset: 8 }} |
104 |
| - lg={{ span: 8, offset: 8 }} |
105 |
| - xl={{ span: 8, offset: 8 }} |
106 |
| - xxl={{ span: 8, offset: 8 }} |
107 |
| - style={{ textAlign: 'center' }} |
108 |
| - > |
109 |
| - <h3>{'Tenant Name'}</h3> |
| 108 | + <Col span={8} offset={8}> |
| 109 | + <h3>{L('TenancyName')}</h3> |
110 | 110 | </Col>
|
111 | 111 | <Col>
|
112 | 112 | <FormItem>
|
113 | 113 | {getFieldDecorator('tenancyName', {})(
|
114 |
| - <Input placeholder={'Tenant Name'} prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} size="large" /> |
| 114 | + <Input placeholder={L('TenancyName')} prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} size="large" /> |
115 | 115 | )}
|
116 | 116 | </FormItem>
|
| 117 | + {!getFieldValue('tenancyName') ? <div>{L('LeaveEmptyToSwitchToHost')}</div> : ''} |
117 | 118 | </Col>
|
118 | 119 | </Row>
|
119 | 120 | </Modal>
|
120 | 121 | </Row>
|
121 | 122 | <Row style={{ marginTop: 10 }}>
|
122 |
| - <Col |
123 |
| - xs={{ span: 8, offset: 8 }} |
124 |
| - sm={{ span: 8, offset: 8 }} |
125 |
| - md={{ span: 8, offset: 8 }} |
126 |
| - lg={{ span: 8, offset: 8 }} |
127 |
| - xl={{ span: 8, offset: 8 }} |
128 |
| - xxl={{ span: 8, offset: 8 }} |
129 |
| - > |
| 123 | + <Col span={8} offset={8}> |
130 | 124 | <Card>
|
131 | 125 | <div style={{ textAlign: 'center' }}>
|
132 |
| - <h3>{'Login'}</h3> |
| 126 | + <h3>{L('WellcomeMessage')}</h3> |
133 | 127 | </div>
|
134 | 128 | <FormItem>
|
135 | 129 | {getFieldDecorator('userNameOrEmailAddress', {
|
136 | 130 | rules: [
|
137 | 131 | {
|
138 | 132 | required: true,
|
139 |
| - message: 'User Name is required.', |
| 133 | + message: L('ThisFieldIsRequired'), |
140 | 134 | },
|
141 | 135 | ],
|
| 136 | + })(<Input placeholder={L('UserNameOrEmail')} prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} size="large" />)} |
| 137 | + </FormItem> |
| 138 | + |
| 139 | + <FormItem> |
| 140 | + {getFieldDecorator('password', { |
| 141 | + rules: [{ required: true, message: L('ThisFieldIsRequired') }], |
142 | 142 | })(
|
143 | 143 | <Input
|
144 |
| - placeholder={'Kullanıcı adı veya mail adresi'} |
145 |
| - prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} |
| 144 | + placeholder={L('Password')} |
| 145 | + prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} |
| 146 | + type="password" |
146 | 147 | size="large"
|
147 | 148 | />
|
148 | 149 | )}
|
149 | 150 | </FormItem>
|
150 |
| - |
151 |
| - <FormItem> |
152 |
| - {getFieldDecorator('password', { |
153 |
| - rules: [{ required: true, message: 'Password is is required.' }], |
154 |
| - })(<Input placeholder={'Şifre'} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" size="large" />)} |
155 |
| - </FormItem> |
156 | 151 | <Row style={{ margin: '0px 0px 10px 15px ' }}>
|
157 |
| - <Col |
158 |
| - xs={{ span: 12, offset: 0 }} |
159 |
| - sm={{ span: 12, offset: 0 }} |
160 |
| - md={{ span: 12, offset: 0 }} |
161 |
| - lg={{ span: 12, offset: 0 }} |
162 |
| - xl={{ span: 12, offset: 0 }} |
163 |
| - xxl={{ span: 12, offset: 0 }} |
164 |
| - > |
165 |
| - <Checkbox checked={this.state.rememberMe} onChange={this.rememberMeCheck} /> |
166 |
| - {'RememberMe'} |
| 152 | + <Col span={12} offset={0}> |
| 153 | + <Checkbox checked={loginModel.rememberMe} onChange={loginModel.toggleRememberMe} /> |
| 154 | + {L('RememberMe')} |
| 155 | + <br /> |
| 156 | + <a>{L('ForgotPassword')}</a> |
167 | 157 | </Col>
|
168 |
| - <Col |
169 |
| - xs={{ span: 8, offset: 4 }} |
170 |
| - sm={{ span: 8, offset: 4 }} |
171 |
| - md={{ span: 8, offset: 4 }} |
172 |
| - lg={{ span: 8, offset: 4 }} |
173 |
| - xl={{ span: 8, offset: 4 }} |
174 |
| - xxl={{ span: 8, offset: 4 }} |
175 |
| - > |
| 158 | + |
| 159 | + <Col span={8} offset={4}> |
176 | 160 | <Button style={{ backgroundColor: '#f5222d', color: 'white' }} htmlType={'submit'} type="danger">
|
177 |
| - Login |
| 161 | + {L('LogIn')} |
178 | 162 | </Button>
|
179 | 163 | </Col>
|
180 | 164 | </Row>
|
|
0 commit comments