I'm using web3, truffle and testrpc.
In my smart contract, some of the functions can only be called by the owner (or creator) of the contract (i.e. onlyOwner functions). So, I've defined some modifier for that. Also, in the smart contract, I have defined a variable called owner that can be called by anyone to see who the owner is.
I'm designing a UI. I'd like to alert the users, in UI, if they call the onlyOwner functions (e.g. you're not the owner). In my .js file I can call owner.call(); to get the owner address. But I don't know how to get the users address to compare it with the owner address.
Question: How can I get the user's address via web3?
Also, when we switch the default account (i.e. the first account) in MetaMask to 2nd, 3rd, .. account, how the .js file can recognize it and use that account as the default one?

web3.eth.accounts[0]is giving meundefinedinstead of the address of the account – Zeeshan Ahmad Khalil Aug 05 '19 at 09:45web3.eth.getAccounts()is giving the addresses of all the accounts – Zeeshan Ahmad Khalil Aug 05 '19 at 09:53web3.eth.getAccounts()now gives me "Method not found" error... – Jim Aug 29 '21 at 06:17web3^1.0.0-beta.55. The current version isweb3^1.5.2. Check your web 3.0 version inpackage.json, see their documentation and find the function against your own version to get all the accounts. – Zeeshan Ahmad Khalil Aug 29 '21 at 11:12