Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
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
Иван Кубота
kus-admin
Commits
cac92781
Commit
cac92781
authored
Jan 29, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Error status on phone\code submitting.
new AuthAjax + old Ajax refactor
parent
92a580d0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
68 deletions
+88
-68
Ajax.jsx
src/controller/Ajax.jsx
+22
-0
Ajax.jsx
src/core/Ajax.jsx
+59
-66
Store.js
src/model/Store.js
+3
-1
Login.jsx
src/view/page/login/Login.jsx
+1
-1
LoginCode.jsx
src/view/page/login/LoginCode.jsx
+1
-0
LoginPhone.jsx
src/view/page/login/LoginPhone.jsx
+2
-0
No files found.
src/controller/Ajax.jsx
0 → 100644
View file @
cac92781
import
{
AsyncAjax
}
from
"/core/Ajax.jsx"
;
export
{
AsyncAjax
}
from
"/core/Ajax.jsx"
;
export
const
AsyncAuthAjax
=
{
async
get
(
url
)
{
if
(
!
store
.
get
(
'account.token'
))
return
false
;
return
await
AsyncAjax
.
get
(
url
,
{
authorization
:
'Bearer '
+
store
.
get
(
'account.token'
)
})
},
async
post
(
url
,
data
)
{
if
(
!
store
.
get
(
'account.token'
))
return
false
;
return
await
AsyncAjax
.
post
(
url
,
data
,
{
authorization
:
'Bearer '
+
store
.
get
(
'account.token'
)
})
}
};
\ No newline at end of file
src/core/Ajax.jsx
View file @
cac92781
const
transformCfg
=
function
(
cfg
)
{
return
{
...
cfg
,
headers
:
{
'Content-Type'
:
'application/json'
,
...(
cfg
&&
cfg
.
headers
||
{})
}
}
};
const
xhrProceed
=
function
(
method
,
xhr
,
cfg
,
cb
)
{
xhr
.
open
(
method
,
cfg
.
url
,
true
);
for
(
let
key
in
cfg
.
headers
){
xhr
.
setRequestHeader
(
key
,
cfg
.
headers
[
key
]);
}
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
&&
xhr
.
status
===
200
)
{
let
json
;
try
{
json
=
JSON
.
parse
(
xhr
.
responseText
);
cb
&&
cb
(
false
,
json
);
}
catch
(
e
)
{
console
.
error
(
'AJAX:'
+
method
+
' Incorrect Response ← '
+
cfg
.
url
,
xhr
.
responseText
,
e
);
cb
&&
cb
(
true
,
e
);
}
}
else
if
(
xhr
.
status
===
404
){
cb
&&
cb
(
true
);
}
else
if
(
xhr
.
status
===
401
){
//Пользователь не авторизован
window
.
location
.
href
=
"/login"
;
return
;
}
else
if
(
xhr
.
status
===
403
){
//Нет доступа к ассистенту
window
.
location
.
href
=
"/"
;
return
;
}
else
if
(
xhr
.
status
>=
400
){
/*HeaderModel.statusNotification.statuses.push({type: 'error'});
setTimeout(function () {
HeaderModel.statusNotification.statuses.length = 0;
}, 3000);*/
cb
&&
cb
(
true
,
{
"status"
:
"error"
});
return
;
}
};
};
export
const
Ajax
=
{
post
(
url
,
data
,
cb
){
post
(
url
,
data
,
cb
,
cfg
){
let
stringData
=
''
;
try
{
stringData
=
JSON
.
stringify
(
data
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"POST"
,
url
,
true
);
xhr
.
setRequestHeader
(
"Content-Type"
,
"application/json"
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
&&
xhr
.
status
===
200
)
{
let
json
;
try
{
json
=
JSON
.
parse
(
xhr
.
responseText
);
cb
&&
cb
(
false
,
json
);
}
catch
(
e
)
{
console
.
error
(
'AJAX:POST Incorrect Response ← '
+
url
,
xhr
.
responseText
,
e
);
cb
&&
cb
(
true
,
e
);
}
}
else
if
(
xhr
.
status
===
404
){
cb
&&
cb
(
true
);
}
else
if
(
xhr
.
status
===
401
){
//Пользователь не авторизован
window
.
location
.
href
=
"/login"
;
return
;
}
else
if
(
xhr
.
status
===
403
){
//Нет доступа к ассистенту
window
.
location
.
href
=
"/"
;
return
;
}
else
if
(
xhr
.
status
>=
400
){
/*HeaderModel.statusNotification.statuses.push({type: 'error'});
setTimeout(function () {
HeaderModel.statusNotification.statuses.length = 0;
}, 3000);*/
cb
&&
cb
(
true
,
{
"status"
:
"error"
});
return
;
}
};
cfg
=
transformCfg
(
cfg
||
{});
cfg
.
url
=
url
;
xhrProceed
(
"POST"
,
xhr
,
cfg
,
cb
);
xhr
.
send
(
stringData
);
}
catch
(
e
)
{
/* HeaderModel.statusNotification.statuses.push({type: 'error'});
...
...
@@ -46,39 +63,14 @@ export const Ajax = {
}
},
get
(
url
,
cb
){
get
(
url
,
cb
,
cfg
){
try
{
const
xhr
=
new
XMLHttpRequest
();
cfg
=
transformCfg
(
cfg
||
{});
cfg
.
url
=
url
;
xhr
.
open
(
"GET"
,
url
,
true
);
xhr
.
setRequestHeader
(
"Content-Type"
,
"application/json"
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
&&
xhr
.
status
===
200
)
{
let
json
;
try
{
json
=
JSON
.
parse
(
xhr
.
responseText
);
cb
&&
cb
(
false
,
json
);
}
catch
(
e
)
{
console
.
error
(
'AJAX:GET Incorrect Response ← '
+
url
,
xhr
.
responseText
,
e
);
cb
&&
cb
(
true
,
e
);
}
}
else
if
(
xhr
.
status
===
404
){
cb
&&
cb
(
true
);
}
else
if
(
xhr
.
status
===
401
){
//Пользователь не авторизован
window
.
location
.
href
=
"/login"
;
return
;
}
else
if
(
xhr
.
status
===
403
){
//Нет доступа к ассистенту
window
.
location
.
href
=
"/"
;
return
;
}
else
if
(
xhr
.
status
>=
400
){
/*HeaderModel.statusNotification.statuses.push({type: 'error'});
setTimeout(function () {
HeaderModel.statusNotification.statuses.length = 0;
}, 3000);*/
cb
&&
cb
(
true
,
{
"status"
:
"error"
});
}
};
xhrProceed
(
xhr
,
url
,
cb
);
xhrProceed
(
"GET"
,
xhr
,
cfg
,
cb
);
xhr
.
send
(
null
);
}
catch
(
e
)
{
/*HeaderModel.statusNotification.statuses.push({type: 'error'});
...
...
@@ -91,7 +83,7 @@ export const Ajax = {
}
};
export
const
AsyncAjax
=
{
get
(
url
)
{
get
(
url
,
cfg
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
Ajax
.
get
(
url
,
function
(
err
,
data
)
{
if
(
err
){
...
...
@@ -99,10 +91,10 @@ export const AsyncAjax = {
}
else
{
resolve
(
data
);
}
})
}
,
cfg
)
});
},
post
(
url
,
data
){
post
(
url
,
data
,
cfg
){
return
new
Promise
(
function
(
resolve
,
reject
)
{
Ajax
.
post
(
url
,
data
,
function
(
err
,
data
)
{
if
(
err
){
...
...
@@ -110,7 +102,7 @@ export const AsyncAjax = {
}
else
{
resolve
(
data
);
}
})
}
,
cfg
)
});
}
};
\ No newline at end of file
src/model/Store.js
View file @
cac92781
...
...
@@ -3,8 +3,10 @@ const store = new Store({
current
:
'login'
},
'account'
:
{
userID
:
5
,
name
:
'Диогроген Курославович'
,
phone
:
'79999877414'
phone
:
'79999877414'
,
token
:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1ODAzMDg0NTcsImV4cCI6MTU4MDM5NDg1Nywicm9sZXMiOlsiUk9MRV9BRE1JTiIsIlJPTEVfRU1QTE9ZRUUiXSwicGhvbmUiOiI3OTk5OTg3NzQxNCIsImlkIjo1fQ.yt7LqaBkHZ_YFXg4WV8LRrm6eW9RdBjFbWNlLBYJXDyFPKjeVuR9PTGwnZdztqRxnGEKc60FnZfqpf52rfTdgkZWuuy_jXQbxfUzRvuD2GHPd4Ds12ucQnbij71-Rv0d8mA4L3EzbEQzMfSwoQsjhY6PXmhHRft4mSuXm0Cx4cn7ms92gTBFGbSWA-Ru395jTcaTpWdpAyIQFCMwAyQ1zQDRwsYc4RPPVKTH2BhkGVLVWlMDh_D22kduV-zcEzxEAFvOf6HhctsYBaasByhXIHVKQUcSKjA5bz_eftW7XQWeer0gQNR3OLRP9Qo7INL8GnhVhGEuu5UL6x0JJ9FeutOhZ4xa0jOqwzmYRcTMP63LbWNoSGHgn-UY14yG_O31Ij0wDNS-VqhCoVB1IdGawWX_p3eKLuUvCX38ZLs3cAIU1vmHlF--0KNSwo3OeYj-U9R8tWPi-zkUDw29ZAM1wu38uXI4_bw_UG2g53cSdjxuIQw8sLmAp7EF-6R1q28YQecqVKm-d8VgVeVAh8ueicFeejSzgax-3GRjHR9Kudqgxescas6rm6g5iV_-73VUXrn-8rvg2vXuB3nF-7X-SWV2gKFBP9u0hTGMBeseODyjohN3bWjnfPWU0rWhwNUsPIJabzg0iICv4a5li507TCaHg025HEa2V2mayj0wkk8'
}
});
...
...
src/view/page/login/Login.jsx
View file @
cac92781
...
...
@@ -11,7 +11,7 @@ import LoginCode from './LoginCode.jsx';
const
{
AND
,
OR
,
IF
}
=
Store
;
export
default
D
.
declare
(
'view.page.Login'
,
()
=>
{
const
loginStore
=
new
Store
({
phone
:
'7999
1112233
'
,
phone
:
'7999
9877415
'
,
code
:
''
,
codeValid
:
false
,
active
:
'enterPhone'
,
...
...
src/view/page/login/LoginCode.jsx
View file @
cac92781
...
...
@@ -7,6 +7,7 @@ const {AND, OR, IF} = Store;
export
default
D
.
declare
(
'view.page.LoginCode'
,
({
loginStore
})
=>
{
const
checkCode
=
function
()
{
loginStore
.
set
(
'codeChecking'
,
true
);
loginStore
.
set
(
'codeError'
,
false
);
try
{
}
catch
(
e
){
...
...
src/view/page/login/LoginPhone.jsx
View file @
cac92781
...
...
@@ -8,6 +8,8 @@ export default D.declare('view.page.LoginPhone', ({loginStore}) => {
const
checkPhone
=
async
function
()
{
loginStore
.
set
(
'phoneChecking'
,
true
);
loginStore
.
set
(
'phoneError'
,
false
);
try
{
const
result
=
await
AsyncAjax
.
post
(
API
.
ENDPOINTS
.
CHECK_PHONE
(),
{
phone
:
loginStore
.
get
(
'phone'
)
...
...
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