To login by ajax request

In WordPress/WooCommerce application I need to make that if some user is not logged by clicking
on link to open popup dialog and login in it. Are there some examples/pluging to make it :
on successfull login redirect to homepage on failure to show error to prepose to login again.

I would prefer code sample as I need to implement it in my own popup dialog.