Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
login with country code #65
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Nov 2, 2017
1 parent 7d6f5c4 commit 8e61e2f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"electron-window-state": "^4.1.1",
"han": "0.0.7",
"ionicons201": "^1.0.0",
"libphonenumber-js": "^0.4.38",
"md5": "^2.2.1",
"mobx": "^3.2.2",
"mobx-react": "^4.2.2",
Expand Down
10 changes: 9 additions & 1 deletion src/js/components/Menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ class Menu extends Component {
var link = `/user/${profile.userId}`;

if (!hasLogin()) {
return false;
return (
<p>
<Link
onClick={close}
to="/login">
Sign in
</Link>
</p>
);
}

return (
Expand Down
2 changes: 2 additions & 0 deletions src/js/stores/me.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { observable, action } from 'mobx';
import axios from 'axios';

import storage from 'utils/storage';
import helper from 'utils/helper';
import player from './player';
import home from './home';

Expand Down Expand Up @@ -37,6 +38,7 @@ class Me {

var response = await axios.get('/login/cellphone', {
params: {
countrycode: helper.getCountryCode(phone),
phone,
password,
}
Expand Down
11 changes: 11 additions & 0 deletions src/js/utils/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import uuid from 'uuid';
import { asYouType } from 'libphonenumber-js';

const helper = {
pad(number) {
Expand Down Expand Up @@ -31,6 +32,16 @@ const helper = {
});
},

getCountryCode(phone) {
if (/1[34578][012356789]\d{8}|134[012345678]\d{7}/.test(phone)) {
return '86';
}

var formatter = new asYouType();
formatter.input(phone);
return formatter.country_phone_code;
},

pureColor(colors = []) {
var rgb = colors[1] || [255, 255, 255];

Expand Down

0 comments on commit 8e61e2f

Please sign in to comment.