File tree Expand file tree Collapse file tree 5 files changed +85
-32
lines changed
Expand file tree Collapse file tree 5 files changed +85
-32
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,12 @@ module.exports = function (app, db) {
1919 if ( err ) {
2020 res . send ( { 'error' : 'An error has occurred' } ) ;
2121 } else {
22- console . log ( item ) ;
22+ if ( item ) {
2323 res . send ( item ) ;
24+ }
25+ else {
26+ res . status ( '401' ) . send ( 'Пользователь не найден' ) ;
27+ }
2428 }
2529 } ) ;
2630 }
Original file line number Diff line number Diff line change 11import request from 'superagent' ;
22
3-
3+ /*
44export const signUp = (userName,userLogin,pass) =>{
55
66request
@@ -14,6 +14,22 @@ request
1414 console.log(new Error(err.message))
1515})
1616
17+ }*/
18+ export const signUp = ( userName , userLogin , pass ) => {
19+ return new Promise ( ( resolve , reject ) => {
20+ request
21+ . post ( 'http://localhost:8000/api' )
22+ . send ( { name :userName , login : userLogin , password : pass } )
23+ . set ( 'Content-Type' , 'application/json' )
24+
25+ . then ( function ( res ) {
26+ resolve ( alert ( 'Пользователь зарегистрирован' ) ) ;
27+ } )
28+ . catch ( function ( err ) {
29+ console . log ( err ) ;
30+ reject ( new Error ( err . message ) )
31+ } )
32+ } )
1733}
1834export const signIn = ( userLogin , pass ) => {
1935 return new Promise ( ( resolve , reject ) => {
@@ -26,6 +42,7 @@ export const signIn = (userLogin, pass) => {
2642 resolve ( res . body ) ;
2743 } )
2844 . catch ( function ( err ) {
45+ console . log ( err ) ;
2946 reject ( new Error ( err . message ) )
3047 } )
3148 } )
Original file line number Diff line number Diff line change 1- import { signUp , signIn } from "../../api/index.js"
1+ import { signUp , signIn } from "../../api/index.js"
22
33
4- export const registrationUser = function ( userName , userLogin , pass ) {
5- signUp ( userName , userLogin , pass ) ;
6-
7-
8- return {
4+ export const registrationUser = ( userName , userLogin , pass ) => dispatch => {
5+ signUp ( userName , userLogin , pass ) . then ( ( res ) => dispatch ( {
96 type : "ADD_USER" ,
107 payload : {
118 userName,
129 userLogin,
1310 pass
1411 }
1512 }
13+ )
14+ )
15+ . catch ( ( err ) => {
16+
17+ alert ( err . message )
18+ } )
19+
20+
21+
1622} ;
1723
18- export const login = ( userLogin , pass ) => dispatch => {
19- signIn ( userLogin , pass ) . then ( ( res ) => dispatch ( {
20-
21- type : "LOGIN" ,
22- payload : {
23- userLogin : res . login ,
24- pass :res . password
25-
24+ export const login = ( userLogin , pass ) => dispatch => {
25+ signIn ( userLogin , pass ) . then ( ( res ) => dispatch ( {
26+
27+ type : "LOGIN" ,
28+ payload : {
29+ userLogin : res . login ,
30+ pass : res . password
31+
2632 }
2733 }
28- ) ) ;
2934
30-
31-
35+ ) )
36+ . catch ( ( err ) => {
37+
38+ alert ( err . message )
39+ } )
40+
41+
42+
43+
44+
45+
3246}
3347export const logout = function ( ) {
3448 return {
3549 type : "LOGOUT"
36-
50+
3751 }
3852}
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ import { createStore, applyMiddleware } from 'redux';
22import thunk from 'redux-thunk' ;
33import reducer from '../index' ;
44
5- export default createStore ( reducer , applyMiddleware ( thunk ) ) ;
5+ export default createStore ( reducer , window . __REDUX_DEVTOOLS_EXTENSION__ && window . __REDUX_DEVTOOLS_EXTENSION__ ( ) , applyMiddleware ( thunk ) ) ;
Original file line number Diff line number Diff line change @@ -10,28 +10,46 @@ module.exports = {
1010 resolve : {
1111 extensions : [ '.js' , '.jsx' ]
1212 } ,
13- module :{
14- rules :[
13+ module : {
14+
15+ rules : [
1516 {
16- test : / \. j s ? $ / ,
17- exclude : / n o d e _ m o d u l e s / ,
18- loader : 'babel-loader' ,
19- query : {
20- presets : [ 'es2015' , 'env' , 'react' ]
17+ test : / \. j s x ? $ / ,
18+ exclude : / ( n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s ) / ,
19+ use : {
20+ loader : 'babel-loader' ,
21+ options : {
22+ presets : [ 'react' ] ,
23+
24+ }
25+
2126 }
27+
28+
29+ } ,
30+ {
31+ test : / \. c s s ? $ / ,
32+ use : [ { loader : 'style-loader' } ,
33+ {
34+ loader : 'css-loader' ,
35+ options : {
36+ modules : true
37+ }
38+ } ]
2239 } ,
2340 {
24- test : / \. c s s $ / ,
41+ test : / \. ( g i f | p n g | j p e ? g | s v g ) $ / i ,
2542 use : [
26- { loader : 'style -loader' } ,
43+ 'file -loader',
2744 {
28- loader : 'css -loader' ,
45+ loader : 'image-webpack -loader' ,
2946 options : {
30- modules : true
47+ bypassOnDebug : true
3148 }
3249 }
3350 ]
3451 }
3552 ]
3653 }
54+
3755} ;
You can’t perform that action at this time.
0 commit comments