File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function getQueryVariable ( variable ) {
2+ let query = window . location . search . substring ( 1 ) ;
3+ let vars = query . split ( '&' ) ;
4+ for ( let i = 0 ; i < vars . length ; i ++ ) {
5+ let pair = vars [ i ] . split ( '=' ) ;
6+ if ( pair [ 0 ] === variable ) {
7+ return pair [ 1 ] ;
8+ }
9+ }
10+ return null ;
11+ }
12+ export default getQueryVariable ;
Original file line number Diff line number Diff line change @@ -99,17 +99,14 @@ let Service = {
9999 } ) ;
100100 } ,
101101 // get auth-code
102- getOauthCode ( username , password ) {
103- return Fetch (
104- '/auth/api/oauth?response_type=code&client_id=51f03389-2a18-4941-ba73-c85d08201d42' ,
105- {
106- method : 'POST' ,
107- data : {
108- username : username ,
109- password : btoa ( password )
110- }
102+ getOauthCode ( username , password , client_id ) {
103+ return Fetch ( `/auth/api/oauth?response_type=code&client_id=${ client_id } ` , {
104+ method : 'POST' ,
105+ data : {
106+ username : username ,
107+ password : btoa ( password )
111108 }
112- ) ;
109+ } ) ;
113110 } ,
114111 //get user info
115112 getUserInfo ( ) {
Original file line number Diff line number Diff line change 77} from 'react-router-dom' ;
88import reset from './pages/reset/index' ;
99import Login from './pages/login/login' ;
10+ import Login_auth from './pages/login_auth/login' ;
1011import Register from './pages/register/register' ;
1112import * as serviceWorker from './serviceWorker' ;
1213import ReactDOM from 'react-dom' ;
@@ -21,6 +22,7 @@ export default class Portal extends Component {
2122 < Route path = "/Register" component = { Register } />
2223 < Route path = "/find_pass" component = { reset } />
2324 < Route path = "/login" component = { Login } />
25+ < Route path = "/login_auth" component = { Login_auth } />
2426 </ Switch >
2527 </ Router >
2628 ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ import Service from '../../common/service';
88import Layout from '../../component/layout' ;
99import Button from '../../component/common/button/button' ;
1010import Input from '../../component/common/input/input' ;
11- class Login extends Component {
11+ import getQueryVariable from '../../common/getFromUrl' ;
12+ class Login_auth extends Component {
1213 componentDidMount ( ) {
1314 if ( localStorage . getItem ( 'checked' ) ) {
1415 Service . Login (
@@ -62,8 +63,9 @@ class Login extends Component {
6263 }
6364 async login ( ) {
6465 const { username, password, isChecked } = this . state ;
66+ let client_id = getQueryVariable ( 'client_id' ) ;
6567 if ( username && password ) {
66- const res = await Service . getOauthCode ( username , password ) ;
68+ const res = await Service . getOauthCode ( username , password , client_id ) ;
6769 console . log ( res ) ;
6870 if ( res . code === 20102 ) {
6971 this . alert ( '用户不存在' ) ;
@@ -155,4 +157,4 @@ class Login extends Component {
155157 ) ;
156158 }
157159}
158- export default Login ;
160+ export default Login_auth ;
You can’t perform that action at this time.
0 commit comments