def resetpassword(request): status = "" if request.POST.get("email", "").strip() != "": try: validate_captcha(request) try: user = User.objects.get(email = request.POST["email"].strip()) axn = ResetPasswordAction() axn.userid = user.id axn.email = user.email send_email_verification(user.email, None, axn) except: pass status = "We've sent an email to that address with further instructions. If you do not receive an email, 1) check your junk mail folder and 2) make sure you correctly entered the address that you registered on this site." except: status = "The reCAPTCHA validation words you typed weren't right." return render_to_response('registration/reset_password.html', { "status": status, "captcha": captcha_html(), "site_name": settings.APP_NICE_SHORT_NAME, }, context_instance=RequestContext(request))
def resetpassword(request): status = "" if request.POST.get("email", "").strip() != "": # Valid reCAPTCHA. import urllib.request, urllib.parse, urllib.error, json ret = json.loads(urllib.request.urlopen( "https://www.google.com/recaptcha/api/siteverify", data=urllib.parse.urlencode({ "secret": settings.RECAPTCHA_SECRET_KEY, "response": request.POST.get("g-recaptcha-response", ""), "remoteip": request.META['REMOTE_ADDR'], }).encode("utf8")).read().decode("utf8")) if not ret.get("success"): status = "; ".join(ret.get("error-codes", [])) + ". If you can't past this point, please contact us using the contact link at the bottom of this page." else: try: user = User.objects.get(email = request.POST["email"].strip()) axn = ResetPasswordAction() axn.userid = user.id axn.email = user.email send_email_verification(user.email, None, axn) except: pass status = "We've sent an email to that address with further instructions. If you do not receive an email, 1) check your junk mail folder and 2) make sure you correctly entered the address that you registered on this site." return render(request, 'registration/reset_password.html', { "status": status, "RECAPTCHA_SITE_KEY": settings.RECAPTCHA_SITE_KEY, })
def resetpassword(request): status = "" if request.POST.get("email", "").strip() != "": try: validate_captcha(request) try: user = User.objects.get(email=request.POST["email"].strip()) axn = ResetPasswordAction() axn.userid = user.id axn.email = user.email send_email_verification(user.email, None, axn) except: pass status = "We've sent an email to that address with further instructions. If you do not receive an email, 1) check your junk mail folder and 2) make sure you correctly entered the address that you registered on this site." except: status = "The reCAPTCHA validation words you typed weren't right." return render_to_response('registration/reset_password.html', { "status": status, "captcha": captcha_html(), "site_name": APP_NICE_SHORT_NAME, }, context_instance=RequestContext(request))
def resetpassword(request): status = "" if request.POST.get("email", "").strip() != "": # Valid reCAPTCHA. import urllib.request, urllib.parse, urllib.error, json ret = json.loads(urllib.request.urlopen( "https://www.google.com/recaptcha/api/siteverify", data=urllib.parse.urlencode({ "secret": settings.RECAPTCHA_SECRET_KEY, "response": request.POST.get("g-recaptcha-response", ""), "remoteip": request.META['REMOTE_ADDR'], }).encode("utf8")).read().decode("utf8")) if not ret.get("success"): status = "; ".join(ret.get("error-codes", [])) + ". If you can't past this point, please contact us using the contact link at the bottom of this page." else: try: user = User.objects.get(email = request.POST["email"].strip()) axn = ResetPasswordAction() axn.userid = user.id axn.email = user.email send_email_verification(user.email, None, axn) except: pass status = "We've sent an email to that address with further instructions. If you do not receive an email, 1) check your junk mail folder and 2) make sure you correctly entered the address that you registered on this site." return render(request, 'registration/reset_password.html', { "status": status, "RECAPTCHA_SITE_KEY": settings.RECAPTCHA_SITE_KEY, })
def handle(self, *args, **options): cutoff = (datetime.now()-timedelta(days=365*3)).date().replace(day=1) users = SubscriptionList.objects\ .filter(email__gt=0, user__last_login__lt=cutoff)\ .exclude(user__ping__pingtime__isnull=False)\ .values_list("user", "user__email", "user__last_login").distinct() print "Cutoff:", cutoff.isoformat() print "Lists:", users.count() print "Emailed since 2.0:", users.exclude(last_event_mailed=None).count() if len(args) > 0 and args[0] == "send": for user in users: axn = UserAction() axn.uid = user[0] print user send_email_verification(user[1], None, axn)
def handle(self, *args, **options): cutoff = (datetime.now() - timedelta(days=365 * 3)).date().replace(day=1) users = SubscriptionList.objects\ .filter(email__gt=0, user__last_login__lt=cutoff)\ .exclude(user__ping__pingtime__isnull=False)\ .values_list("user", "user__email", "user__last_login").distinct() print "Cutoff:", cutoff.isoformat() print "Lists:", users.count() print "Emailed since 2.0:", users.exclude( last_event_mailed=None).count() if len(args) > 0 and args[0] == "send": for user in users: axn = UserAction() axn.uid = user[0] print user send_email_verification(user[1], None, axn)
def profile(request): errors = {} success = [] if request.method == "POST": email = None if request.POST.get("email", "").strip() != "": try: email = validate_email(request.POST.get("email", ""), skip_if_this_user=request.user) except Exception as e: errors["email"] = validation_error_message(e) password = None if request.POST.get("password", "").strip() != "": try: password = validate_password(request.POST.get("password", "")) except Exception as e: errors["password"] = validation_error_message(e) username = None if settings.REGISTRATION_ASK_USERNAME: if request.POST.get("username", "").strip() != request.user.username: try: username = validate_username( request.POST.get("username", "")) except Exception as e: errors["username"] = validation_error_message(e) if len(errors) == 0: if username or password or email: u = request.user if password: u.set_password(password) success.append("Your password was updated.") if username: u.username = username success.append("Your user name was updated.") if email and email.lower() == u.email.lower(): # Maybe the case is being changed. Or nothing is being changed. if email != u.email: success.append("Your email address was updated.") u.email = email email = None # don't send a confirmation email u.save() if email: axn = ChangeEmailAction() axn.userid = request.user.id axn.email = email send_email_verification(email, None, axn) return render(request, 'registration/registration_check_inbox.html', { "email": email, "site_name": settings.APP_NICE_SHORT_NAME, }) return render( request, 'registration/profile.html', { "site_name": settings.APP_NICE_SHORT_NAME, "ask_username": settings.REGISTRATION_ASK_USERNAME, "sso": request.user.singlesignon.all(), "errors": errors, "success": " ".join(success) if len(success) > 0 else None, })
def registration_utility(request, provider, profile, axn): username = None if "username" in request.POST: username = request.POST["username"] else: # Guess a username. if "screen_name" in profile: username = profile["screen_name"] elif "email" in profile and "@" in profile["email"]: username = profile["email"][0:profile["email"].index("@")] elif "email" in request.POST and "@" in request.POST["email"]: username = request.POST["email"][0:request.POST["email"].index("@" )] email = None if "email" in request.POST: email = request.POST["email"] elif "email" in profile and len(profile["email"]) <= 64: # Pre-populate an email address. email = profile["email"] # Validation errors = {} if username: try: username = validate_username(username) except Exception as e: if settings.REGISTRATION_ASK_USERNAME: errors["username"] = validation_error_message(e) else: # make up a username that validates (i.e. not already taken) c = User.objects.count() + 100 while True: try: username = validate_username( "Anonymous" + str(random.randint(c, c * 5))) break except: continue elif request.method == "POST" and settings.REGISTRATION_ASK_USERNAME: errors["username"] = "******" if email: try: email = validate_email(email) except Exception as e: errors["email"] = validation_error_message(e) elif request.method == "POST": errors["email"] = "Provide an email address." password = None if not provider: if request.method == "POST": try: password = validate_password(request.POST.get("password", "")) except Exception as e: errors["password"] = validation_error_message(e) if len(errors) > 0 or request.method != "POST": # Show the form again with the last entered field values and the # validation error message. return render( request, 'registration/register.html', { "provider": provider, "username": username, "ask_username": settings.REGISTRATION_ASK_USERNAME, "email": email, "errors": errors, "site_name": settings.APP_NICE_SHORT_NAME, }) # Beign creating the account. axn.username = username axn.email = email axn.password = password # If we trust the email address --- because we trust the provider --- we can # create the account immediately. if provider and "trust_email" in providers.providers[ provider] and providers.providers[provider][ "trust_email"] and "email" in profile and email == profile[ "email"]: return axn.finish(request) # Check that the email address is valid by sending an email and delaying registration. request.goal = {"goal": "register-emailcheck"} send_email_verification(email, None, axn) return render(request, 'registration/registration_check_inbox.html', { "email": email, "site_name": settings.APP_NICE_SHORT_NAME, })
# Beign creating the account. axn.username = username axn.email = email axn.password = password # If we trust the email address --- because we trust the provider --- we can # create the account immediately. if provider and "trust_email" in providers.providers[provider] and providers.providers[provider]["trust_email"] and "email" in profile and email == profile["email"]: return axn.finish(request) # Check that the email address is valid by sending an email and delaying registration. request.goal = { "goal": "register-emailcheck" } send_email_verification(email, None, axn) return render_to_response('registration/registration_check_inbox.html', { "email": email, "site_name": settings.APP_NICE_SHORT_NAME, }, context_instance=RequestContext(request)) class RegisterUserAction: username = None email = None password = None provider = None uid = None auth_token = None profile = None next = None
def profile(request): errors = { } success = [] if request.method == "POST": email = None if request.POST.get("email", "").strip() != "": try: email = validate_email(request.POST.get("email", ""), skip_if_this_user=request.user) except Exception as e: errors["email"] = validation_error_message(e) password = None if request.POST.get("password", "").strip() != "": try: password = validate_password(request.POST.get("password", "")) except Exception as e: errors["password"] = validation_error_message(e) username = None if settings.REGISTRATION_ASK_USERNAME: if request.POST.get("username", "").strip() != request.user.username: try: username = validate_username(request.POST.get("username", "")) except Exception as e: errors["username"] = validation_error_message(e) if len(errors) == 0: if username or password or email: u = request.user if password: u.set_password(password) success.append("Your password was updated.") if username: u.username = username success.append("Your user name was updated.") if email and email.lower() == u.email.lower(): # Maybe the case is being changed. Or nothing is being changed. if email != u.email: success.append("Your email address was updated.") u.email = email email = None # don't send a confirmation email u.save() if email: axn = ChangeEmailAction() axn.userid = request.user.id axn.email = email send_email_verification(email, None, axn) return render(request, 'registration/registration_check_inbox.html', { "email": email, "site_name": settings.APP_NICE_SHORT_NAME, }) return render(request, 'registration/profile.html', { "site_name": settings.APP_NICE_SHORT_NAME, "ask_username": settings.REGISTRATION_ASK_USERNAME, "sso": request.user.singlesignon.all(), "errors": errors, "success": " ".join(success) if len(success) > 0 else None, })
def registration_utility(request, provider, profile, axn): username = None if "username" in request.POST: username = request.POST["username"] else: # Guess a username. if "screen_name" in profile: username = profile["screen_name"] elif "email" in profile and "@" in profile["email"]: username = profile["email"][0:profile["email"].index("@")] elif "email" in request.POST and "@" in request.POST["email"]: username = request.POST["email"][0:request.POST["email"].index("@")] email = None if "email" in request.POST: email = request.POST["email"] elif "email" in profile and len(profile["email"]) <= 64: # Pre-populate an email address. email = profile["email"] # Validation errors = { } if username: try: username = validate_username(username) except Exception as e: if settings.REGISTRATION_ASK_USERNAME: errors["username"] = validation_error_message(e) else: # make up a username that validates (i.e. not already taken) c = User.objects.count() + 100 while True: try: username = validate_username("Anonymous" + str(random.randint(c, c*5))) break except: continue elif request.method == "POST" and settings.REGISTRATION_ASK_USERNAME: errors["username"] = "******" if email: try: email = validate_email(email) except Exception as e: errors["email"] = validation_error_message(e) elif request.method == "POST": errors["email"] = "Provide an email address." password = None if not provider: if request.method == "POST": try: password = validate_password(request.POST.get("password", "")) except Exception as e: errors["password"] = validation_error_message(e) if len(errors) > 0 or request.method != "POST": # Show the form again with the last entered field values and the # validation error message. return render(request, 'registration/register.html', { "provider": provider, "username": username, "ask_username": settings.REGISTRATION_ASK_USERNAME, "email": email, "errors": errors, "site_name": settings.APP_NICE_SHORT_NAME, }) # Beign creating the account. axn.username = username axn.email = email axn.password = password # If we trust the email address --- because we trust the provider --- we can # create the account immediately. if provider and "trust_email" in providers.providers[provider] and providers.providers[provider]["trust_email"] and "email" in profile and email == profile["email"]: return axn.finish(request) # Check that the email address is valid by sending an email and delaying registration. request.goal = { "goal": "register-emailcheck" } send_email_verification(email, None, axn) return render(request, 'registration/registration_check_inbox.html', { "email": email, "site_name": settings.APP_NICE_SHORT_NAME, })
def change_email_address(user, newaddress): axn = ChangeEmailAddressAction() axn.user = user axn.newemail = newaddress send_email_verification(newaddress, None, axn)
def email_body(self): return """Please follow this link: <URL> Thanks!""" def email_body(self): return """Please follow this link: <URL> Thanks!""" def email_html_template(self): return ("emailverification/htmlexample.html", { "info": self.info }) def get_response(self, request, vrec): return HttpResponseRedirect("/") # Form Submission Code from emailverification.utils import send_email_verification axn = MyAction() axn.info = "This is a sentence passed in through a template context variable." send_email_verification(to_addr, None, axn)
axn.email = email axn.password = password # If we trust the email address --- because we trust the provider --- we can # create the account immediately. if provider and "trust_email" in providers.providers[ provider] and providers.providers[provider][ "trust_email"] and "email" in profile and email == profile[ "email"]: return axn.finish(request) # Check that the email address is valid by sending an email and delaying registration. request.goal = {"goal": "register-emailcheck"} send_email_verification(email, None, axn) return render_to_response('registration/registration_check_inbox.html', { "email": email, "site_name": APP_NICE_SHORT_NAME, }, context_instance=RequestContext(request)) class RegisterUserAction: username = None email = None password = None provider = None uid = None auth_token = None
def email_body(self): return """Please follow this link: <URL> Thanks!""" def email_body(self): return """Please follow this link: <URL> Thanks!""" def email_html_template(self): return ("emailverification/htmlexample.html", {"info": self.info}) def get_response(self, request, vrec): return HttpResponseRedirect("/") # Form Submission Code from emailverification.utils import send_email_verification axn = MyAction() axn.info = "This is a sentence passed in through a template context variable." send_email_verification(to_addr, None, axn)
def change_email_address(user, newaddress): axn = ChangeEmailAddressAction() axn.user = user axn.newemail = newaddress send_email_verification(newaddress, None, axn)