def reqister(): """ Обработка регистрации :return: форма регистрации """ form = RegisterForm() if form.validate_on_submit(): if form.password.data != form.password_again.data: return render_template('register.html', title='Регистрация', form=form, message="Пароли не совпадают") db_sess = db_session.create_session() if db_sess.query(User).filter(User.email == form.email.data).first(): return render_template('register.html', title='Регистрация', form=form, message="Такой пользователь уже есть") user = User( nickname=form.nickname.data, name=form.name.data, email=form.email.data, about=form.about.data, ) user.set_password(form.password.data) db_sess.add(user) db_sess.commit() return redirect('/login') return render_template('register.html', title='Регистрация', form=form)
def reqister(): form = RegisterForm() if form.validate_on_submit(): if form.password.data != form.password_again.data: return render_template('register.html', title='Регистрация', form=form, message="Password mismatch") db_sess = db_session.create_session() if db_sess.query(User).filter(User.email == form.email.data).first(): return render_template('register.html', title='Регистрация', form=form, message="This user already exists") user = User( surname=form.surname.data, name=form.name.data, age=form.age.data, position=form.position.data, speciality=form.speciality.data, address=form.address.data, email=form.email.data, ) user.set_password(form.password.data) db_sess.add(user) db_sess.commit() return redirect('/login') return render_template('register.html', title='Register Form', form=form)
def reqister(): global user, back form = RegisterForm() if form.validate_on_submit(): db_sess = db_session.create_session() if db_sess.query(User).filter(User.email == form.email.data).first(): return render_template('register.html', title='Sign up', form=form, message="This email is already exists") if db_sess.query(User).filter( User.username == form.username.data).first(): return render_template('register.html', title='Sign up', form=form, message="This name is already exists") if "@" not in form.email.data and len(form.email.data): return render_template('register.html', title='Sign up', form=form, message="This email is already exists") user = User(username=form.username.data, email=form.email.data, month_of_birth=form.month.data, day_of_birth=form.day.data, year_of_birth=form.year.data, country=form.country.data) back = '/register' return redirect('/send_verification') return render_template('register.html', title='Sign up', form=form)
def register(): if 'username' not in session: return redirect(request.referrer) form = RegisterForm() if form.validate_on_submit(): name = form.username.data password = form.password.data exists = Database.user_exists(name) if not exists: user = User(name, password) if session.get('access'): user.make_user_admin() Database.insert_user(user) return redirect('/') else: flash("Username already taken!", 'userTakenMsg') return redirect('/register') return render_template('register.html', title='Register', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): if form.password.data != form.password_again.data: return render_template('register.html', title='Регистрация', form=form, message="Пароли не совпадают") if len(form.password.data) < 5: return render_template( 'register.html', title='Регистрация', form=form, message="Пароль должен содержать 5 и более символов") if len(form.uniq_name.data) < 3: return render_template( 'register.html', title='Регистрация', form=form, message="Ник должен содержать 3 и более символов") db_sess = db_session.create_session() if db_sess.query(User).filter( User.uniq_name == form.uniq_name.data).first(): return render_template('register.html', title='Регистрация', form=form, message="Такой пользователь уже есть") if form.vk_id.data: if db_sess.query(User).filter( User.vk_id == form.vk_id.data).first(): return render_template('register.html', title='Регистрация', form=form, message="Такой vk_id уже есть") if form.vk_id.data.isdigit(): vk_id = requests.get(f'https://vk.com/id{form.vk_id.data}') else: vk_id = requests.get(f'https://vk.com/{form.vk_id.data}') if not vk_id: return render_template('register.html', title='Регистрация', form=form, message="Такой vk_id не существует") user = User() user.uniq_name = form.uniq_name.data user.about = form.about.data user.vk_id = form.vk_id.data if form.vk_id.data else None user.name = form.name.data if form.name.data else form.uniq_name.data user.set_password(form.password.data) user.profile_picture = user.conver_to_binary( fr'{os.getcwd()}\static\img\default_image.jpg') db_sess.add(user) db_sess.commit() login_user(user, remember=form.remember_me.data) return redirect('/register/load_photo') return render_template('register.html', title='Reg', form=form)
def post_register(): form = RegisterForm() if form.validate_on_submit(): email_hash = md5.new(form.email.data.strip().lower()).hexdigest() user = User(email=form.email.data, email_hash=email_hash) user.password = generate_password_hash(form.password.data) user.registered = True ''' # Create a stripe customer stripe.api_key = app.config['STRIPE_SECRET_KEY'] customer = stripe.Customer.create(email=user.email) user.stripe_id = customer.id ''' user.save() login_user(user) flash("Successfully registered") return redirect(url_for("index")) return render_template('register.html', form=RegisterForm())
def signup(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): fname = form.fname.data lname = form.lname.data email = form.email.data cnumber = form.cnumber.data address = form.address.data password = sha256_crypt.encrypt(str(form.password.data)) val = (fname, lname, cnumber, email, address, password) # Create cursor cur = mysql.connection.cursor() # Execute query cur.execute( "INSERT INTO user_registration(firstname, lastname, contactno, email, address, password) VALUES(%s, %s, %s, %s, %s, %s)", val) # Commit to DB mysql.connection.commit() # Close connection cur.close() flash('You are now registered', 'success') return redirect(url_for('home')) return render_template('signup2.html', form=form)
def user(id): db_sess = db_session.create_session() user = db_sess.query(User).get(id) if not user: return redirect('/') edit = False register_form = RegisterForm() if request.method == 'POST': if request.form.get('set_admin'): user.lvl = 1 if int(request.form['set_admin']) else 2 db_sess.commit() elif request.form.get('ban_user'): user.is_banned = bool(int(request.form['ban_user'])) user.lvl = 2 db_sess.commit() elif request.form.get('delete_user'): for discussion in user.discussions: delete_discussion(discussion.id, db_sess) for forum in user.forums: delete_forum(forum.id, db_sess) if user.profile_picture_name != 'default_image.jpg': os.remove(f'static/img/{user.profile_picture_name}') db_sess.delete(user) db_sess.commit() return redirect('/') elif request.form.get('edit_user'): register_form.name.data = user.name register_form.uniq_name.data = user.uniq_name register_form.about.data = user.about register_form.vk_id.data = user.vk_id if user.vk_id else '' register_form.password_again.data = 'no matter' edit = True elif request.form.get('delete_discussion'): delete_discussion(request.form['delete_discussion'], db_sess) edit = True elif request.form.get('delete_forum'): delete_forum(request.form['delete_forum'], db_sess) edit = True elif request.form.get('submit'): edit = True if len(register_form.uniq_name.data) < 3: return render_template( 'user.html', user=user, max=max, len=len, edit=edit, register_form=register_form, message="Ник должен содержать 3 и более символов") another_user = db_sess.query(User).filter( User.uniq_name == register_form.uniq_name.data).first() if another_user and another_user.id != user.id: return render_template('user.html', user=user, max=max, len=len, edit=edit, register_form=register_form, message="Такой пользователь уже есть") if register_form.vk_id.data: another_user = db_sess.query(User).filter( User.vk_id == register_form.vk_id.data).first() if another_user and another_user.id != user.id: return render_template( 'user.html', user=user, max=max, len=len, edit=edit, register_form=register_form, message="Пользователь с таким VK_id уже есть") if register_form.vk_id.data.isdigit(): vk_id = requests.get( f'https://vk.com/id{register_form.vk_id.data}') else: vk_id = requests.get( f'https://vk.com/{register_form.vk_id.data}') if not vk_id: return render_template('user.html', user=user, max=max, len=len, edit=edit, register_form=register_form, message="Такой vk_id не существует") if not user.check_password(register_form.password.data): return render_template('user.html', user=user, max=max, len=len, edit=edit, register_form=register_form, message='Неверный пароль') user.name = register_form.name.data if register_form.name.data else register_form.uniq_name.data user.uniq_name = register_form.uniq_name.data user.about = register_form.about.data user.vk_id = register_form.vk_id.data if register_form.vk_id.data else None db_sess.commit() edit = False return render_template('user.html', user=user, max=max, len=len, edit=edit, register_form=register_form)
def register(): form = RegisterForm() if form.validate_on_submit(): return 'success' return render_template('RegisterTemplate.html', form=form, title='Register')