client/src/sagas/authSaga.js
changeset 199 c78d579f4b55
parent 134 be36eed5e6e0
equal deleted inserted replaced
198:f0f83f5530a6 199:c78d579f4b55
    98       //TODO: handle error
    98       //TODO: handle error
    99     }
    99     }
   100   }
   100   }
   101 }
   101 }
   102 
   102 
       
   103 export function* watchResetSubmit() {
       
   104   while (true) {
       
   105     const { email } = yield take(types.AUTH_RESET_SUBMIT);
       
   106     yield put({ type: types.AUTH_RESET_REQUEST, email });
       
   107   }
       
   108 }
       
   109 
       
   110 
       
   111 function* watchResetRequest(context) {
       
   112   while (true) {
       
   113     try {
       
   114 
       
   115         const { email } = yield take(types.AUTH_RESET_REQUEST);
       
   116 
       
   117         const client = context.client;
       
   118         yield client.post('/api/auth/password/reset/', { email });
       
   119 
       
   120         context.history.push('/sessions');
       
   121 
       
   122     } catch(e) {
       
   123       yield put({ type: types.AUTH_RESET_ERROR, error: e });
       
   124     }
       
   125   }
       
   126 }
       
   127 
       
   128 
       
   129 
   103 // ---
   130 // ---
   104 
   131 
   105 export default function* rootSaga(context) {
   132 export default function* rootSaga(context) {
   106   yield all([
   133   yield all([
   107     watchLoginSubmit(),
   134     watchLoginSubmit(),
   108     watchLoginRequest(context),
   135     watchLoginRequest(context),
   109     watchRegisterSubmit(),
   136     watchRegisterSubmit(),
   110     watchRegisterRequest(context),
   137     watchRegisterRequest(context),
   111     watchStoreToken(),
   138     watchStoreToken(),
   112     watchUpdateSettings(context),
   139     watchUpdateSettings(context),
       
   140     watchResetSubmit(),
       
   141     watchResetRequest(context),
   113   ])
   142   ])
   114 }
   143 }