Ugly but working register/login-logout process using cookies+token