def put(request, form): email = form.get('email') password = form.get('password') if not all((email, password)): # Client-side error. Should not be possible by proper calls. raise Json404({'success': False, 'errors': ['Please fill all fields.']}) try: user = User.objects.get(email=email, password=get_hash(password)) except User.DoesNotExist: raise Json404() #! Should the response be more specific? print("Yes, been here") _setup_session(request.session, user) return { 'success': True, 'redirect': '/lists?welcome=1' }
def post(request, form): name = form.get('first_name') email = form.get('email') password = form.get('password') print form if not all((name, email, password)): # Client-side error. Should not be possible by proper calls. raise Json404({'success': False, 'errors': ['Please fill all fields.']}) form = UserForm(form) if not form.is_valid(): return {'success': False, 'errors': sum(form.errors.values(),[])} if User.objects.filter(email=email): return {'success': False, 'errors': ['This email is already registered.']} user = User.objects.create( first_name=name, email=email, password=get_hash(password)) _setup_session(request.session, user) return {'success': True, 'redirect': '/lists?welcome=0'}