def register(self): name = request.POST.get('name') email = request.POST.get('email') location_id = request.POST.get('location_id') accept_terms = request.POST.get('accept_terms') person = request.POST.get('person') c.universities = self._universities(limit=12) c.all_universities = self._universities() # checks if email, name, person are not empty if not email or not name or not person or accept_terms != '1': redirect(url('frontpage')) # redirect to login if user is already registered if User.get_all(email): redirect(url(controller='home', action='login', email=email)) # otherwise we validate the form properly try: self.form_result = RegistrationForm().to_python(request.POST) except validators.Invalid, e: return htmlfill.render(self._sign_up_form(), defaults=request.POST, errors=e.error_dict, error_formatters=u_error_formatters)
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)