def create(request): '''create a new user with address''' users = vmod.User() users.username = '' users.first_name = '' users.last_name = '' users.email = '' users.password = '' users.security_answer = 'to seek the holy grail' users.security_question = 'What is your quest?' users.address_id = 1 users.save() return HttpResponseRedirect('/user/user.edit/{}/'.format(users.id))
def joinform(request): params = {} #This brings in the form created below. form = UserJoinForm() #When I call this funtion as a POST run this. Otherwise, skip to below if request.method == "POST": form = UserJoinForm(request.POST) print("Before Valid") if form.is_valid(): print("After Valid") #Create the user user = vmod.User() address = vmod.Address() address.address1 = '' address.city = '' address.state = '' address.zip = '12345' address.save() address_id = address.id user.address_id = address_id #Use the form data as the attributes user.username = form.cleaned_data['username'] user.first_name = form.cleaned_data['first_name'] user.last_name = form.cleaned_data['last_name'] user.email = form.cleaned_data['email'] user.security_question = form.cleaned_data['security_question'] user.security_answer = form.cleaned_data['security_answer'] user.set_password(form.cleaned_data['password']) #Save the user user.save() return templater.render_to_response(request, 'join.thankyou.html', params) else: print("Form Not Valid") params['form'] = form return templater.render_to_response(request, 'join.joinform.html', params)
def commit(self, request): review = hmod.Review() review.rating = self.cleaned_data.get('rating') review.message = self.cleaned_data.get('message') review.save() review = hmod.Review.objects.latest('create_date') user = hmod.User() if 'submit_normal' in request.POST: user.name = self.cleaned_data.get('name') user.email = self.cleaned_data.get('email') user.school = self.cleaned_data.get('school') if self.request.POST.get( 'mailing_list') is not None and user.email != '': user.mailing_list = True user.review = review user.save()
def loginform(request): params = {} form = LoginForm() if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] print(">>>>Username", username) sauce = form.cleaned_data['password'] print(">>>>Sauce", sauce) try: #Colonial Server connection for LDAP s = Server('www.colonialheritage.space', port=8889, get_info=GET_ALL_INFO) print('>>>>LDAP-S ', s) c = Connection(s, auto_bind=True, client_strategy=STRATEGY_SYNC, user='******' % username, password='******' % sauce, authentication=AUTH_SIMPLE) # #If good login if c != None: print('>>>>LDAP-C ', c) #Update the website with information from AD search_results = c.search( search_base='CN=Users,DC=colonialheritage,DC=local', search_filter='(samAccountName=%s)' % username, attributes=['givenName', 'sn', 'userPrincipalName']) user_info = c.response[0]['attributes'] print(">>>>LDAP-C.Info ", user_info) first_name = user_info['givenName'] last_name = user_info['sn'] email = user_info['userPrincipalName'] print('>>>>Username ', username) print('>>>>First_name ', first_name) print('>>>>Last_name ', last_name) print('>>>>Email ', email) try: u = hmod.User.objects.get(username=username) u.first_name = first_name u.last_name = last_name u.email = email u.set_password(sauce) u.save() except: u = hmod.User() u.first_name = first_name u.last_name = last_name u.email = email u.username = username u.set_password(sauce) u.is_staff = True u.is_superuser = False u.last_login = str(datetime.now()) u.address_id = 1 u.save() print(">>>>LDAP-Complete") u2 = authenticate(username, sauce) login(request, u2) return HttpResponse( '<script> window.location.href="/home/index/";</script>' ) else: print('>>>>C-None') except: #Log in just on website print(">>>LDAP-Abort") try: user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) if user == None: print("Invalid Credentials") raise forms.ValidationError('Invalid Credentials') else: #Log the user in with the following code login(request, user) return HttpResponse( '<script> window.location.href="/home/index/";</script>' ) except: pass else: print('Form Not Valid') params['form'] = form return templater.render_to_response(request, 'login.loginform.html', params)
], [ "Erwin", "Rommel", "erwinP", "erwin1", False, 10, "*****@*****.**", '801-423-1428', "What is the answer to the universe?", "41" ], [ "George", "Patton", "georgeP", "georges1", False, 11, "*****@*****.**", '801-423-1428', "What is the answer to the universe?", "41" ], [ "Omar", "Bradley", "omarP", "omar1", False, 12, "*****@*****.**", '801-423-1428', "What is the answer to the universe?", "41" ], ]: u = hmod.User() u.first_name = data[0] u.last_name = data[1] u.set_password(data[2]) u.username = data[3] u.is_superuser = data[4] u.address_id = data[5] u.email = data[6] u.phone = data[7] u.security_question = data[8] u.security_answer = data[9] u.save() #####Permissions##### ##Code from Carter Hesterman