def create(request): """ Creates a new user account request from a new user. """ # Check if the creation form has been submitted. if request.method == "POST": # If so, bind the creation form to HTTP POST values. form = RegistrationRequestForm(request.POST) # Check if the form has validated successfully. if form.is_valid(): # Create a new (inactive) User account so that we can discard the # plain text password. This will also create a corresponding # `UserProfile` instance by post_save "magic". _user = User.objects.create_user(form.cleaned_data['shortname'], form.cleaned_data['email'], form.cleaned_data['password']) _user.first_name = form.cleaned_data['first_name'] _user.last_name = form.cleaned_data['last_name'] _user.is_active = False _user.save() _profile = UserProfile.objects.get(user_id= _user.id) _profile.affiliation = form.cleaned_data['organization'] _profile.country = form.cleaned_data['country'] if 'phone_number' in form.cleaned_data: _profile.phone_number = form.cleaned_data['phone_number'] _profile.save() # Create new RegistrationRequest instance. new_object = RegistrationRequest(user=_user) # Save new RegistrationRequest instance to django database. new_object.save() # Render confirmation email template with correct values. data = {'firstname': _user.first_name, 'lastname': _user.last_name, 'shortname': _user.username, 'node_url': DJANGO_URL, 'confirmation_url': '{0}/accounts/confirm/{1}/'.format( DJANGO_URL, new_object.uuid)} email = render_to_string('accounts/confirmation.email', data) try: # Send out confirmation email to the given email address. send_mail(_('Please confirm your ELRC-SHARE user account'), email, '*****@*****.**', [_user.email], fail_silently=False) except: #SMTPException: # If the email could not be sent successfully, tell the user # about it and also give the confirmation URL. messages.error(request, _("There was an error sending out the confirmation email " \ "for your registration account. You can confirm your " \ "account by <a href='%s'>clicking here</a>.") % (data['confirmation_url'],)) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Add a message to the user after successful creation. messages.success(request, _("We have received your registration data and sent you an " \ "email with further activation instructions.")) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Otherwise, create an empty RegistrationRequestForm instance. else: form = RegistrationRequestForm() dictionary = {'title': 'Create Account', 'form': form} return render_to_response('accounts/create_account.html', dictionary, context_instance=RequestContext(request))
def create(request): """ Creates a new user account request from a new user. """ # Check if the creation form has been submitted. if request.method == "POST": # If so, bind the creation form to HTTP POST values. form = RegistrationRequestForm(request.POST) # Check if the form has validated successfully. if form.is_valid(): # Create a new (inactive) User account so that we can discard the # plain text password. This will also create a corresponding # `UserProfile` instance by post_save "magic". _user = User.objects.create_user(form.cleaned_data['shortname'], form.cleaned_data['email'], form.cleaned_data['password']) _user.first_name = form.cleaned_data['first_name'] _user.last_name = form.cleaned_data['last_name'] _user.is_active = False _user.save() _profile = UserProfile.objects.create(user= _user, \ affiliation = form.cleaned_data['organization'], \ country = form.cleaned_data['country'], ) if 'phone_number' in form.cleaned_data: _profile.phone_number = form.cleaned_data['phone_number'] _profile.save() # UserProfileForm # Create new RegistrationRequest instance. new_object = RegistrationRequest(user=_user) # Save new RegistrationRequest instance to django database. new_object.save() # Render confirmation email template with correct values. data = {'firstname': _user.first_name, 'lastname': _user.last_name, 'shortname': _user.username, 'node_url': DJANGO_URL, 'confirmation_url': '{0}/accounts/confirm/{1}/'.format( DJANGO_URL, new_object.uuid)} email = render_to_string('accounts/confirmation.email', data) try: # Send out confirmation email to the given email address. send_mail(_('Please confirm your ELRC-SHARE user account'), email, '*****@*****.**', [_user.email], fail_silently=False) except: #SMTPException: # If the email could not be sent successfully, tell the user # about it and also give the confirmation URL. messages.error(request, _("There was an error sending out the confirmation email " \ "for your registration account. You can confirm your " \ "account by <a href='%s'>clicking here</a>.") % (data['confirmation_url'],)) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Add a message to the user after successful creation. messages.success(request, _("We have received your registration data and sent you an email " \ "with further activation instructions. If you do not see the " \ "message in your Inbox within the next 5 minutes, please " \ "check your Spam/Junk folder, or contact us at " \ "[email protected].")) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Otherwise, create an empty RegistrationRequestForm instance. else: form = RegistrationRequestForm() dictionary = {'title': 'Create Account', 'form': form} return render_to_response('accounts/create_account.html', dictionary, context_instance=RequestContext(request))
def create(request): """ Creates a new user account request from a new user. """ # Check if the creation form has been submitted. if request.method == "POST": # If so, bind the creation form to HTTP POST values. form = RegistrationRequestForm(request.POST) # Check if the form has validated successfully. if form.is_valid(): # Create new RegistrationRequest instance. new_object = RegistrationRequest( shortname=form.cleaned_data['shortname'], firstname=form.cleaned_data['firstname'], lastname=form.cleaned_data['lastname'], email=form.cleaned_data['email']) # Save new RegistrationRequest instance to django database. new_object.save() # Render confirmation email template with correct values. data = {'firstname': new_object.firstname, 'lastname': new_object.lastname, 'shortname': new_object.shortname, 'confirmation_url': '{0}/accounts/confirm/{1}/'.format( DJANGO_URL, new_object.uuid)} email = render_to_string('accounts/confirmation.email', data) try: # Send out confirmation email to the given email address. send_mail('Please confirm your META-SHARE user account', email, '*****@*****.**', [new_object.email], fail_silently=False) except: #SMTPException: # If the email could not be sent successfully, tell the user # about it and also give the confirmation URL. messages.error(request, "There was an error sending out the confirmation email " \ "for your registration account. You can confirm your " \ "account by <a href='{0}'>clicking here</a>.".format( data['confirmation_url'])) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Add a message to the user after successful creation. messages.success(request, "We have received your registration data and sent you an " \ "email with further activation instructions.") # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Otherwise, create an empty UploadCreateForm instance. else: form = RegistrationRequestForm() dictionary = {'title': 'Create Account', 'form': form} return render_to_response('accounts/create_account.html', dictionary, context_instance=RequestContext(request))
def create(request): """ Creates a new user account request from a new user. """ #Commenting from now, as it might be more functional to handle group assignment for logged in users group_choices = Group.objects.exclude( id__in=EditorGroup.objects.values_list('id', flat=True))\ .values_list('name', 'name') # Check if the creation form has been submitted. if request.method == "POST": # If so, bind the creation form to HTTP POST values. form = RegistrationRequestForm(request.POST, group_choices=group_choices) # Check if the form has validated successfully. if form.is_valid(): # Create a new (inactive) User account so that we can discard the # plain text password. This will also create a corresponding # `UserProfile` instance by post_save "magic". _user = User.objects.create_user(form.cleaned_data['shortname'], form.cleaned_data['email'], form.cleaned_data['password']) _user.first_name = form.cleaned_data['first_name'] _user.last_name = form.cleaned_data['last_name'] _user.is_active = False _user.save() _profile = UserProfile.objects.get(user_id=_user.id) _profile.affiliation = form.cleaned_data['organization'] _profile.affiliation_address = form.cleaned_data[ 'organization_address'] _profile.affiliation_phone_number = form.cleaned_data[ 'organization_phone_number'] # These two were removed from the form #_profile.country = form.cleaned_data['country'] #_profile.phone_number = form.cleaned_data['phone_number'] _profile.position = form.cleaned_data['position'] #Commenting from now, as it might be more functional to handle group assignment for logged in users #_profile.user.groups.add( #Group.objects.get(name=form.cleaned_data['contributor_group'])) _profile.save() # Create new RegistrationRequest instance. new_object = RegistrationRequest(user=_user) # Save new RegistrationRequest instance to django database. new_object.save() # Send e-mail to superusers su_emails = [ u.email for u in User.objects.filter(is_superuser=True) ] data = { 'username': _user.username, 'firstname': _user.first_name, 'lastname': _user.last_name, 'email': _user.email, 'telephone': _profile.phone_number, 'affiliation': _profile.affiliation, 'position': _profile.position, 'confirmation_url': '{0}/accounts/confirm/{1}/'.format(DJANGO_URL, new_object.uuid) } email = render_to_string('accounts/registration_email.html', data) try: send_mail(_('New user registration'), email, EMAIL_ADDRESSES['elri-no-reply'], su_emails, fail_silently=False) except: # failed to send e-mail to superuser # If the email could not be sent successfully, tell the user # about it and also give the confirmation URL. messages.error( request, _("There was an error sending out the notification email " "to the administrators. Please contact them directly.")) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Add a message to the user after successful creation. messages.success( request, _("We have received your registration data and sent the " "administrators a notification email." "You will receive an email when your account has been activated." )) # Redirect the user to the front page. return redirect('metashare.views.frontpage') # Otherwise, create an empty RegistrationRequestForm instance. else: form = RegistrationRequestForm(group_choices=group_choices) elri_tos_def = 'metashare/ELRI_ToS_template.pdf' #provide ToS document according to the user prefered language: the one that appears in the URL lang = translation.get_language() elri_tos = '/static/metashare/ELRI_ToS_' + lang + '.pdf' dictionary = { 'title': _('Create Account'), 'form': form, 'elri_tos': elri_tos } return render_to_response('accounts/create_account.html', dictionary, context_instance=RequestContext(request))