Exemplo n.º 1
0
    def testInsert(self):
        st = time.time()
        u = User(login='******', password='******')
        u.save()
        print(time.time() - st)

        assert True
    def handle(self, *args, **options):
        if User.objects.exists() or Posting.objects.exists() or RidePosting.objects.exists() \
        or ItemPosting.objects.exists() or Comment.objects.exists():
            print('Data already loaded...exiting.')
            return
        print("Proceeding to add data")

        print("Adding user data")
        for row in DictReader(open('./test_user_data_01.csv')):
            user = User()
            user.name = row['Name']
            user.email = row['Email']
            user.role = row['role']
            user.save()
Exemplo n.º 3
0
def check_user_exist(user, createNew=False):
    """Check if a user exists. If the user doesn't exist, create a new one"""
    user_query_result = User.objects.filter(user_id=user.id)

    if not user_query_result.exists():
        if not createNew:
            return False
        user_settings = UserSettings()
        user_settings.save()
        result_user = User(user_id=user.id, username=user.username, settings=user_settings)
        result_user.save()
    else:
        result_user = user_query_result.first()
    return result_user
Exemplo n.º 4
0
class LoginTest(TestCase):
    def setUp(self):
        self.user = User(login='******', password='******')
        self.user.save()

    def testExists(self):
        self.assertEqual(User.objects.get(login='******', password='******'),
                         self.user)
        self.assertFalse(
            User.objects.filter(login='******', password='******').exists(),
            False)

    def testInsert(self):
        st = time.time()
        u = User(login='******', password='******')
        u.save()
        print(time.time() - st)

        assert True
Exemplo n.º 5
0
    def post(self, request, **kwargs):
        fname = request.POST.get('fname').strip()
        lname = request.POST.get('lname').strip()
        gender = request.POST.get('gender')
        login = request.POST.get('login').strip()
        email = request.POST.get('email').strip()
        phone = request.POST.get('phone').strip()
        password = request.POST.get('password').strip()
        rpassword = request.POST.get('rep-password').strip()

        try:
            photo = request.FILES['photo']
        except:
            if gender is None or gender == 'm':
                photo = '/main_app/img/male.jpg'
            else:
                photo = '/main_app/img/female.png'

        if User.objects.filter(login=login).first() is not None:
            return render(request, "main_app/registration.html",
                          {'error': 'Login is not unique'})

        if password != rpassword:
            return render(request, "main_app/registration.html",
                          {'error': 'Passwords should match'})

        u = User(fname=fname,
                 lname=lname,
                 gender=gender,
                 login=login,
                 email=email,
                 phone=phone,
                 password=password,
                 photo=photo)
        u.save()
        request.session['user'] = u.pk

        user_details = UserLearningDetail(user=u)
        user_details.save()

        return redirect('/first_test')
Exemplo n.º 6
0
def add_account(request):
    form = AddAccountForm(request.POST,
                          req_user_dcode=request.user.Ins_ID.Dcode)
    context = {
        'form': form,
    }
    if form.is_valid():
        if re.match(r'[A-Za-z0-9]{8,}', form.cleaned_data['password']):
            user = User(
                Ins_ID=form.cleaned_data['instructor'],
                password=make_password(form.cleaned_data['password']),
            )
            user.save()
            user = User.objects.get(
                Ins_ID=form.cleaned_data['instructor'])  # Email
            #         message = """
            # Dear: {}
            # An account has been created for you.
            # password: {}

            # Examination Control Committee""".format(
            #             form.cleaned_data['instructor'], form.cleaned_data['password'])
            #         mail_thread = Thread(target=send_mail, args=(message, [user.Ins_ID.Email]))
            #         mail_thread.start()
            # sms_thread = Thread(target=send_sms, args=(message,))
            # sms_thread.start()
            messages.success(
                request,
                'Successfully created account: {}'.format(user.Ins_ID))
            return HttpResponseRedirect('/hod/ManageAccounts')
        else:
            messages.error(
                request,
                'Password should be a combination of Alphabets and Numbers and more than 8 characters'
            )
            return HttpResponseRedirect('/hod/ManageAccounts')

    return render(request, 'hod/cud/AddAccount.html', context)
Exemplo n.º 7
0
    def setUp(self):
        u = User(login='******', password='******')
        u.save()

        self.wd = WebDriver()