Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
def Food_Preference_Form():
    if request.method == 'POST':

        foodchoice = request.form.get('foodchoice')
        spiciness = request.form.get('spiciness')
        location = request.form.get('location')
        cuisines = request.form.getlist('cuisine')
        allergies = request.form.getlist('allergy')

        cuisines_str = ""
        for cuisine in cuisines:
            cuisines_str = cuisines_str + cuisine + ","

        if len(allergies) == 1:
            allergies_str = allergies[0]
        else:
            allergies_str = ""
            for allergy in allergies:
                allergies_str = allergies_str + allergy + ","

        Num_Users = int(
            max(Credentials.query.with_entities(Credentials.user_id))[0])
        UserDetail = UserDetails(user_id=Num_Users + 1,
                                 fav_cuisine=cuisines_str,
                                 spiciness=spiciness,
                                 food_choice=foodchoice,
                                 state=location,
                                 allergy=allergies_str)

        db.session.add(UserDetail)
        db.session.commit()

    return render_template('Login.html')
Ejemplo n.º 3
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')
Ejemplo n.º 4
0
    def store_user_details(self, data):
        try:
            user_details = UserDetails()
            user_details.id_number = data['id_number']

            user_details.first_name = data['first_name']
            user_details.last_name = data['last_name']
            user_details.mobile = data['mobile']
            user_details.image = data['image_url']
            user_details.gender = data['gender']
            session.add(user_details)
            session.flush()
            session.commit()

        except Exception as e:
            session.rollback()
            print(e)
            raise e
def user_signup_func():
    email = request.json.get('email')
    user = UserDetails.query.filter_by(email=email).first()
    if not user:
        password = request.json.get('password')
        hashed_password = generate_password_hash(password, method='sha256')
        full_name = request.json.get('full_name')
        phone = request.json.get('phone')
        upi_id = request.json.get('upi_id')

        detail = UserDetails(full_name=full_name,
                             email=email,
                             password=hashed_password,
                             phone=phone,
                             upi_id=upi_id)
        print(detail)
        try:
            db.session.add(detail)
            db.session.commit()
        except Exception as e:
            return str(e), 400
        return 'User Registered Successfully', 200
    else:
        return "Already Registered"
Ejemplo n.º 6
0
def tutor_register(request):
    if request.method == 'POST':
        name = request.POST.get('name')
        email = request.POST.get('email')
        email = email.lower()
        qualification_level = request.POST.get('level')
        subject = request.POST.get('subject')
        user = User.objects.get_or_create(username=email)
        password = config('tutorspassword')
        b = user[1]
        user = user[0]
        if b == True:
            user.email = email
            user.first_name = name
            user.save()
            UserDetails(user=user, user_type="Tutor").save()
            user.set_password(password)
            user.is_active = False
            user.save()
            hard = Questions.objects.filter(subject=subject)
            hard = random.choice(hard)
            tutor = TutorRegister(name=name,
                                  qualification_level=qualification_level,
                                  subject=subject,
                                  tutor=user)
            tutor.save()
            id = tutor.pk
            id += 3000
            subject = subject.upper()
            tutor.unique_id = f'{subject[0:3]}-{id}'
            tutor.save()
            c = {'user': name}
            email_msg = render_to_string('tutor_email.txt', c)
            connection = mail.get_connection(
                backend='django.core.mail.backends.smtp.EmailBackend',
                host='smtp.gmail.com',
                name="TutorChamps",
                use_tls=True,
                port=587,
                username='******',
                password=config('tutorPassword'))
            connection.open()
            email = EmailMessage(
                subject='Welcome to TutorChamps || Complete the test',
                body=email_msg,
                from_email=
                'TutorChamps Tutors Support <*****@*****.**>',
                to=[email])
            hard = hard.question
            email.attach(hard.name, hard.read())
            connection.send_messages([email])
            connection.close()
            x = TutorBalance(tutor=tutor, balance=0)
            x.save()
            account = TutorAccount(tutor=tutor)
            account.save()
            return redirect(f'/thank-you/{id}/')
        else:
            messages.warning(request, 'already registered')
            return redirect('registration')
    return render(request, 'register.html')
Ejemplo n.º 7
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)