Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. @csrf_exempt
  2. @api_view(["POST"])
  3. @permission_classes((AllowAny,))
  4. def register(request,):
  5. password = request.data.get("password", "")
  6. email = request.data.get("email", "")
  7. if not email and not password and not email:
  8. return Response(
  9. data={
  10. "message": "username, password and email is required to register a user"
  11. },
  12. status=status.HTTP_400_BAD_REQUEST
  13. )
  14. new_user = User.objects.create_user(
  15. email=email, password=password
  16. )
  17. return Response(status=status.HTTP_201_CREATED)
  18.  
  19. createUser(event) {
  20. event.preventDefault();
  21.  
  22. let data = {
  23. name: this.state.name,
  24. password: this.state.password,
  25. repeatPassword: this.state.repeatPassword,
  26. email: this.state.email
  27. };
  28.  
  29. if (this.state.name !== '' && this.state.password !== '' && this.state.email !== '' && this.checkPasswords()) {
  30. console.log('name', this.state.name, 'password ', this.state.password, 'email ', this.state.email);
  31. fetch("https://kollektivet.app:8082/api/register/", {
  32. method: 'POST',
  33. headers: {
  34. 'Accept': 'application/json',
  35. 'Content-Type': 'application/json',
  36. },
  37. mode: "cors",
  38. body: JSON.stringify(data)
  39. })
  40. .then(response => response.json())
  41. .then(data => console.log(data))
  42. .catch(error => console.log(error));
  43. this.setState({message: "Du er nå registrert! For å aktivere din konto trykk på linken som vi har sendt til deg på epost"});
  44. this.setState({name: ""});
  45. this.setState({password: ""});
  46. this.setState({repeatPassword: ""});
  47. this.setState({email: ""});
  48.  
  49. }
  50. }
  51.  
  52. CORS_ORIGIN_ALLOW_ALL = True
  53. CORS_ALLOW_HEADERS = (
  54. 'accept',
  55. 'accept-encoding',
  56. 'authorization',
  57. 'content-type',
  58. 'dnt',
  59. 'origin',
  60. 'user-agent',
  61. 'x-csrftoken',
  62. 'x-requested-with',
  63. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement