Login/Auth and pariticipate. Telegram auth (wip)

This commit is contained in:
vjrj 2017-12-22 09:33:37 +01:00
parent 91b4197b04
commit 4227389a67
14 changed files with 161 additions and 48 deletions

View file

@ -118,10 +118,10 @@ Meteor.publish('activefiresmyloc', function activeInMyLoc(zoom, lat, lng, height
check(height, NullOr(Number)); check(height, NullOr(Number));
check(width, NullOr(Number)); check(width, NullOr(Number));
// console.log(`Check active fires in ${lat},${lng} with zoom ${zoom} pixels in ${height}x${width} map`); // console.log(`Check active fires in ${lat},${lng} with zoom ${zoom} pixels in ${height}x${width} map`);
if (lat === null || lng === null) { if (lat && lng) {
return activefires(zoom, lat, lng, height, width);
}
const location = localize(); const location = localize();
// console.log(`${location.latitude}, ${location.longitude}`); // console.log(`${location.latitude}, ${location.longitude}`);
return activefires(zoom, location.latitude, location.longitude, height, width); return activefires(zoom, location.latitude, location.longitude, height, width);
}
return activefires(zoom, lat, lng, height, width);
}); });

View file

@ -3,13 +3,13 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import SimpleSchema from 'simpl-schema'; import SimpleSchema from 'simpl-schema';
import { defaultCreatedAt, defaultUpdateAt } from '/imports/api/Utility/Utils.js'; import { defaultCreatedAt, defaultUpdateAt } from '/imports/api/Utility/Utils.js';
import i18n from 'i18next';
const schemaUserProfile = new SimpleSchema({ const schemaUserProfile = new SimpleSchema({
// name: { type: String, optional: true }, /* Our users has a name of type Object while Google Service, for instance, not */
name: Object, /* name: { type: String, optional: true }, */
/* name: Object,
'name.first': String, 'name.first': String,
'name.last': String, 'name.last': String, */
lang: { type: String, optional: true }, lang: { type: String, optional: true },
telegramChatId: { type: Number, optional: true }, telegramChatId: { type: Number, optional: true },
telegramUsername: { type: String, optional: true }, telegramUsername: { type: String, optional: true },

View file

@ -2,14 +2,18 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Route, Redirect } from 'react-router-dom'; import { Route, Redirect } from 'react-router-dom';
const Public = ({ loggingIn, authenticated, component, path, exact, ...rest }) => ( const Public = ({
loggingIn, authenticated, component, location, path, exact, ...rest
}) => (
<Route <Route
path={path} path={path}
exact={exact} exact={exact}
render={props => ( render={props => (
!authenticated ? !authenticated ?
(React.createElement(component, { ...props, ...rest, loggingIn, authenticated })) : (React.createElement(component, {
(<Redirect to="/subscriptions" />) ...props, ...rest, loggingIn, authenticated
})) :
(<Redirect to={{ pathname: '/subscriptions', state: location.state }} />)
)} )}
/> />
); );
@ -17,7 +21,7 @@ const Public = ({ loggingIn, authenticated, component, path, exact, ...rest }) =
Public.propTypes = { Public.propTypes = {
loggingIn: PropTypes.bool.isRequired, loggingIn: PropTypes.bool.isRequired,
authenticated: PropTypes.bool.isRequired, authenticated: PropTypes.bool.isRequired,
component: PropTypes.func.isRequired, component: PropTypes.func.isRequired
}; };
export default Public; export default Public;

View file

@ -74,7 +74,7 @@ class SelectionMap extends Component {
onFstBtn() { onFstBtn() {
this.props.onFstBtn({ this.props.onFstBtn({
location: { lat: this.state.center[0], lon: this.state.center[1] }, location: { lat: this.state.marker[0], lon: this.state.marker[1] },
distance: this.state.distance distance: this.state.distance
}); });
} }
@ -113,7 +113,7 @@ class SelectionMap extends Component {
fit() { fit() {
// console.log("fit!"); // console.log("fit!");
if (this.props.currentSubs.length > 0 && this.state.subsFit) { if (this.props.currentSubs.length > 0 && this.state.subsFit && this.props.action !== action.add) {
// has autofit, do nothing // has autofit, do nothing
} else if (this.selectionMap && this.distanceCircle) { } else if (this.selectionMap && this.distanceCircle) {
if (!this.getMap().getBounds().contains(this.distanceCircle.leafletElement.getBounds())) { if (!this.getMap().getBounds().contains(this.distanceCircle.leafletElement.getBounds())) {

View file

@ -20,7 +20,10 @@ class FireSubscription extends React.Component {
zoom: this.props.zoom, zoom: this.props.zoom,
distance: this.props.distance distance: this.props.distance
}; };
// console.log(this.props.location.state); if (props.location) {
console.log(props.location.state);
}
console.log(this.state);
} }
componentDidMount() { componentDidMount() {

View file

@ -38,7 +38,10 @@ class FiresMap extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
viewport: this.props.viewport, viewport: {
center: props.center,
zoom: props.zoom
},
useMarkers: false, useMarkers: false,
showSubsUnion: true showSubsUnion: true
}; };
@ -214,7 +217,8 @@ FiresMap.propTypes = {
activefires: PropTypes.arrayOf(PropTypes.object).isRequired, activefires: PropTypes.arrayOf(PropTypes.object).isRequired,
firealerts: PropTypes.arrayOf(PropTypes.object).isRequired, firealerts: PropTypes.arrayOf(PropTypes.object).isRequired,
activefirestotal: PropTypes.number.isRequired, activefirestotal: PropTypes.number.isRequired,
viewport: PropTypes.object.isRequired, center: PropTypes.arrayOf(PropTypes.number),
zoom: PropTypes.number,
t: PropTypes.func.isRequired t: PropTypes.func.isRequired
}; };
@ -224,6 +228,7 @@ export default translate([], { wait: true })(withTracker(() => {
Meteor.autorun(() => { Meteor.autorun(() => {
if (geolocation.get() && init) { if (geolocation.get() && init) {
center.set(geolocation.get()); center.set(geolocation.get());
// console.log(`Geolocation ${geolocation.get()}`);
init = false; init = false;
} }
if (mapSize.get()) { if (mapSize.get()) {
@ -258,9 +263,7 @@ export default translate([], { wait: true })(withTracker(() => {
firealerts: FireAlertsCollection.find().fetch().map(doc => ( firealerts: FireAlertsCollection.find().fetch().map(doc => (
{ _id: doc._id, lat: doc.location.lat, lon: doc.location.lon } { _id: doc._id, lat: doc.location.lat, lon: doc.location.lon }
)), )),
viewport: {
center: geolocation.get(), center: geolocation.get(),
zoom: zoom.get() zoom: zoom.get()
}
}; };
})(FiresMap)); })(FiresMap));

View file

@ -16,7 +16,8 @@ class Login extends React.Component {
super(props); super(props);
this.t = props.t; this.t = props.t;
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
// console.log(this.props.location.state); console.log(this.props.location.state);
this.state = props.location.state;
} }
componentDidMount() { componentDidMount() {
@ -110,6 +111,7 @@ class Login extends React.Component {
Login.propTypes = { Login.propTypes = {
history: PropTypes.object.isRequired, history: PropTypes.object.isRequired,
t: PropTypes.func.isRequired, t: PropTypes.func.isRequired,
location: PropTypes.object
}; };
export default translate([], { wait: true })(Login); export default translate([], { wait: true })(Login);

View file

@ -11,7 +11,15 @@ class NewSubscription extends Component {
const pushState = this.props.location.state; const pushState = this.props.location.state;
this.state = { this.state = {
center: pushState ? pushState.center : [null, null], center: pushState ? pushState.center : [null, null],
zoom: pushState ? pushState.zoom : null zoom: pushState ? pushState.zoom : null,
// we have a subscription from home?
doc: pushState && pushState.location ? {
location: {
lat: pushState.location.lat,
lot: pushState.location.lon
},
distance: pushState.distance
} : undefined
}; };
} }
@ -24,6 +32,7 @@ class NewSubscription extends Component {
history={history} history={history}
center={this.state.center} center={this.state.center}
zoom={this.state.zoom} zoom={this.state.zoom}
doc={this.state.doc}
/> />
</div> </div>
); );

View file

@ -1,3 +1,5 @@
/* eslint-disable react/jsx-indent-props */
import React from 'react'; import React from 'react';
import { Row, FormGroup, ControlLabel, Button } from 'react-bootstrap'; import { Row, FormGroup, ControlLabel, Button } from 'react-bootstrap';
import Col from '../../components/Col/Col'; import Col from '../../components/Col/Col';
@ -6,6 +8,8 @@ import { Link } from 'react-router-dom';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base'; import { Accounts } from 'meteor/accounts-base';
import { Bert } from 'meteor/themeteorchef:bert'; import { Bert } from 'meteor/themeteorchef:bert';
import randomHex from 'random-hexadecimal';
import Icon from '../../components/Icon/Icon';
import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButtons'; import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButtons';
import InputHint from '../../components/InputHint/InputHint'; import InputHint from '../../components/InputHint/InputHint';
import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter'; import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter';
@ -64,7 +68,7 @@ class Signup extends React.Component {
} }
handleSubmit() { handleSubmit() {
const { history } = this.props; const { history, t } = this.props;
Accounts.createUser({ Accounts.createUser({
email: this.emailAddress.value, email: this.emailAddress.value,
@ -80,31 +84,35 @@ class Signup extends React.Component {
Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger'); Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
} else { } else {
Meteor.call('users.sendVerificationEmail'); Meteor.call('users.sendVerificationEmail');
Bert.alert('Welcome!', 'success'); Bert.alert(t('Bienvenid@!'), 'success');
history.push('/subscriptions'); history.push('/subscriptions');
} }
}); });
} }
render() { render() {
const { t, history } = this.props;
return (<div className="Signup"> return (<div className="Signup">
<Row className="align-items-center justify-content-center"> <Row className="align-items-center justify-content-center">
<Col xs={12} sm={6} md={5} lg={4}> <Col xs={12} sm={6} md={5} lg={4}>
<h4 className="page-header">{this.t('Registrarse')}</h4> <h4 className="page-header">{t('Registrarse')}</h4>
<Row> <Row>
{/* <Col xs={12}> <Col xs={12}>
<button <button
className={`btn btn-block btn-raised btn-primary OAuthLoginButtonDis OAuthLoginButton-telegram`} className="btn btn-block btn-raised btn-primary OAuthLoginButtonDis OAuthLoginButton-telegram"
type="button" onClick={() => handleLogin(service, callback)}> type="button"
<span><Icon icon="telegram" /> Usa nuestro bot de Telegram</span> onClick={() => { const hex = randomHex({ max: 20 }); window.open(`https://t.me/TodosContraElFuego_bot?start=${hex}`); }}
>
<span><Icon icon="telegram" /> {t('Iniciar sesión con Telegram')}</span>
</button> </button>
</Col> */} </Col>
<Col xs={12}> <Col xs={12}>
<OAuthLoginButtons <OAuthLoginButtons
services={['telegram', 'google']} services={['telegram', 'google']}
emailMessage={{ emailMessage={{
offset: 97, offset: 97,
text: this.t('o regístrate con un correo') text: t('o regístrate con un correo')
}} }}
/> />
</Col> </Col>
@ -113,7 +121,7 @@ class Signup extends React.Component {
<Row> <Row>
<Col xs={6}> <Col xs={6}>
<FormGroup> <FormGroup>
<ControlLabel>{this.t('Nombre')}</ControlLabel> <ControlLabel>{t('Nombre')}</ControlLabel>
<input <input
type="text" type="text"
name="firstName" name="firstName"
@ -124,7 +132,7 @@ class Signup extends React.Component {
</Col> </Col>
<Col xs={6}> <Col xs={6}>
<FormGroup> <FormGroup>
<ControlLabel>{this.t('Apellidos')}</ControlLabel> <ControlLabel>{t('Apellidos')}</ControlLabel>
<input <input
type="text" type="text"
name="lastName" name="lastName"
@ -135,7 +143,7 @@ class Signup extends React.Component {
</Col> </Col>
</Row> </Row>
<FormGroup> <FormGroup>
<ControlLabel>{this.t('Correo electrónico')}</ControlLabel> <ControlLabel>{t('Correo electrónico')}</ControlLabel>
<input <input
type="email" type="email"
name="emailAddress" name="emailAddress"
@ -144,18 +152,18 @@ class Signup extends React.Component {
/> />
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<ControlLabel>{this.t('Contraseña')}</ControlLabel> <ControlLabel>{t('Contraseña')}</ControlLabel>
<input <input
type="password" type="password"
name="password" name="password"
ref={password => (this.password = password)} ref={password => (this.password = password)}
className="form-control" className="form-control"
/> />
<InputHint>{this.t('Usa al menos seis caracteres.')}</InputHint> <InputHint>{t('Usa al menos seis caracteres.')}</InputHint>
</FormGroup> </FormGroup>
<Button type="submit" bsStyle="success">{this.t('Registrarse')}</Button> <Button type="submit" bsStyle="success">{t('Registrarse')}</Button>
<AccountPageFooter> <AccountPageFooter>
<p>{this.t('¿Ya tienes un cuenta?')} <Link to={{ pathname: '/login', state: this.state }} >{this.t('Iniciar sesión')}</Link>.</p> <p>{t('¿Ya tienes un cuenta?')} <Link to={{ pathname: '/login', state: this.state }} >{t('Iniciar sesión')}</Link>.</p>
</AccountPageFooter> </AccountPageFooter>
</form> </form>
</Col> </Col>
@ -165,7 +173,8 @@ class Signup extends React.Component {
} }
Signup.propTypes = { Signup.propTypes = {
history: PropTypes.object.isRequired history: PropTypes.object.isRequired,
location: PropTypes.object
}; };
export default translate([], { wait: true })(Signup); export default translate([], { wait: true })(Signup);

View file

@ -19,9 +19,16 @@ class Subscriptions extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.t = props.t; this.t = props.t;
this.state = { if (props.location.state) {
action: action.view const received = props.location.state;
}; props.history.push(`${this.props.match.url}/new`, {
location: received.location,
distance: received.distance,
center: [received.location.lat, received.location.lon]
});
}
this.state = {};
this.state.action = action.view;
this.onViewportChanged = this.onViewportChanged.bind(this); this.onViewportChanged = this.onViewportChanged.bind(this);
this.onFstBtn = this.onFstBtn.bind(this); this.onFstBtn = this.onFstBtn.bind(this);
this.onSndBtn = this.onSndBtn.bind(this); this.onSndBtn = this.onSndBtn.bind(this);
@ -109,7 +116,8 @@ Subscriptions.propTypes = {
subscriptions: PropTypes.arrayOf(PropTypes.object).isRequired, subscriptions: PropTypes.arrayOf(PropTypes.object).isRequired,
match: PropTypes.object.isRequired, match: PropTypes.object.isRequired,
t: PropTypes.func.isRequired, t: PropTypes.func.isRequired,
history: PropTypes.object.isRequired history: PropTypes.object.isRequired,
location: PropTypes.object
}; };
export default translate([], { wait: true })(withTracker(() => { export default translate([], { wait: true })(withTracker(() => {

View file

@ -190,6 +190,7 @@ div.section.contact ul.list-social li.social-google-plus a:hover {
font-size: 16px; font-size: 16px;
} }
.OAuthLoginButton-telegram,
.OAuthLoginButtons > .btn { .OAuthLoginButtons > .btn {
letter-spacing: inherit; letter-spacing: inherit;
text-transform: none; text-transform: none;

70
package-lock.json generated
View file

@ -2342,6 +2342,11 @@
"integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==",
"dev": true "dev": true
}, },
"clamp": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/clamp/-/clamp-1.0.1.tgz",
"integrity": "sha1-ZqDmQBGBbjcZaCj9yMjBRzEshjQ="
},
"classnames": { "classnames": {
"version": "2.2.5", "version": "2.2.5",
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.5.tgz", "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.5.tgz",
@ -5250,6 +5255,11 @@
"number-is-nan": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz" "number-is-nan": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz"
} }
}, },
"is-function": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-function/-/is-function-1.0.1.tgz",
"integrity": "sha1-Es+5i2W1fdPRk6MSH19uL0N2ArU="
},
"is-glob": { "is-glob": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz",
@ -5270,6 +5280,11 @@
"xtend": "4.0.1" "xtend": "4.0.1"
} }
}, },
"is-nil": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-nil/-/is-nil-1.0.1.tgz",
"integrity": "sha1-LauingtYUGOHXntTnQcfWxWTeWk="
},
"is-number": { "is-number": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz", "resolved": "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz",
@ -5279,6 +5294,11 @@
"kind-of": "3.2.2" "kind-of": "3.2.2"
} }
}, },
"is-object": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz",
"integrity": "sha1-iVJojF7C/9awPsyF52ngKQMINHA="
},
"is-path-cwd": { "is-path-cwd": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz",
@ -7615,6 +7635,11 @@
"tmpl": "1.0.4" "tmpl": "1.0.4"
} }
}, },
"max-safe-int": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/max-safe-int/-/max-safe-int-1.0.0.tgz",
"integrity": "sha1-RPuo7Jk97ZH7LFo15xz5yfNpzlI="
},
"maxmind": { "maxmind": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/maxmind/-/maxmind-2.3.0.tgz", "resolved": "https://registry.npmjs.org/maxmind/-/maxmind-2.3.0.tgz",
@ -9624,6 +9649,33 @@
"ret": "0.1.15" "ret": "0.1.15"
} }
}, },
"random-hexadecimal": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/random-hexadecimal/-/random-hexadecimal-1.0.3.tgz",
"integrity": "sha1-vg80y8Jbnz21I8NZpUarl//zz1c=",
"requires": {
"random-natural": "1.0.3"
}
},
"random-integral": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/random-integral/-/random-integral-1.0.3.tgz",
"integrity": "sha1-j/PBF1ZcmgS2bd1VnzrtKb0PD2w=",
"requires": {
"clamp": "1.0.1",
"max-safe-int": "1.0.0",
"to-integer": "1.0.1"
}
},
"random-natural": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/random-natural/-/random-natural-1.0.3.tgz",
"integrity": "sha1-7yhhWwPCy3Gq6/fyT0hyZqRDxcA=",
"requires": {
"max-safe-int": "1.0.0",
"random-integral": "1.0.3"
}
},
"randomatic": { "randomatic": {
"version": "1.1.7", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz",
@ -11301,6 +11353,24 @@
"integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=", "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=",
"dev": true "dev": true
}, },
"to-integer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/to-integer/-/to-integer-1.0.1.tgz",
"integrity": "sha1-URrUHc5qk3MKjztuNaFk/YKUZNo=",
"requires": {
"is-function": "1.0.1",
"is-nil": "1.0.1",
"is-object": "1.0.1",
"is-symbol": "1.0.1"
},
"dependencies": {
"is-symbol": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz",
"integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI="
}
}
},
"tough-cookie": { "tough-cookie": {
"version": "2.3.3", "version": "2.3.3",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz",

View file

@ -42,6 +42,7 @@
"nodemailer": "^4.4.1", "nodemailer": "^4.4.1",
"popper.js": "^1.12.7", "popper.js": "^1.12.7",
"prop-types": "^15.6.0", "prop-types": "^15.6.0",
"random-hexadecimal": "^1.0.3",
"rc-slider": "^8.5.0", "rc-slider": "^8.5.0",
"rc-tooltip": "^3.7.0", "rc-tooltip": "^3.7.0",
"react": "^16.0.0", "react": "^16.0.0",

View file

@ -180,5 +180,8 @@
"No": "No", "No": "No",
"Sobre los datos y imágenes usados": "Sobre los datos y imágenes usados", "Sobre los datos y imágenes usados": "Sobre los datos y imágenes usados",
"Términos de Servicio": "Términos de Servicio", "Términos de Servicio": "Términos de Servicio",
"Política de Privacidad": "Política de Privacidad" "Política de Privacidad": "Política de Privacidad",
"No estás suscrito a fuegos en ninguna zona": "No estás suscrito a fuegos en ninguna zona",
"Iniciar sesión con Telegram":
"Iniciar sesión con Telegram"
} }