Working on login process

This commit is contained in:
unknown 2018-05-23 07:13:43 -07:00
parent 594010d0ee
commit ed1ec0f4f7
5 changed files with 15 additions and 6 deletions

View File

@ -22,7 +22,9 @@ class AuthRepositoryFlutter {
/// error, it attempts to load the Products from a Web Client. /// error, it attempts to load the Products from a Web Client.
Future<List<dynamic>> login(String email, String password, String url) async { Future<List<dynamic>> login(String email, String password, String url) async {
final data = await webClient.postList(url + '/login?api_secret=secret', '', { final data = await webClient.postList(url + '/login', '', {
'api_secret': 'secret',
'token_name': 'mobile-app',
'email': email, 'email': email,
'password': password, 'password': password,
}); });

View File

@ -19,7 +19,9 @@ class DashboardRepositoryFlutter {
}); });
Future<dynamic> loadItem(CompanyEntity company, AuthState auth) async { Future<dynamic> loadItem(CompanyEntity company, AuthState auth) async {
print('== Load item ==');
print('url: ' + auth.url + '/dashboard');
print('token: ' + company.token);
final data = await webClient.fetchItem( final data = await webClient.fetchItem(
auth.url + '/dashboard', company.token); auth.url + '/dashboard', company.token);

View File

@ -49,8 +49,6 @@ Middleware<AppState> _createLoginRequest(AuthRepositoryFlutter repository) {
} }
store.dispatch(SelectCompany(1)); store.dispatch(SelectCompany(1));
store.dispatch(UserLoginSuccess());
store.dispatch(UserLoginSuccess()); store.dispatch(UserLoginSuccess());
store.dispatch(LoadDashboardAction()); store.dispatch(LoadDashboardAction());

View File

@ -20,6 +20,7 @@ AuthState userLoginRequestReducer(AuthState auth, UserLoginRequest action) {
AuthState userLoginSuccessReducer(AuthState auth, UserLoginSuccess action) { AuthState userLoginSuccessReducer(AuthState auth, UserLoginSuccess action) {
return AuthState().copyWith( return AuthState().copyWith(
url: auth.url,
isAuthenticated: true, isAuthenticated: true,
isAuthenticating: false, isAuthenticating: false,
); );
@ -27,6 +28,7 @@ AuthState userLoginSuccessReducer(AuthState auth, UserLoginSuccess action) {
AuthState userLoginFailureReducer(AuthState auth, UserLoginFailure action) { AuthState userLoginFailureReducer(AuthState auth, UserLoginFailure action) {
return AuthState().copyWith( return AuthState().copyWith(
url: auth.url,
isAuthenticated: false, isAuthenticated: false,
isAuthenticating: false, isAuthenticating: false,
error: action.error error: action.error
@ -34,5 +36,7 @@ AuthState userLoginFailureReducer(AuthState auth, UserLoginFailure action) {
} }
AuthState userLogoutReducer(AuthState auth, UserLogout action) { AuthState userLogoutReducer(AuthState auth, UserLogout action) {
return AuthState(); return AuthState().copyWith(
url: auth.url,
);
} }

View File

@ -24,8 +24,11 @@ List<Middleware<AppState>> createStoreDashboardMiddleware([
Middleware<AppState> _createLoadDashboard(DashboardRepositoryFlutter repository) { Middleware<AppState> _createLoadDashboard(DashboardRepositoryFlutter repository) {
return (Store<AppState> store, action, NextDispatcher next) { return (Store<AppState> store, action, NextDispatcher next) {
print('== LOAD DASHBOARD ==');
print(store.state.selectedCompany());
print(store.state.auth);
repository.loadItem(store.state.selectedCompanyState().company, store.state.auth).then( repository.loadItem(store.state.selectedCompany(), store.state.auth).then(
(data) => store.dispatch(DashboardLoadedAction(data)) (data) => store.dispatch(DashboardLoadedAction(data))
).catchError((error) => store.dispatch(DashboardNotLoadedAction(error))); ).catchError((error) => store.dispatch(DashboardNotLoadedAction(error)));