|
|
@@ -11,7 +11,7 @@ import My from './pages/my'
|
|
|
import {graphqlFC} from "./configs/url"
|
|
|
import {getCookie, setCookie} from "./utils/cookie"
|
|
|
import {find_user_by_openid, create_user} from "./utils/gql"
|
|
|
-import {idGen} from "./utils/func"
|
|
|
+import {idGen, getIsWechatBrowser} from "./utils/func"
|
|
|
import './app.css'
|
|
|
|
|
|
class App extends Component {
|
|
|
@@ -84,38 +84,40 @@ class App extends Component {
|
|
|
}
|
|
|
|
|
|
oauthLogin = () => {
|
|
|
- setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
|
|
|
- let openid = getCookie("openid")
|
|
|
- let user_id = getCookie("user_id")
|
|
|
- console.log('oauthLogin openid',openid)
|
|
|
-
|
|
|
- if (!openid) {
|
|
|
- window.location.href = "/subscribe"
|
|
|
-
|
|
|
- }
|
|
|
- if(!user_id){
|
|
|
- request(graphqlFC, find_user_by_openid ,{openid})
|
|
|
- .then(data => {
|
|
|
- console.log('find user data',data)
|
|
|
- if(data.userbyprops.length){
|
|
|
- let id = data.userbyprops[0].id
|
|
|
- setCookie('user_id',id)
|
|
|
- }else {
|
|
|
- let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
|
- let id = idGen('user')
|
|
|
- const userContent = {
|
|
|
- email: "",
|
|
|
- updatedAt: "",
|
|
|
- password: "",
|
|
|
- telephone: "",
|
|
|
- username: "",
|
|
|
- createdAt,
|
|
|
- openid,
|
|
|
- id,
|
|
|
- userData_id: ""
|
|
|
-
|
|
|
- }
|
|
|
- request(graphqlFC, create_user ,userContent)
|
|
|
+ let isWechatLogin = getIsWechatBrowser()
|
|
|
+ // console.log('isWechatLogin',isWechatLogin)
|
|
|
+ if(isWechatLogin){
|
|
|
+ // setCookie("openid","obR_j5GbxDfGlOolvSeTdZUwfpKA")
|
|
|
+ let openid = getCookie("openid")
|
|
|
+ let user_id = getCookie("user_id")
|
|
|
+ console.log('oauthLogin openid',openid)
|
|
|
+
|
|
|
+ if (!openid) {
|
|
|
+ window.location.href = "/subscribe"
|
|
|
+ }
|
|
|
+ if(!user_id){
|
|
|
+ request(graphqlFC, find_user_by_openid ,{openid})
|
|
|
+ .then(data => {
|
|
|
+ console.log('find user data',data)
|
|
|
+ if(data.userbyprops.length){
|
|
|
+ let id = data.userbyprops[0].id
|
|
|
+ setCookie('user_id',id)
|
|
|
+ }else {
|
|
|
+ let createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ let id = idGen('user')
|
|
|
+ const userContent = {
|
|
|
+ email: "",
|
|
|
+ updatedAt: "",
|
|
|
+ password: "",
|
|
|
+ telephone: "",
|
|
|
+ username: "",
|
|
|
+ createdAt,
|
|
|
+ openid,
|
|
|
+ id,
|
|
|
+ userData_id: ""
|
|
|
+
|
|
|
+ }
|
|
|
+ request(graphqlFC, create_user ,userContent)
|
|
|
.then(data => {
|
|
|
console.log('create user data',data)
|
|
|
setCookie('user_id',id)
|
|
|
@@ -123,11 +125,15 @@ class App extends Component {
|
|
|
.catch(err => {
|
|
|
console.log(err, `graphql-request create user error`)
|
|
|
})
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err, `graphql-request find user error`)
|
|
|
- })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err, `graphql-request find user error`)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ setCookie("user_id","ioobot")
|
|
|
+ setCookie("openid","ioobot")
|
|
|
}
|
|
|
}
|
|
|
|