Skip to content

Commit 43587b5

Browse files
committed
Add authentication with standard Caché Login Page method
1 parent 5ae43f9 commit 43587b5

File tree

9 files changed

+177
-11
lines changed

9 files changed

+177
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"babel-preset-stage-1": "^6.24.1",
3131
"babel-register": "^6.26.0",
3232
"colors": "^1.1.2",
33+
"copy-webpack-plugin": "^4.2.0",
3334
"css-loader": "^0.28.7",
3435
"eslint": "4.9.0",
3536
"eslint-plugin-import": "2.8.0",

src/api/catalogApi.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import axios from 'axios';
1+
import rest from './rest';
22
import { server } from "./config";
33

44
class CatalogApi {
55

66
// get list of all available catalogs
77
static getAllCatalogs() {
8-
return axios({
8+
return rest({
99
method: 'get',
1010
url: `${server}/form/info`,
1111
params: {
@@ -16,15 +16,15 @@ class CatalogApi {
1616

1717
// get full metadata of specified catalog
1818
static getCatalogInfo(catalogClass) {
19-
return axios({
19+
return rest({
2020
method: 'get',
2121
url: `${server}/form/info/${catalogClass}`
2222
});
2323
}
2424

2525
// get <size> objects of specified catalog
2626
static getCatalogExtent(catalogClass) {
27-
return axios({
27+
return rest({
2828
method: 'get',
2929
url: `${server}/form/objects/${catalogClass}/info`,
3030
params: {
@@ -35,7 +35,7 @@ class CatalogApi {
3535

3636
// get <size> objects of specified catalog with _class property
3737
static getCatalogExtendWithClass(catalogClass) {
38-
return axios({
38+
return rest({
3939
method: 'get',
4040
url: `${server}/form/objects/${catalogClass}/infoclass`,
4141
params: {
@@ -47,30 +47,30 @@ class CatalogApi {
4747

4848
// get object by catalog and id
4949
static getFormObjectById(catalogClass, id) {
50-
return axios({
50+
return rest({
5151
method: 'get',
5252
url: `${server}/form/object/${catalogClass}/${id}`
5353
});
5454
}
5555

5656
static updateObject(catalogClass, id, catalog) {
57-
return axios({
57+
return rest({
5858
method: 'put',
5959
url: `${server}/form/object/${catalogClass}/${id}`,
6060
data: catalog
6161
});
6262
}
6363

6464
static saveObject(catalogClass, catalog) {
65-
return axios({
65+
return rest({
6666
method: 'post',
6767
url: `${server}/form/object/${catalogClass}`,
6868
data: catalog
6969
});
7070
}
7171

7272
static deleteObject(catalogClass, id) {
73-
return axios({
73+
return rest({
7474
method: 'delete',
7575
url: `${server}/form/object/${catalogClass}/${id}`
7676
});

src/api/rest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import axios from 'axios';
2+
3+
export default function rest(config) {
4+
clearTimeout(window.cspSessionTimer);
5+
window.cspSessionTimerReset();
6+
7+
return axios(config);
8+
}

src/components/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class App extends Component {
2020
<Layout className="layout">
2121
<Header style={{background: "#fff"}}>
2222
<Container>
23-
<span>User: <b>Tester</b></span>
23+
<span>User: <b>{window.userName}</b></span>
2424
<Menu
2525
mode="horizontal"
2626
selectable={false}
2727
style={{ lineHeight: '63px', display: 'inline'}}
2828
>
29-
<Menu.Item style={{float: "right"}}>Log out <Icon type="logout"/></Menu.Item>
29+
<Menu.Item style={{float: "right"}}><a href="?CacheLogout=1">Log out <Icon type="logout"/></a></Menu.Item>
3030
</Menu>
3131
</Container>
3232
</Header>

src/index.csp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<link rel="stylesheet" href="style.css">
88
<title>Сахалинский областной медицинский информационно-аналитический центр</title>
9+
10+
<script>
11+
var cspSessionTimeout = (+'#(%session.AppTimeout)#' + 15) * 1000;
12+
var cspSessionTimer;
13+
var userName = ('#(%session.Username)#');
14+
15+
function cspSessionTimerReset() {
16+
cspSessionTimer = setTimeout(function() {location.reload()}, cspSessionTimeout);
17+
}
18+
19+
cspSessionTimerReset();
20+
</script>
921
</head>
1022
<body>
1123
<div id="app"></div>

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HashRouter } from 'react-router-dom';
44
import App from './components/App';
55
import './index.csp';
66
import './styles/styles.css';
7+
import './styles/login.css';
78

89
ReactDOM.render(
910
<HashRouter>

src/styles/login.css

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.login__page-text-center {
2+
text-align: center;
3+
}
4+
5+
.login__page-middle {
6+
display: flex;
7+
margin: -1px;
8+
justify-content: center;
9+
}
10+
11+
.login__page-login {
12+
min-width: 420px;
13+
max-width: 450px;
14+
-webkit-box-orient: vertical;
15+
-webkit-box-direction: normal;
16+
-ms-flex-direction: column;
17+
flex-direction: column;
18+
vertical-align: middle;
19+
-ms-flex-item-align: center!important;
20+
-ms-grid-row-align: center!important;
21+
align-self: center!important;
22+
}
23+
24+
.login__page-login h2 {
25+
font-size: 1.71428571rem;
26+
}
27+
28+
.login__page-segment {
29+
position: relative;
30+
background: #fff;
31+
box-shadow: 0 1px 2px 0 rgba(34,36,38,.15);
32+
margin: 1rem 0;
33+
padding: 1em 1em;
34+
border-radius: .28571429rem;
35+
border: 1px solid rgba(34,36,38,.15);
36+
}
37+
38+
.login__page-field {
39+
width: 100%;
40+
clear: both;
41+
margin: 0 0 1em;
42+
}
43+
44+
.login__page-input {
45+
width: 100%;
46+
font-family: Arial,Helvetica,sans-serif;
47+
margin: 0;
48+
outline: 0;
49+
-webkit-appearance: none;
50+
tap-highlight-color: rgba(255,255,255,0);
51+
line-height: 1.21428571em;
52+
padding: .67857143em 1em;
53+
font-size: 1em;
54+
background: #fff;
55+
border: 1px solid rgba(34,36,38,.15);
56+
color: rgba(0,0,0,.87);
57+
border-radius: .28571429rem;
58+
box-shadow: 0 0 0 0 transparent inset;
59+
}
60+
61+
.login__page-button {
62+
background-color: #2185D0;
63+
background-image: none;
64+
color: #fff;
65+
text-shadow: none;
66+
width: 100%;
67+
display: block;
68+
cursor: pointer;
69+
min-height: 1em;
70+
outline: 0;
71+
border: none;
72+
vertical-align: baseline;
73+
font-family: Arial,Helvetica,sans-serif;
74+
margin: 0 .25em 0 0;
75+
padding: .78571429em 1.5em .78571429em;
76+
text-transform: none;
77+
font-weight: 700;
78+
line-height: 1em;
79+
font-style: normal;
80+
text-align: center;
81+
text-decoration: none;
82+
border-radius: .28571429rem;
83+
}
84+
85+
.login__page-message {
86+
box-shadow: 0 0 0 1px #e0b4b4 inset, 0 0 0 0 transparent;
87+
background-color: #fff6f6;
88+
color: #9f3a38;
89+
position: relative;
90+
min-height: 1em;
91+
margin: 1em 0;
92+
padding: 1em 1.5em;
93+
line-height: 1.4285em;
94+
border-radius: .28571429rem;
95+
font-weight: bold;
96+
}

static/login.csp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="style.css">
8+
<title>Сахалинский областной медицинский информационно-аналитический центр</title>
9+
</head>
10+
<body style="background-color: #E9EDF1">
11+
<div id="login">
12+
<div class="login__page-middle login__page-text-center" style="height: calc(100vh - 140px)">
13+
<div class="login__page-login">
14+
15+
<form name="Login" method="post">
16+
<div class="login__page-segment">
17+
18+
<div class="login__page-field">
19+
<div style="width: 100%;">
20+
<i class="user icon"></i>
21+
<input class="login__page-input" type="text" placeholder="Login" name="CacheUserName">
22+
</div>
23+
</div>
24+
25+
<div class="login__page-field">
26+
<div style="width: 100%;">
27+
<i class="lock icon"></i>
28+
<input class="login__page-input" type="password" placeholder="Password" name="CachePassword">
29+
</div>
30+
</div>
31+
32+
<button type="submit" class="login__page-button">Log in
33+
</button>
34+
35+
#($select( ($Get(%request.Data("Error:ErrorCode",1))'="")&&($$$GETERRORCODE($Get(%request.Data("Error:ErrorCode",1)))'=$$$ERRORCODE($$$RequireAuthentication)): "<div class=""login__page-message"">The user name or password is incorrect</div>", 1:"") )#
36+
</div>
37+
</form>
38+
39+
</div>
40+
</div>
41+
</div>
42+
</body>
43+
</html>

webpack.config.babel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import webpack from 'webpack';
22
import path from 'path';
33
import ExtractTextPlugin from 'extract-text-webpack-plugin';
4+
import CopyWebpackPlugin from 'copy-webpack-plugin';
5+
46

57
export default {
68
stats: 'errors-only',
@@ -15,6 +17,9 @@ export default {
1517
plugins: [
1618
new webpack.optimize.OccurrenceOrderPlugin(),
1719
new ExtractTextPlugin('style.css'),
20+
new CopyWebpackPlugin([
21+
{ from: 'static', to: './' }
22+
])
1823
//new webpack.optimize.UglifyJsPlugin()
1924
],
2025
module: {

0 commit comments

Comments
 (0)