Exemplo n.º 1
0
 def post(self, request, format=None):
     serializer = RegisterSerializer(data=request.data)
     if serializer.is_valid():
         try:
             user = AppUser.objects.get(email=serializer.data['email'])
             admin_user = User.objects.get(email=serializer.data['email'])
             return Response({"status": "user exist"},status=status.HTTP_400_BAD_REQUEST)
         except ObjectDoesNotExist:
             username = ""
             num = random.randint(4, 10)
             while True:
                 username = ""
                 for i in range(num):
                     username += random.choice(seed)
                 try:
                     user = AppUser.objects.get(username=username)
                 except AppUser.DoesNotExist:
                     break
             password = serializer.data['password']
             email = serializer.data['email']
             admin_user = User.objects.create_user(username=username, password=password,
                                                   last_login=datetime.datetime.now(), email=email)
             admin_user.save()
             user = AppUser()
             user.username = username
             user.password = password
             user.user = admin_user
             user.email = email
             user.save()
             return Response(status=status.HTTP_201_CREATED)
     return Response({"status": "format error"}, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
def reg(request):
    res = UserReg()
    if request.method == 'POST':
        res = UserReg(request.POST)
        if res.is_valid():
            code = request.POST.get('msgcode')
            if code != request.session.get('smscode'):
                return render(request,
                              'register.html',
                              context={
                                  'user': res,
                                  'codeer': '验证码错误'
                              })
            else:
                request.session.flush()
                phone = request.POST.get('phone')
                email = request.POST.get('email')
                username = request.POST.get('user_name')
                password = request.POST.get('pwd')
                auser = AppUser()
                auser.u_username = username
                auser.u_password_has = hashlib.sha1(
                    password.encode('utf8')).hexdigest()
                auser.u_email = email
                auser.u_phone = phone
                auser.u_sex = True
                auser.u_register_time = datetime.datetime.now()
                auser.u_type = 0
                auser.u_credits = 50
                auser.save()
                return redirect(reverse('app:login'))
        return render(request, 'register.html', context={'user': res})
    return render(request, 'register.html', context={'user': res})
Exemplo n.º 3
0
    def test_questions_evaluated_correctly(self):
        s = self.client.session
        newUser = AppUser(100000, "*****@*****.**", "notapassword", "Applicant", False, "Firstname", "Lastname")
        newUser.save()
        s.update({
            "id": 100000,
        })
        s.save()
        data = dict()
        testML = MLModel(1, "TestModel")
        testML.save()
        testOrganisation = Organisation(1, "TestOrg", True, "*****@*****.**", "01234567890")
        testOrganisation.save()
        testJob = Job(1, 1, 1, "TestJob", "TestDesc", "2019-03-15")
        testJob.save()

        testCV = CV(1, 1, '{"Name": "Bill", "Degree Qualification": "Computer Science BSc", "Degree Level": "1st", "University Attended": "University of Warwick", "Skills": [{"Skill": "Server setup", "Expertise": 10}, {"Skill": "Database Management", "Expertise": 10}], "Languages Known": [{"Language": "Python", "Expertise": 10}, {"Language": "Java", "Expertise": 10}, {"Language": "C#", "Expertise": 10}], "Hobbies": [{"Name": "Gaming", "Interest": 10}], "A-Level Qualifications": [{"Subject": "Computer Science", "Grade": "A"}, {"Subject": "Chemistry", "Grade": "A"}], "Previous Employment": [{"Company": "Microsoft", "Position": "CEO", "Length of Employment": 120}]}')
        test_question_one = TestQuestions(1, "What is 5 + 3?", "8", 1)
        test_question_one.save()
        test_question_two = TestQuestions(2, "What is 9 + 5?", "14", 1)
        test_question_two.save()
        test_question_three = TestQuestions(3, "What is 12 + 4?", "16", 1)
        test_question_three.save()
        test_question_four = TestQuestions(4, "What is 15 + 16?", "31", 1)
        test_question_four.save()
        data['extra_questionfield_0'] = "8"
        data['extra_questionfield_1'] = "14"
        data['extra_questionfield_2'] = "16"
        data['extra_questionfield_3'] = "73"
        response = self.client.post('/applicant/test/1/', data)
        self.assertEqual(200, response.status_code)
        newApplication = Application.objects.get(id=1)
        self.assertEqual(75.0, newApplication.answer_percent)
Exemplo n.º 4
0
    def test_JSON_formatted_correctly(self):
        #This function tests that data from the CV form is correctly inserted into the database in a format
        #that will be accepted by the machine learning
        s = self.client.session
        newUser = AppUser(100000, "*****@*****.**", "notapassword", "Applicant", False, "Firstname", "Lastname")
        newUser.save()
        s.update({
            "id": 100000,
        })
        s.save()
        data = dict()
        data['extra_field_count'] = 10
        data['extra_language_count'] = 10
        data['extra_hobby_count'] = 10
        data['extra_qual_count'] = 10
        data['extra_job_count'] = 10
        data['name'] = "testname"
        data['degree'] = "testdegree"
        #data['degree_level'] = "1st"
        data['university'] = "testuniversity"
        for i in range(10):
            data['extra_charfield_' + str(i+1)] = "testchar"+str(i+1)
            data['extra_intfield_'+str(i+1)] = 10
            data['extra_charfield_lang_' +str(i+1)] = "testlang"+str(i+1)
            data['extra_intfield_lang_'+str(i+1)] = 10
            data['extra_charfield_hobby_'+str(i+1)] = "testhobby"+str(i+1)
            data['extra_intfield_hobby_'+str(i+1)] = 10
            data['extra_charfield_qual_'+str(i+1)] = "testqual"+str(i+1)
            data['extra_intfield_qual_'+str(i+1)] = 10
            data['extra_charfield_job_'+str(i+1)] = "testjob"+str(i+1)
            data['extra_intfield_job_'+str(i+1)] = "testpos"+str(i+1)
            data['extra_lenfield_job_'+str(i+1)] = 10

        response = self.client.post('/applicant/cv/', data)
        self.assertEqual(200, response.status_code)
        testCv = json.loads(CV.objects.get(pk=0).cvData)
        skill = testCv['Skills']
        language = testCv['Languages Known']
        hobbies = testCv['Hobbies']
        qualifications = testCv['A-Level Qualifications']
        jobs = testCv['Previous Employment']
        for i in range(10):
            self.assertEqual("testchar"+str(i+1), skill[i]["Skill"])
            self.assertEqual("testlang"+str(i+1), language[i]["Language"])
            self.assertEqual("testhobby"+str(i+1), hobbies[i]["Name"])
            self.assertEqual("testqual"+str(i+1), qualifications[i]["Qualification"])
            self.assertEqual("testjob"+str(i+1), jobs[i]["Company"])
Exemplo n.º 5
0
 def post(self, requests, format=None):
     '''
     注册,验证码成功之后进行注册
     :param username:用户名
     :param password: 密码
     :return: 201,注册成功
     '''
     username = requests.data['username']
     password = requests.data['password']
     try:
         user = User.objects.get(username=username)
         return Response(status=status.HTTP_403_FORBIDDEN)
     except:
         user = User.objects.create_user(username=username, password=password,
                                         last_login=datetime.datetime.now(), email=username)
         user.save()
         appuser = AppUser()
         appuser.user = user
         appuser.save()
         return Response(status=status.HTTP_201_CREATED)
Exemplo n.º 6
0
 def post(self, request, format=None):
     serializer = RegisterSerializer(data=request.data)
     if serializer.is_valid():
         try:
             user = AppUser.objects.get(email=serializer.data['email'])
             admin_user = User.objects.get(email=serializer.data['email'])
             return Response({"status": "user exist"},
                             status=status.HTTP_400_BAD_REQUEST)
         except ObjectDoesNotExist:
             username = ""
             num = random.randint(4, 10)
             while True:
                 username = ""
                 for i in range(num):
                     username += random.choice(seed)
                 try:
                     user = AppUser.objects.get(username=username)
                 except AppUser.DoesNotExist:
                     break
             password = serializer.data['password']
             email = serializer.data['email']
             admin_user = User.objects.create_user(
                 username=username,
                 password=password,
                 last_login=datetime.datetime.now(),
                 email=email)
             admin_user.save()
             user = AppUser()
             user.username = username
             user.password = password
             user.user = admin_user
             user.email = email
             user.save()
             return Response(status=status.HTTP_201_CREATED)
     return Response({"status": "format error"},
                     status=status.HTTP_400_BAD_REQUEST)
def add_app_user(data):
    add_user(data)
    user = User.objects.get(username=data['username'])
    p = AppUser(user=user, photo=data['photo'], user_type=data['type'])
    p.save()
    print "App user saved"
Exemplo n.º 8
0
def aaron_signup(request):
    #This function creates a new user from the data entered into the sign up form
    form = AddUserForm()
    context = {'form': form, 'signup_page': 'active'}
    if request.method == 'POST':
        form = AddUserForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data[
                'email']  # TODO check email is unique, only store unique emails
            password = form.cleaned_data['password']
            check_password = form.cleaned_data['confirm_password']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            if AppUser.objects.filter(email=email).exists():
                context = {
                    'form':
                    form,
                    'signup_page':
                    'active',
                    'error_message':
                    '<p style="color:red">This email already exsists.</p>'
                }
                return render(request, 'applicantportal/signup.html', context)
            if len(password) < 8:
                context = {
                    'form':
                    form,
                    'signup_page':
                    'active',
                    'error_message':
                    '<p style="color:red">Password length is too short. Password must be greater than 8 characters.</p>'
                }
                return render(request, 'applicantportal/signup.html', context)
            if password != check_password:
                context = {
                    'form':
                    form,
                    'signup_page':
                    'active',
                    'error_message':
                    '<p style="color:red">Passwords do not match.</p>'
                }
                return render(request, 'applicantportal/signup.html', context)
            if any(x.isupper() for x in password) == False:
                context = {
                    'form':
                    form,
                    'signup_page':
                    'active',
                    'error_message':
                    '<p style="color:red">Password needs one uppercase letter.</p>'
                }
                return render(request, 'applicantportal/signup.html', context)
            hashed_password = make_password(password)
            user = AppUser(email=email,
                           password=hashed_password,
                           userType='Applicant',
                           first_name=first_name,
                           last_name=last_name)
            user.save()  # TODO create session key
            request.session['id'] = AppUser.objects.get(email=email).id
            return applicant_jobs(request)
    return render(request, 'applicantportal/signup.html', context)