def set_text_property(bot, update, chat_data, property_name, to_edit=None): uid = util.uid_from_update(update) user = User.from_update(update) if check_suggestion_limit(bot, update, user): return if to_edit: text = (util.escape_markdown(getattr(to_edit, property_name)) + "\n\n" if getattr(to_edit, property_name) else '') text += mdformat.action_hint( messages.SET_BOTPROPERTY.format( property_name, util.escape_markdown(to_edit.username), CLEAR_QUERY)) if property_name == 'description': text += ', markdown enabled.' update.effective_message.reply_text( text, reply_markup=ForceReply(selective=True), parse_mode=ParseMode.MARKDOWN) chat_data['edit_bot'] = to_edit elif update.message: value = None text = update.message.text to_edit = chat_data.get('edit_bot', None) def too_long(n): bot.formatter.send_failure( uid, "Your {} text is too long, it must be shorter " "than {} characters. Please try again.".format( property_name, n)) util.wait(bot, update) return admin.edit_bot(bot, update, chat_data, to_edit) # Validation if property_name == 'description' and len(text) > 300: return too_long(300) if property_name == 'username': value = helpers.validate_username(text) if value: to_edit = chat_data.get('edit_bot', None) else: bot.formatter.send_failure( uid, "The username you entered is not valid. Please try again..." ) return admin.edit_bot(bot, update, chat_data, to_edit) if not value: value = text if to_edit: if _is_clear_query(text): Suggestion.add_or_update(user, property_name, to_edit, None) else: Suggestion.add_or_update(user, property_name, to_edit, value) admin.edit_bot(bot, update, chat_data, to_edit) else: bot.formatter.send_failure(uid, "An unexpected error occured.")
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, e: if 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
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, 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
def register(): if session.get("username") != None: return redirect("/") session.clear() if request.method == "GET": return render_template("register.html") username = request.form.get("username") password = request.form.get("password") password1 = request.form.get("password1") email = request.form.get("email") if not username or not password or not email or not password1: return render_template( "register.html", register_error="Input in all fields marked with *.") if not validate_email(email): return render_template("register.html", register_error="Invalid Email Address") if not validate_password(password): return render_template( "register.html", register_error="Alpha-numeric Password Required") if password != password1: return render_template("register.html", register_error="Passwords Don't Match") if not validate_username(username): return render_template("register.html", register_error="Invalid Username") username = username.strip() password = password.strip() email = email.strip() user = User.query.filter_by(username=username).first() if user != None: return render_template("register.html", register_error="This Username already exists.") user = User.query.filter_by(email=email).first() if user != None: return render_template( "register.html", register_error="This Email is associated with another account.") password = generate_password_hash(password) code = str(random.randint(100000, 999999)) session["user_registration"] = { "username": username, "password": password, "email": email, "code": code } try: sendmail(email, "Verify Email", code) except: return redirect("/process_verification") return redirect("/verification")
email = validate_email(request.POST.get("email", ""), skip_if_this_user=request.user) except Exception, 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, 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, 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:
try: email = validate_email(request.POST.get("email", "")) except Exception, 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, e: errors["password"] = validation_error_message(e) username = None if REGISTRATION_ASK_USERNAME: try: username = validate_username(request.POST.get("username", "")) except Exception, e: errors["username"] = validation_error_message(e) if len(errors) == 0: if username or password: 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.") u.save() if email: