Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
netdisc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rocosen
netdisc
Commits
6203cc03
Commit
6203cc03
authored
Dec 02, 2022
by
rocosen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
d6751b33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
37 deletions
+48
-37
Axios.js
src/commons/axios/Axios.js
+36
-24
login.jsx
src/renderer/console/login.jsx
+12
-13
No files found.
src/commons/axios/Axios.js
View file @
6203cc03
import
Controller
from
'./controller'
;
import
Controller
from
'./controller'
;
import
store
from
'../reduxs/store'
;
import
store
from
'../reduxs/store'
;
import
{
setRequest
}
from
'../reduxs/actions'
;
import
{
setRequest
}
from
'../reduxs/actions'
;
import
qs
from
"qs"
;
import
qs
from
'qs'
;
import
API
from
'../../commons/utils/api_manager'
;
import
API
from
'../../commons/utils/api_manager'
;
import
{
Constants
}
from
'../../commons/utils/constants'
;
import
{
Constants
}
from
'../../commons/utils/constants'
;
import
axios
from
'axios'
;
import
axios
from
'axios'
;
...
@@ -34,22 +34,22 @@ class Axios {
...
@@ -34,22 +34,22 @@ class Axios {
res
,
res
,
};
};
}
catch
(
error
)
{
}
catch
(
error
)
{
if
(
error
.
response
.
data
.
errorCode
===
'100003'
)
{
if
(
error
.
response
.
data
.
errorCode
===
'100003'
)
{
let
reLoad
=
await
Axios
.
request_reLoad
();
let
reLoad
=
await
Axios
.
request_reLoad
();
if
(
reLoad
[
'access_token'
])
{
if
(
reLoad
[
'access_token'
])
{
localStorage
.
setItem
(
Constants
.
TOKEN_KEY
,
JSON
.
stringify
(
data
))
localStorage
.
setItem
(
Constants
.
TOKEN_KEY
,
JSON
.
stringify
(
data
)
);
window
.
location
.
reload
();
window
.
location
.
reload
();
}
else
{
}
else
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
localStorage
.
removeItem
(
Constants
.
TEMPORARY_TOKEN_KEY
);
localStorage
.
removeItem
(
Constants
.
TEMPORARY_TOKEN_KEY
);
localStorage
.
removeItem
(
Constants
.
TOKEN_KEY
);
localStorage
.
removeItem
(
Constants
.
TOKEN_KEY
);
},
3000
);
},
3000
);
}
}
return
;
}
}
return
;
actions
&&
store
.
dispatch
(
setRequest
(
error
));
actions
&&
store
.
dispatch
(
setRequest
(
error
));
if
(
!
actions
)
{
if
(
!
actions
)
{
return
{
return
{
...
@@ -62,17 +62,29 @@ class Axios {
...
@@ -62,17 +62,29 @@ class Axios {
}
}
static
request_reLoad
()
{
static
request_reLoad
()
{
let
token
=
localStorage
.
getItem
(
Constants
.
TOKEN_KEY
)
&&
JSON
.
parse
(
localStorage
.
getItem
(
Constants
.
TOKEN_KEY
)).
refresh_token
let
token
=
let
data
=
qs
.
stringify
({
'scope'
:
'ui'
,
'grant_type'
:
'refresh_token'
,
'refresh_token'
:
token
});
localStorage
.
getItem
(
Constants
.
TOKEN_KEY
)
&&
JSON
.
parse
(
localStorage
.
getItem
(
Constants
.
TOKEN_KEY
)).
refresh_token
;
let
data
=
qs
.
stringify
({
scope
:
'ui'
,
grant_type
:
'refresh_token'
,
refresh_token
:
token
,
});
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
axios
.
post
(
API
.
API_USER_LOGIN
,
data
,
{
axios
headers
:
{
.
post
(
API
.
API_USER_LOGIN
,
data
,
{
'Authorization'
:
'Basic YnJvd3Nlcjo='
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded'
Authorization
:
'Basic YnJvd3Nlcjo='
,
}
'Content-Type'
:
'application/x-www-form-urlencoded'
,
}).
then
(
function
(
response
)
{
resolve
(
response
.
data
)
})
},
.
catch
(
function
(
error
)
{
reject
(
error
)
})
})
})
.
then
(
function
(
response
)
{
resolve
(
response
.
data
);
})
.
catch
(
function
(
error
)
{
reject
(
error
);
});
});
}
}
}
}
export
default
Axios
;
export
default
Axios
;
src/renderer/console/login.jsx
View file @
6203cc03
...
@@ -64,10 +64,17 @@ export default (props) => {
...
@@ -64,10 +64,17 @@ export default (props) => {
const
[
usernameError
,
setUsernameError
]
=
useState
(
false
);
const
[
usernameError
,
setUsernameError
]
=
useState
(
false
);
const
[
password
,
setPassword
]
=
useState
(
''
);
const
[
password
,
setPassword
]
=
useState
(
''
);
const
[
passwordError
,
setPasswordError
]
=
useState
(
false
);
const
[
passwordError
,
setPasswordError
]
=
useState
(
false
);
const
[
checked
,
setChecked
]
=
useState
(
localStorage
.
getItem
(
'stay'
)
&&
localStorage
.
getItem
(
'stay'
)
===
"1"
?
true
:
false
);
const
[
checked
,
setChecked
]
=
useState
(
localStorage
.
getItem
(
'stay'
)
&&
localStorage
.
getItem
(
'stay'
)
===
'1'
?
true
:
false
);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
localStorage
.
getItem
(
Constants
.
TOKEN_KEY
)
&&
localStorage
.
getItem
(
'stay'
)
===
"1"
){
if
(
localStorage
.
getItem
(
Constants
.
TOKEN_KEY
)
&&
localStorage
.
getItem
(
'stay'
)
===
'1'
)
{
getUserData
();
getUserData
();
}
}
if
(
!
localStorage
.
getItem
(
'Preferences'
))
{
if
(
!
localStorage
.
getItem
(
'Preferences'
))
{
...
@@ -77,22 +84,14 @@ export default (props) => {
...
@@ -77,22 +84,14 @@ export default (props) => {
);
);
}
}
if
(
!
localStorage
.
getItem
(
'stay'
)){
if
(
!
localStorage
.
getItem
(
'stay'
))
{
localStorage
.
setItem
(
localStorage
.
setItem
(
'stay'
,
'1'
);
'stay'
,
'1'
);
}
}
},
[]);
},
[]);
const
handleChange
=
(
event
)
=>
{
const
handleChange
=
(
event
)
=>
{
setChecked
(
event
.
target
.
checked
);
setChecked
(
event
.
target
.
checked
);
localStorage
.
setItem
(
localStorage
.
setItem
(
'stay'
,
event
.
target
.
checked
?
'1'
:
'2'
);
'stay'
,
event
.
target
.
checked
?
'1'
:
"2"
);
};
};
const
login
=
async
()
=>
{
const
login
=
async
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment