Esempio n. 1
0
def signUpPage(request):
    group = Group.objects.get(name='Customer')
    if request.method == 'POST':
        first_name = request.POST['fname']
        last_name = request.POST['lname']
        username = request.POST['username']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        email = request.POST['email']

        if password1 == password2:
            if User.objects.filter(username=username).exists():
                messages.info(request, 'Username Taken')
                return redirect('signup')
            elif User.objects.filter(email=email).exists():
                messages.info(request, 'Email Taken')
                return redirect('signup')
            else:
                user = User.objects.create_user(
                    username=username, password=password1, email=email, first_name=first_name, last_name=last_name)
                user.groups.add(group)
                user.is_active = False
                send_email(user)
                user.save()

                return redirect('signin')

        else:
            messages.info(request, 'password not matching..')
            return redirect('signup')
        return redirect('/')

    else:
        return render(request, 'signup.html')
Esempio n. 2
0
File: forms.py Progetto: ramy655/MSM
 def save(self):
     user = super().save(commit=False)
     user.type = 'DOCTOR'
     user.is_active = False
     user.save()
     send_email(user)
     return user
Esempio n. 3
0
def registration_view(request):
    context = {}
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            username = form.cleaned_data.get('username')
            raw_password = request.POST['password1']
            user = get_user_model().objects.create(
                username=username,
                password=make_password(raw_password),
                email=email)
            raw_password = form.cleaned_data.get('password1')
            account = authenticate(email=email, password=raw_password)
            user.is_active = False  # Example
            send_email(user)
            login(request, account)
            messages.info(
                request,
                ' We have sent a confirmation mail to your e-mail account. You are just one-step away from our registration process.'
            )
            # messages.info(request, 'You are just one-step away from our registration process.')
            return redirect('blog_list')
        else:
            context['registration_form'] = form
    else:
        form = RegistrationForm()
        context['registration_form'] = form
    return render(request, 'accounts/register.html', context)
Esempio n. 4
0
    def post(self, request, *args, **kwargs):
        email = request.data.get('email')
        password = request.data.get('password')
        print('creating account for')
        print(email)
        print(password)

        try:
            user = User.objects.create_user(email=email, password=password)
            user.is_active = False
            password = User.objects.make_random_password()
            user.set_password(password)
            user.set_customer_group()
            send_email(user)

            data = {
                'status': 201,
                'message': 'User created',
                'data': {
                    'id': user.id,
                    'user_type': 'customer',
                },
            }

            return Response(data=data, status=201)
        except IntegrityError:
            return Response(data={
                'status': 400,
                'detail': 'User with this email already exists',
                'data': {},
            },
                            status=400)
Esempio n. 5
0
def sendEmail(request):
	
	email = '*****@*****.**'
	password = "******"
	phone = 92929291111 
	user = get_user_model().objects.create(email=email,password=password,phone=phone)
	send_email(user)
	return render(request, 'confim_template.html')
Esempio n. 6
0
 def post(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     if not serializer.is_valid():
         return Response(serializer.errors,
                         status=status.HTTP_422_UNPROCESSABLE_ENTITY)
     user = serializer.save()
     send_email(user)
     return Response({"success": True}, status=status.HTTP_201_CREATED)
Esempio n. 7
0
 def form_valid(self, form, user=None):
     super().form_valid(form)
     if user is None:
         user = form.save()
     user.is_active = False
     user.save()
     send_email(user)
     return redirect('password_reset_done')
    def create(self, validated_data):
        user = User.objects.create(**validated_data)
        user.is_active = False
        password = User.objects.make_random_password()
        user.set_password(password)

        if 'customer' in self.context['request'].path:
            user.set_customer_group()
        else:
            user.set_staff_group()

        user.save()
        send_email(user)

        return user
Esempio n. 9
0
 def post(self, request, format=None):
     serializer = UserSerializerWithToken(data=request.data)
     if serializer.is_valid():
         user = serializer.save()
         user = get_user_model().objects.get(
             username=serializer.data['username'])
         user.is_active = False
         send_email(user)
         send_mail_core(
             'Subject here',
             'Here is the message.',
             '*****@*****.**',
             ['*****@*****.**'],
             fail_silently=True,
         )
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 10
0
    def put(self, request):
        try:
            change_email_serializer = ChangeEmailSerializer(request.user,
                                                            data=request.data)
            if not change_email_serializer.is_valid():
                return Response(change_email_serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)
            user = change_email_serializer.save()
        except Exception as error:
            response = {
                "success": False,
                "message": str(error),
            }
            return Response(response, status=status.HTTP_400_BAD_REQUEST)

        # Send Verification Email
        send_email(user)
        return Response(UserSerializer(user).data, status=status.HTTP_200_OK)
Esempio n. 11
0
    def save(self, commit=True):
        user = super().save(commit=commit)

        if commit and settings.EMAIL_ENABLED:
            user.is_active = False
            send_email(user)

        if commit and settings.MULTI_ORGANIZATIONS:
            from purplship.server.orgs.models import Organization

            org_name = user.full_name.split(" ")[0]
            org = Organization.objects.create(
                name=f"{org_name.capitalize()}'s Org",
                slug=f"{org_name.lower()}_org".replace(" ", "").lower(),
                is_active=not settings.EMAIL_ENABLED,
            )
            # Set as organization user
            owner = org.add_user(user, is_admin=True)
            # Set as organization owner
            org.change_owner(owner)
            org.save()

        return user
Esempio n. 12
0
	def done(self, form_list, **kwargs):

		form_lst = list(form_list)

		all_valid = reduce(lambda a,b: a.is_valid() and b.is_valid(),list(form_list))

		if all_valid:

			user_form = form_lst[0]
			profile_form = form_lst[1]

			user = user_form.save()

			user.profile.weight = form_lst[1].cleaned_data.get('weight')
			user.profile.gender = form_lst[1].cleaned_data.get('gender')
			user.profile.age = form_lst[1].cleaned_data.get('age')
			user.profile.activity_level = form_lst[1].cleaned_data.get('activity_level')
			user.profile.goal = form_lst[1].cleaned_data.get('goal')
			user.profile.preferred_units = form_lst[1].cleaned_data.get('preferred_units')
			user.profile.height = form_lst[1].cleaned_data.get('height')
			user.profile.height_feet_seg = form_lst[1].cleaned_data.get('height_feet_seg')

			if not form_lst[1].cleaned_data.get('height_inches_seg') :
				user.profile.height_inches_seg = 0
			else:
				user.profile.height_inches_seg = form_lst[1].cleaned_data.get('height_inches_seg')
			
			user.profile.preferred_height_units = form_lst[1].cleaned_data.get('preferred_height_units')
			user.profile.save()

			messages.success(self.request, f'Verification email sent to {user.email}!')

			user.is_active = False
			send_email(user)


		return redirect('verifyemail')
Esempio n. 13
0
    def save(self, commit=True):
        user = super().save(commit)
        if commit and settings.EMAIL_ENABLED:
            send_email(user)

        return user
Esempio n. 14
0
 def form_valid(self, form):
     user = form.save()
     returnVal = super(UserCreationView, self).form_valid(form)
     send_email(user)
     return returnVal