This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component, PropTypes } from 'react'; | |
| import FormInput from './../common/form-input' | |
| import { observer } from 'mobx-react' | |
| @observer | |
| class LoginForm extends Component { | |
| render() { | |
| const {form, onChange} = this.props; | |
| return ( | |
| <form onSubmit={this.submit}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { observer } from 'mobx-react'; | |
| import LoginForm from './login/login-form.component'; | |
| import LoginStore from './login/login.store'; | |
| let loginStore = LoginStore(); | |
| @observer | |
| class App extends Component { | |
| render() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {action, toJS} from 'mobx' | |
| import Validator from 'validatorjs'; | |
| class FormStore { | |
| getFlattenedValues = (valueKey = 'value') => { | |
| let data = {}; | |
| let form = toJS(this.form).fields; | |
| Object.keys(form).map(key => { | |
| data[key] = form[key][valueKey] | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { observable } from 'mobx' | |
| import GenericFormStore from './../common/generic-form.store' | |
| export default class LoginStore extends GenericFormStore { | |
| @observable | |
| form = {/* form model */} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post('/',function (req, res, next) { | |
| var body = req.body; | |
| if (!body.name || !body.email || !body.password) { | |
| return res.status(400).send("Missing username or email or password") | |
| }; | |
| // case #1- if user was registered (socials platform) before -> just add a password; | |
| User.findOneAndUpdate({ | |
| email: body.email | |
| }, { | |
| $set: {password: body.password} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User.findOneAndUpdate({}, (err, user) => { | |
| if (err) { // !!!!! | |
| return res.status(500).send(err) | |
| } | |
| // everething is ok, do smth | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var co = require('co') | |
| app.post('/',function (req, res, next) { | |
| var body = req.body; | |
| if (!body.name || !body.email || !body.password) { | |
| return res.status(400).send("Missing a username or email or password") | |
| }; | |
| co(function *(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = { | |
| middlewares: [], | |
| use(fn) { | |
| this.middlewares.push(fn) | |
| }, | |
| compose(middleware) { | |
| return function (next) { | |
| return dispatch(0) | |
| function dispatch(i) { | |
| let fn = middleware[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post('/', function (req, res, next) { | |
| var body = req.body; | |
| if (!body.name || !body.email || !body.password) { | |
| return res.status(400).send("Missing username or email or password") | |
| }; | |
| // case #1- if user was registered (socials platform) before -> just add a password; | |
| User.findOneAndUpdate({ | |
| email: body.email | |
| }, { | |
| $set: { password: body.password } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let compose = (middlewares) => { | |
| return function () { | |
| return dispatch(0) | |
| function dispatch(i) { | |
| let fn = middlewares[i] | |
| if (!fn) { | |
| return | |
| } | |
| fn(function next() { | |
| return dispatch(i + 1) |