Init password reset after registration

This commit is contained in:
Christian Cueni 2019-10-23 12:53:24 +02:00
parent 836cd63cfd
commit 148b2cae3d
4 changed files with 19 additions and 7 deletions

View File

@ -129,7 +129,7 @@ export default {
let that = this; let that = this;
if (result) { if (result) {
this.$apollo.mutate({ this.$apollo.mutate({
// client: 'publicClient', client: 'publicClient',
mutation: REGISTRATION_MUTATION, mutation: REGISTRATION_MUTATION,
variables: { variables: {
input: { input: {
@ -149,8 +149,7 @@ export default {
) { ) {
try { try {
if (success) { if (success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' that.$router.push('/set-password/done/');
that.$router.push(redirectUrl);
} else { } else {
errors.forEach(function(error) { errors.forEach(function(error) {
switch (error.field) { switch (error.field) {

View File

@ -3,9 +3,10 @@ from django.conf import settings
from graphene_django.debug import DjangoDebug from graphene_django.debug import DjangoDebug
from users.mutations_public import UserMutations from users.mutations_public import UserMutations
from registration.mutations_public import RegistrationMutations
class Mutation(UserMutations, graphene.ObjectType): class Mutation(UserMutations, RegistrationMutations, graphene.ObjectType):
if settings.DEBUG: if settings.DEBUG:
debug = graphene.Field(DjangoDebug, name='__debug') debug = graphene.Field(DjangoDebug, name='__debug')

View File

@ -115,6 +115,8 @@ input[type=text], input[type=password], input[type=email], select {
.reset__text { .reset__text {
margin-bottom: 52px; margin-bottom: 52px;
line-height: 1.5rem;
font-size: 1.125rem;
} }
.reset__form label { .reset__form label {

View File

@ -10,10 +10,11 @@
import graphene import graphene
from graphene import relay from graphene import relay
from core.views import SetPasswordView
from registration.models import License from registration.models import License
from registration.serializers import RegistrationSerializer from registration.serializers import RegistrationSerializer
from users.models import User, Role, UserRole, SchoolClass from users.models import User, Role, UserRole, SchoolClass
from users.mutations import UpdateError, FieldError from users.mutations_public import MutationError, FieldError
class Registration(relay.ClientIDMutation): class Registration(relay.ClientIDMutation):
@ -24,7 +25,7 @@ class Registration(relay.ClientIDMutation):
license_key_input = graphene.String() license_key_input = graphene.String()
success = graphene.Boolean() success = graphene.Boolean()
errors = graphene.List(UpdateError) # todo: change for consistency errors = graphene.List(MutationError) # todo: change for consistency
@classmethod @classmethod
def mutate_and_get_payload(cls, root, info, **kwargs): def mutate_and_get_payload(cls, root, info, **kwargs):
@ -57,11 +58,20 @@ class Registration(relay.ClientIDMutation):
student_role = Role.objects.get(key=Role.objects.STUDENT_KEY) student_role = Role.objects.get(key=Role.objects.STUDENT_KEY)
UserRole.objects.get_or_create(user=user, role=student_role) UserRole.objects.get_or_create(user=user, role=student_role)
password_reset_view = SetPasswordView()
password_reset_view.request = info.context
form = password_reset_view.form_class({'email': user.email})
if not form.is_valid():
return cls(success=False, errors=form.errors)
password_reset_view.form_valid(form)
return cls(success=True) return cls(success=True)
errors = [] errors = []
for key, value in serializer.errors.items(): for key, value in serializer.errors.items():
error = UpdateError(field=key, errors=[]) error = MutationError(field=key, errors=[])
for field_error in serializer.errors[key]: for field_error in serializer.errors[key]:
error.errors.append(FieldError(code=field_error.code)) error.errors.append(FieldError(code=field_error.code))