Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @csrf_exempt
- @api_view(["POST"])
- @permission_classes((AllowAny,))
- def register(request,):
- password = request.data.get("password", "")
- email = request.data.get("email", "")
- if not email and not password and not email:
- return Response(
- data={
- "message": "username, password and email is required to register a user"
- },
- status=status.HTTP_400_BAD_REQUEST
- )
- new_user = User.objects.create_user(
- email=email, password=password
- )
- return Response(status=status.HTTP_201_CREATED)
- createUser(event) {
- event.preventDefault();
- let data = {
- name: this.state.name,
- password: this.state.password,
- repeatPassword: this.state.repeatPassword,
- email: this.state.email
- };
- if (this.state.name !== '' && this.state.password !== '' && this.state.email !== '' && this.checkPasswords()) {
- console.log('name', this.state.name, 'password ', this.state.password, 'email ', this.state.email);
- fetch("https://kollektivet.app:8082/api/register/", {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- mode: "cors",
- body: JSON.stringify(data)
- })
- .then(response => response.json())
- .then(data => console.log(data))
- .catch(error => console.log(error));
- this.setState({message: "Du er nå registrert! For å aktivere din konto trykk på linken som vi har sendt til deg på epost"});
- this.setState({name: ""});
- this.setState({password: ""});
- this.setState({repeatPassword: ""});
- this.setState({email: ""});
- }
- }
- CORS_ORIGIN_ALLOW_ALL = True
- CORS_ALLOW_HEADERS = (
- 'accept',
- 'accept-encoding',
- 'authorization',
- 'content-type',
- 'dnt',
- 'origin',
- 'user-agent',
- 'x-csrftoken',
- 'x-requested-with',
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement