def test_db_add(request): if request.method == "POST": entry = UserProfile() entry.username = request.POST.get('uname') entry.email = request.POST.get('email') entry.first = request.POST.get('fname') entry.last = request.POST.get('lname') entry.picture = '/Images/User' + str(entry.username) entry.interests1 = request.POST.get('int1') entry.interests2 = request.POST.get('int2') entry.interests3 = request.POST.get('int3') entry.interests4 = request.POST.get('int4') entry.interests5 = request.POST.get('int5') entry.save() return HttpResponse('Successfully Added') else: return render(request, 'test_db_add.html')
def userCreate(request): if request.method == 'POST': fName = str(request.POST.get('fName', '')) lName = str(request.POST.get('lName', '')) university = str(request.POST.get('university', '')) email = str(request.POST.get('email', '')) username = str(request.POST.get('username', '')) password = str(request.POST.get('password', '')) confirmPassword = str(request.POST.get('confirmPassword', '')) ''' print(fName) print(lName) print(email) print(username) ''' # now for some form validation #first check database for existing userid and email since these need to be unique to each user if isEmailPresent(email): messages.error( request, "This email is already registered to an existing user!") if isUsernamePresent(username): messages.error( request, "This username already belongs to an existing user!") if not isEmailPresent(email) and not isUsernamePresent(username): # this is checking to make sure first name and last name only include letters isFNameValid = fName.isalpha() isLNameValid = lName.isalpha() isUserNameValid = True if username.isalnum() and len( username) in range(5, 12) else False isNyuEmail = True if "@nyu.edu" in email else False #Currently only serves NYU passwordsMatch = True if password == confirmPassword else False if not isFNameValid: messages.error(request, "The First Name Entered is not Valid!") if not isLNameValid: messages.error(request, "The Last Name Entered is not Valid!") if not isUserNameValid: messages.error( request, "Username should only include letters and numbers and be between 5 and 12 characters long!" ) if not isNyuEmail: messages.error( request, "Please use the email associated with your university!") if not passwordsMatch: messages.error(request, "Please make sure that the passwords match!") elif passwordsMatch: #already confirmed that they match, now checking if it's valid isValid = isPasswordValid(password) if not isValid: messages.error( request, "Passwords should be between 8 and 15 characters!") if isFNameValid and isLNameValid and isUserNameValid and isNyuEmail and passwordsMatch and isPasswordValid( password): #create instance of user and save to db print("here") newUser = User(email=email) newUser.set_password(password) newUser.save() newUserProfile = UserProfile() newUserProfile.user = newUser newUserProfile.firstName = fName newUserProfile.lastName = lName newUserProfile.username = username newUserProfile.university = university newUserProfile.save() user = authenticate(username=email, password=password) login(request, user) return HttpResponseRedirect('/search_chats/')