def create_admin(request): if request.method == 'POST': user_form = InitialAdminForm(request.POST) if user_form.is_valid(): if user_form.usernameExists(): messages.info(request, 'Username already taken. Try a different one.') #checks if username exists in db return redirect("admin_register") elif user_form.emailExists(): messages.info(request, 'Email already taken. Try a different one.') #checks if email exists in db return redirect("admin_register") elif number_symbol_exists(user_form.cleaned_data["first_name"]): #checks if number/symbol exists in string messages.info(request, 'Please enter a valid first name.') return redirect("admin_register") elif number_symbol_exists(user_form.cleaned_data["last_name"]): #checks if number/symbol exists in string messages.info(request, 'Please enter a valid last name.') return redirect("admin_register") elif not user_form.samePasswords(): messages.info(request, 'Passwords not matching. Try again.') #checks if password and confirm password are matching return redirect("admin_register") elif not user_form.emailDomainExists(): #checks if there is an exising domain for given email messages.info(request, 'Email domain does not exist. Try again.') return redirect("admin_register") else: if isValidated(user_form.cleaned_data.get('password1')): #checks if password is valid admin_form = AdminForm(request.POST, request.FILES) if admin_form.is_valid(): with transaction.atomic(): user = user_form.save() admin = admin_form.save(commit=False) admin.user = user admin.save() next_page = request.POST.get('next', '/') return redirect(next_page) else: messages.info(request, admin_form.errors) return redirect("admin_register") else: messages.info(request, 'ERROR: Password must be 8 characters or more, and must have atleast 1 numeric character and 1 letter.') return redirect("admin_register") else: messages.info(request, user_form.errors) return redirect("admin_register") else: user_form = InitialAdminForm() admin_form = AdminForm() args = {'admin_form': admin_form, 'user_form': user_form} return render(request, 'admin/admin_registration.html', args)
def student_signup(request): if request.method == 'POST': user_form = InitialStudentForm(request.POST) if user_form.is_valid(): if user_form.usernameExists(): #checks if username exists in db messages.info(request, 'Username already taken. Try a different one.') return redirect("student_registration") elif user_form.emailExists(): #checks if email exists in db messages.info(request, 'Email already taken. Try a different one.') return redirect("student_registration") elif number_symbol_exists( user_form.cleaned_data["first_name"] ): #checks if number/symbol exists in string messages.info(request, 'Please enter a valid first name.') return redirect("student_registration") elif number_symbol_exists( user_form.cleaned_data["last_name"] ): #checks if number/symbol exists in string messages.info(request, 'Please enter a valid last name.') return redirect("student_registration") elif not user_form.samePasswords( ): #checks if password and confirm password are matching messages.info(request, 'Passwords not matching. Try again.') return redirect("student_registration") elif not user_form.emailDomainExists( ): #checks if there is an exising domain for given email messages.info(request, 'Email domain does not exist. Try again.') return redirect("student_registration") else: if isValidated(user_form.cleaned_data.get( 'password1')): #checks if password is valid student_form = StudentForm(request.POST, request.FILES) if student_form.is_valid(): email = user_form.cleaned_data["email"] if not search("@student.murdoch.edu.au", email): if not student_form.cleaned_data["alumni_status"]: messages.info( request, 'Please enter an existing murdoch student email.' ) return redirect("student_registration") else: pass with transaction.atomic(): user = user_form.save() student = student_form.save(commit=False) student.user = user student.save() student_form.save_m2m() message = Mail( from_email=DEFAULT_FROM_EMAIL, to_emails=['*****@*****.**'], subject='New User has signed up', html_content= "A new Student has registered to use the Murdoch Career Portal." ) sg = SendGridAPIClient(SENDGRID_API_KEY) # sg.send(message) # notification = "A new Student has registered to use the Murdoch Career Portal." # add_notif = UserNotifications(to_user_id=1, from_user_id=request.user.id, # notification=notification, # type='Sign Up', # to_show=True) # add_notif.save() return redirect("log_in") else: messages.info(request, student_form.errors) return redirect("student_registration") else: messages.info( request, 'ERROR: Password must be 8 characters or more, and must have atleast 1 numeric character and 1 letter.' ) return redirect("student_registration") else: messages.info(request, user_form.errors) return redirect("student_registration") else: user_form = InitialStudentForm() student_form = StudentForm() user = get_user_type(request) args = { 'student_form': student_form, 'user_form': user_form, 'user_type': user['user_type'] } return render(request, 'student_registration.html', args)
def student_signup(request): if request.method == 'POST': user_data = { 'first_name': request.POST.get('first_name'), 'last_name': request.POST.get('last_name'), 'email': request.POST.get('email') } student_data = { 'gender': request.POST.get('gender'), 'date_of_birth': request.POST.get('date_of_birth'), 'student_id': request.POST.get('student_id'), 'expected_graduation_date': request.POST.get('expected_graduation_date'), 'personal_email': request.POST.get('personal_email'), 'skills': request.POST.getlist('skills'), 'majors': request.POST.getlist('majors'), 'dp': request.FILES.get('dp'), 'cv': request.FILES.get('cv') } user_form = InitialStudentForm(request.POST) if user_form.is_valid(): if user_form.usernameExists(): messages.error( request, 'Username already taken. Try a different one.', extra_tags='danger') # checks if username exists in db elif user_form.emailExists(): messages.error( request, 'Email already taken. Try a different one.', extra_tags='danger') # checks if email exists in db elif not user_form.same_passwords(): messages.error( request, 'Passwords not matching. Try again.', extra_tags='danger' ) # checks if password and confirm password are matching elif not user_form.email_domain_exists(): messages.error( request, 'Email domain does not exist. Try again.', extra_tags='danger' ) # checks if there is an existing domain for given email else: if isValidated(user_form.cleaned_data.get('password1')): student_form = StudentForm(request.POST, request.FILES) if student_form.is_valid(): with transaction.atomic(): user = user_form.save() student = student_form.save(commit=False) student.user = user email = str(student.user) student_email = str(student.personal_email) student.save() student_form.save_m2m() first_name = user_form.cleaned_data.get( 'first_name') context = {'first_name': first_name} admin_context = { 'first_name': first_name, 'protocol': 'https', 'domain': 'murdochdubaicareerportal.com' } subject = 'Your account creation request has been received' htmlText = render_to_string( 'Accounts/account_creation_request.html', context) send_html_mail(subject, htmlText, [email]) send_html_mail(subject, htmlText, [student_email]) subject = 'An account creation request has been received ' htmlText = render_to_string( 'Accounts/account_creation_request_admin.html', admin_context) send_html_mail(subject, htmlText, [DEFAULT_FROM_EMAIL]) messages.success(request, 'A student account has been created') return render(request, 'Accounts/pending_acc.html', get_user_type(request)) else: messages.error(request, student_form.errors, extra_tags='danger') else: messages.error( request, 'Password must be 8 characters or more, and must have at least 1 numeric character ' 'and 1 letter.', extra_tags='danger') else: messages.error(request, user_form.errors, extra_tags='danger') user_form = InitialStudentForm(user_data) student_form = StudentForm(student_data) else: user_form = InitialStudentForm() student_form = StudentForm() user = get_user_type(request) args = { 'student_form': student_form, 'user_form': user_form, 'user_type': user['user_type'] } return render(request, 'Student/student_registration.html', args)
def signup(request): if request.method == 'POST': user_data = {'email': request.POST.get('email')} employer_data = {'logo': request.FILES.get('logo'), 'company_name': request.POST.get('company_name'), 'company_description': request.POST.get('company_description'), 'company_website': request.POST.get('company_website'), 'phone_number': request.POST.get('phone_number'), 'contact_name': request.POST.get('contact_name'), 'trade_license': request.FILES.get('trade_license') } user_form = InitialEmployerForm(request.POST) if user_form.is_valid(): if user_form.usernameExists(): messages.error(request, 'Username already taken. Try a different one.', extra_tags='danger') # checks if username exists in db elif user_form.emailExists(): messages.error(request, 'Email already taken. Try a different one.', extra_tags='danger') # checks if email exists in db elif not user_form.samePasswords(): messages.error(request, 'Passwords not matching. Try again.', extra_tags='danger') # checks if password and confirm password are matching elif not user_form.emailDomainExists(): messages.error(request,'Email domain does not exist. Try again.', extra_tags='danger') # checks if there is an exising domain for given email else: if isValidated(user_form.cleaned_data.get('password1')): # checks if password is valid employer_form = EmployerForm(request.POST, request.FILES) if employer_form.is_valid(): with transaction.atomic(): user = user_form.save() employer = employer_form.save(commit=False) employer.user = user email = str(request.user) employer.save() first_name = str(employer.company_name) print(first_name) context = {'first_name': first_name} admin_context = {'first_name': first_name, 'protocol': 'https', 'domain': 'murdochdubaicareerportal.com'} subject = 'Your account creation request has been received' htmlText = render_to_string('Accounts/account_creation_request.html', context) send_html_mail(subject, htmlText, [email]) subject = 'An account creation request has been received ' htmlText = render_to_string('Accounts/account_creation_request_admin.html', admin_context) send_html_mail(subject, htmlText, [DEFAULT_FROM_EMAIL]) messages.success(request, 'Employer account created') return render(request, 'Accounts/pending_acc.html', get_user_type(request)) else: messages.error(request, employer_form.errors, extra_tags='danger') else: messages.error(request, 'Password must be 8 characters or more, and must have at least 1 ' 'numeric character and 1 letter.', extra_tags='danger') else: messages.error(request, user_form.errors, extra_tags='danger') user_form = InitialEmployerForm(user_data) employer_form = EmployerForm(employer_data) else: user_form = InitialEmployerForm() employer_form = EmployerForm() user = get_user_type(request) args = {'employer_form': employer_form, 'user_form': user_form, 'user_type': user['user_type']} return render(request, 'Employer/employer_registration.html', args)
def signup(request): if request.method == 'POST': user_form = InitialEmployerForm(request.POST) if user_form.is_valid(): if user_form.usernameExists(): messages.info(request, 'Username already taken. Try a different one.' ) #checks if username exists in db return redirect("employer_register") elif user_form.emailExists(): messages.info(request, 'Email already taken. Try a different one.' ) #checks if email exists in db return redirect("employer_register") elif not user_form.samePasswords(): messages.info( request, 'Passwords not matching. Try again.' ) #checks if password and confirm password are matching return redirect("employer_register") elif not user_form.emailDomainExists(): messages.info( request, 'Email domain does not exist. Try again.' ) #checks if there is an exising domain for given email return redirect("employer_register") else: if isValidated(user_form.cleaned_data.get( 'password1')): #checks if password is valid employer_form = EmployerForm(request.POST, request.FILES) if employer_form.is_valid(): with transaction.atomic(): user = user_form.save() employer = employer_form.save(commit=False) employer.user = user employer.save() message = Mail( from_email=DEFAULT_FROM_EMAIL, to_emails=['*****@*****.**'], subject='New User has signed up', html_content= "A new Employer has registered to use the Murdoch Career Portal." ) sg = SendGridAPIClient(SENDGRID_API_KEY) # sg.send(message) # notification = "A new Employer has registered to use the Murdoch Career Portal." # add_notif = UserNotifications(to_user_id=1, from_user_id=request.user.id, # notification=notification, # type='Sign Up', # to_show=True) # add_notif.save() return redirect("log_in") else: messages.info(request, employer_form.errors) return redirect("employer_register") else: messages.info( request, 'ERROR: Password must be 8 characters or more, and must have atleast 1 numeric character and 1 letter.' ) return redirect("employer_register") else: messages.info(request, user_form.errors) return redirect("employer_register") else: user_form = InitialEmployerForm() employer_form = EmployerForm() user = get_user_type(request) args = { 'employer_form': employer_form, 'user_form': user_form, 'user_type': user['user_type'] } return render(request, 'employer_registration.html', args)