def register(request):
    """Renders the register page."""
    try:
        assert isinstance(request, HttpRequest)
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if (form.is_valid()):
                firstname = form['firstname'].value()
                lastname = form['lastname'].value()
                email = form['email'].value()
                address = form['address'].value()
                password = sha256_crypt.encrypt(form['password'].value())
                user_auth = User.objects.create_user(username=email,
                                                     first_name=firstname,
                                                     last_name=lastname,
                                                     email=email,
                                                     password=password)
                user = UserDetails(email, address, password)
                user_auth.save()
                user.save()
                return render(request, 'app/login.html')
        else:
            form = RegisterForm()
        return render(request, 'app/register.html', {'form': form})
    except:
        return render(request, 'app/index.html')
Exemple #2
0
def registerUser(request):
    username = request.POST.get('un')
    email = request.POST.get('email')
    password = request.POST.get('password')
    fn = request.POST.get('fn')
    ln = request.POST.get('ln')
    ph = request.POST.get('ph')
    user = User.objects.create_user(username, email, password)
    user.last_name = ln
    user.first_name = fn
    user.save()
    usrphone = UserDetails(user=user, Phone=ph)
    usrphone.save()
    global message
    message = "User Registration Successfull"
    return redirect('registrationPage')
Exemple #3
0
def signup(request):
    if request.user.is_authenticated:
        return redirect("old-user")
    data = {}
    if request.method == 'POST':
        email = request.POST.get('email')
        password = request.POST.get('password')
        try:
            User.objects.get(email=email)
            #messages.info(request, 'This email is already registered')
            data = {
                'status': 'error',
                'msg': 'This email is already registered'
            }
            return JsonResponse(data)
        except ObjectDoesNotExist:

            uname = email.replace('@', '_')
            user = User(username=uname, email=email)
            user.set_password(password)
            user.save()
            staff = User.objects.filter(groups__name='Students Help')
            room = create_room(staff)
            room.members.add(user)
            room.save()
            user_detail = UserDetails(user=user, user_type="Student")
            user_detail.save()
            if request.session.get('session_key'):
                username = request.session['session_key']
                unknown_user = User.objects.get(username=username)
                try:
                    laborder = LabOrders.objects.get(user=unknown_user)
                    laborder.user = user
                    laborder.save()
                    c = {
                        'user': user.username,
                        'order_id': laborder.order_id,
                        'subject': laborder.subject,
                        'deadline': laborder.deadline
                    }
                    order_id = laborder.order_id
                    email_msg = render_to_string('order.txt', c)
                    mail = EmailMessage(
                        subject=f'Order Created - {order_id}',
                        body=email_msg,
                        from_email=
                        'TutorChamps Student Support <*****@*****.**>',
                        to=[email, '*****@*****.**'])
                    mail.send()
                except:
                    order = Orders.objects.get(user=unknown_user)
                    order.user = user
                    order.save()
                    c = {
                        'user': user.username,
                        'order_id': order.order_id,
                        'subject': order.subject,
                        'deadline': order.deadline
                    }
                    order_id = order.order_id
                    print(order.deadline)
                    email_msg = render_to_string('order.txt', c)
                    mail = EmailMessage(
                        subject=f'Order Created - {order_id}',
                        body=email_msg,
                        from_email=
                        'TutorChamps Student Support <*****@*****.**>',
                        to=[email, '*****@*****.**'])
                    mail.send()
                finally:
                    unknown_user.delete()
                    del request.session['session_key']
                    #messages.success(request, 'you have registered successfully')
                    usr = authenticate(username=uname, password=password)
                    login(request, usr)
                    data = {'status': 'ok', 'msg': 'User created successfully'}
                    print("Order successful, order id : {}".format(
                        order.order_id))
                    send_message(
                        request,
                        "Order successful, order id : {}".format(order_id))
                    data['order'] = "YES"
                    #return redirect('new-user-ordered', order="order-successful")
                    return JsonResponse(data)
            else:
                #messages.success(request, 'you have registered successfully')
                usr = authenticate(username=uname, password=password)
                login(request, usr)
                data = {'status': 'ok', 'msg': 'User created successfully'}
                c = {'user': user.username}
                email_msg = render_to_string('signup.txt', c)
                mail = EmailMessage(
                    subject='Welcome to TutorChamps',
                    body=email_msg,
                    from_email=
                    'TutorChamps Student Support <*****@*****.**>',
                    to=[email])
                mail.send()
                return JsonResponse(data)
            print(usr)

    print("here2")
    return render(request, 'signup.html', data)