Fix some bugs in login procedure and implement check for user status