Skip to content

Instantly share code, notes, and snippets.

@kmmraj
Created January 23, 2018 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmmraj/0388dd38054a3aa99e97927658e3c13d to your computer and use it in GitHub Desktop.
Save kmmraj/0388dd38054a3aa99e97927658e3c13d to your computer and use it in GitHub Desktop.
fun executeGitHubLogin(action: LoginAction, dispatch: DispatchFunction) {
val loginTaskListenerMiddleware = LoginTaskListenerMiddleware()
val authTask = UserLoginTask(loginTaskListenerMiddleware,
action.userName,
action.password )
authTask.execute()
dispatch(LoginStartedAction(action.userName))
}
interface LoginTaskListenerInterface {
fun onFinished(result: LoginCompletedAction,store: Store<StateType>)
}
class LoginTaskListenerMiddleware : LoginTaskListenerInterface {
override fun onFinished(result: LoginCompletedAction, store: Store<StateType>) {
if (result.loginStatus == LoggedInState.loggedIn ) {
result.token?.let {
// Login succeed, do the next work
}
} else {
result.message?.let{
// Login failed, show an error message
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment