def _try_sign_in(self, username, password, location=None, remember=False): # user may have registered in several Ututi # networks using same username locations = [user.location for user in User.get_all(username)] if len(locations) == 0: return {'username': _('Incorrect username.')} if len(locations) > 1: # if there is more than one location, # we will want to show it in the form c.locations = [(loc.id, loc.title) for loc in locations] c.selected_location = location if location is None and len(locations) == 1: location = locations[0].id if location is None: # still none! that means that location is not # unique and user did not specify it. return {'location': _('Please select your network.')} user = User.authenticate(location, username, password) if user is None: return {'password': _('Incorrect password.')} sign_in_user(user, long_session=remember)