def put(self, request, id_): """ Updates user data """ json_data = get_json_data(request) user = User.get_by_id(id_) if not user: JsonResponseNotFound() if user.can_edit(request.user): user.from_dict(json_data) if not user.is_valid(ignore=['password']): return JsonResponseError(user.errors) user.save() return JsonResponse({}) else: return JsonResponseError({ 'all': _('You do not have permission to perform this operation') })
def post(self, request): """ Resposible for handle the LoginForm from LoginView (authentication/views.coffee) """ json_data = get_json_data(request) email, password = [json_data.get(data, '') for data in ['email', 'password']] email = email.lower() login = Login() login.from_dict({'email': email, 'password': password}) if not login.is_valid(): return JsonResponseError(login.errors, status_code=401) else: user = login.user auth_login(request, user) next_page = json_data.get('next', '') or reverse('root') if next_page.endswith('#'): next_page = next_page[:-1] return JsonResponse({'redirect': next_page})
def post(self, request): """ Handles the RegisterForm from LoginView (authentication/views.coffee) Responsible for creating a new User account. """ json_data = get_json_data(request) json_data['email'] = json_data.get('email', '').lower() user = User() user.from_dict(json_data) # user model validations form_validates = user.is_valid() form_validates = _user_form_specific_validations( user, json_data, form_validates) if not form_validates: return JsonResponseError(user.errors) else: user.is_active = False user.set_password(json_data.get('password')) user.save() user.send_confirmation_mail(request) return JsonResponse()