def mdl_register(request): form = RegisterForm() if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): #Email exits try: user = MdlUser.objects.filter( email=request.POST['email']).first().id messages.success( request, "Email : " + request.POST['email'] + " already registered on this website. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login" ) except Exception, e: mdluser = MdlUser() mdluser.auth = 'manual' mdluser.institution = form.cleaned_data['college'] mdluser.gender = form.cleaned_data['gender'] mdluser.firstname = form.cleaned_data['firstname'].upper() mdluser.lastname = form.cleaned_data['lastname'].upper() mdluser.email = form.cleaned_data['email'].lower() mdluser.username = mdluser.email mdluser.password = encript_password( form.cleaned_data['password']) mdluser.confirmed = 1 mdluser.mnethostid = 1 mdluser.save() mdluser = MdlUser.objects.get(email=mdluser.email) get_or_create_user(mdluser, form.cleaned_data['password']) messages.success( request, "User " + form.cleaned_data['firstname'] + " " + form.cleaned_data['lastname'] + " Created!. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login" ) return HttpResponseRedirect('/participant/register/')
def mdl_register(request): form = RegisterForm() if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): #Email exits try: user = MdlUser.objects.filter(email=request.POST['email']).first().id messages.success(request, "Email : "+request.POST['email']+" already registered on this website. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login") except Exception, e: mdluser = MdlUser() mdluser.auth = 'manual' mdluser.institution = form.cleaned_data['college'] mdluser.gender = form.cleaned_data['gender'] mdluser.firstname = form.cleaned_data['firstname'].upper() mdluser.lastname = form.cleaned_data['lastname'].upper() mdluser.email = form.cleaned_data['email'].lower() mdluser.username = mdluser.email mdluser.password = encript_password(form.cleaned_data['password']) mdluser.confirmed = 1 mdluser.mnethostid = 1 mdluser.save() mdluser = MdlUser.objects.get(email=mdluser.email) get_or_create_user(mdluser, form.cleaned_data['password']) messages.success(request, "User " + form.cleaned_data['firstname'] +" "+form.cleaned_data['lastname']+" Created!. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login") return HttpResponseRedirect('/participant/register/')
def mdl_register(request): form = RegisterForm() # import recaptcha validate function from cms.recaptcha import recaptcha_valdation, get_recaptcha_context #reCAPTCHA Site key context = get_recaptcha_context() if request.method == "POST": # verify recaptcha #recaptcha_result = recaptcha_valdation(request) form = RegisterForm(request.POST) #if recaptcha_result and form.is_valid(): if form.is_valid(): #Email exits try: user = MdlUser.objects.filter( email=request.POST['email']).first().id messages.success( request, "Email : " + request.POST['email'] + " already registered on this website. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login" ) except Exception as e: mdluser = MdlUser() mdluser.auth = 'manual' mdluser.institution = form.cleaned_data['college'] mdluser.gender = form.cleaned_data['gender'] mdluser.firstname = form.cleaned_data['firstname'].upper() mdluser.lastname = form.cleaned_data['lastname'].upper() mdluser.email = form.cleaned_data['email'].lower() mdluser.username = mdluser.email mdluser.password = encript_password( form.cleaned_data['password']) mdluser.confirmed = 1 mdluser.mnethostid = 1 mdluser.save() mdluser = MdlUser.objects.get(email=mdluser.email) get_or_create_user(mdluser, form.cleaned_data['password']) messages.success( request, "User " + form.cleaned_data['firstname'] + " " + form.cleaned_data['lastname'] + " Created!. Please click <a href='http://www.spoken-tutorial.org/participant/login/'>here </a>to login" ) return HttpResponseRedirect('/participant/register/') context['form'] = form context.update(csrf(request)) return render(request, 'mdl/templates/register.html', context)
def forget_password(request): context = {} form = PasswordResetForm() if request.method == "POST": form = PasswordResetForm(request.POST) if form.is_valid(): password_string = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) user = MdlUser.objects.filter(email=request.POST['email']).first() password_encript = encript_password(password_string) user.password = password_encript user.save() # reset auth user password mdluser, flag, authuser = get_or_create_user(user) authuser.set_password(password_string) authuser.save() subject = "Spoken Tutorial Online Test password reset" to = [user.email] message = '''Hi {0}, Your account password at 'Spoken Tutorials Online Test Center' has been reset and you have been issued with a new temporary password. Your current login information is now: username: {1} password: {2} Please go to this page to change your password: {3} In most mail programs, this should appear as a blue link which you can just click on. If that doesn't work, then cut and paste the address into the address line at the top of your web browser window. Cheers from the 'Spoken Tutorials Online Test Center' administrator, Admin Spoken Tutorials '''.format(user.firstname, user.username, password_string, 'http://onlinetest.spoken-tutorial.org/login/change_password.php') # send email email = EmailMultiAlternatives( subject, message, '*****@*****.**', to = to, bcc = [], cc = [], headers={'Reply-To': '*****@*****.**', "Content-type":"text/html;charset=iso-8859-1"} ) result = email.send(fail_silently=False) messages.success(request, "New password sent to your email "+user.email) return HttpResponseRedirect('/participant/login/') context = { 'form': form } context.update(csrf(request)) return render(request, 'mdl/templates/password_reset.html', context)
def clean_email(self): email = self.cleaned_data['email'].lower() error = 0 try: user = MdlUser.objects.filter(email=email).first() user.id error = 1 # check if user exists mdluser, flag, authuser = get_or_create_user(user) if flag: mdluser.password = encript_password(mdluser.firstname) mdluser.save() # send email along with password except Exception, e: return email