def add_user_ajax(): # вытаскиваем данные с полученной формы login = request.form.get('login') password = request.form.get('password') fio = request.form.get('fio') user_type = request.form.get('user_type') # хешируем пароль hash_pwd = generate_password_hash(password) # проверка заполненности полей if not (login and password and fio): return jsonify({'error': 'Все поля должны быть заполнены'}) # отловщик ошибок try: # создание объекта User user = User(login=login, password=hash_pwd, fio=fio, type=user_type) user.fio = fio user.type = user_type db.session.add(user) db.session.commit() return jsonify({'success': f'Успешно добавлен: {fio}'}) # если поймалась ошибка, то выполняется этот блок except: return jsonify({'error': 'Что то пошло не так, попробуйте позже'})
def register(): login = request.form.get('login') password = request.form.get('password') password2 = request.form.get('password2') pass_img = request.form.get('pass_img') if request.method == 'POST': if not (login or password or password2): flash('Пожалуйста, заполните поля') elif password != password2: flash('Пароли не совпадают') else: user = User.query.filter_by(login=login).first() if user is None: hash_pwd = generate_password_hash(password) passImg = module.make_mass(pass_img) zone = '' probability = '' for i in range(50): probability += str(random.randint(22, 30)) + ',' zone += str(module.gen_zone(passImg)) + ',' zone = zone[0:-1] probability = probability[0:-1] new_user = User(login=login, password=hash_pwd, pass_img=pass_img, banned=0, zone=zone, probability=probability) db.session.add(new_user) db.session.commit() return redirect(url_for('firstFactor')) else: flash('Такой пользователь уже существует') return render_template('register.html')
def register(): login = request.form.get('login') password = request.form.get('password') password2 = request.form.get('password2') if request.method == 'POST': if not (login or password or password2): flash('Please, fill all fields!') elif password != password2: flash('Passwords are not equal!') else: hash_pwd = generate_password_hash(password) new_user = User(login=login, password=hash_pwd) db.session.add(new_user) db.session.commit() return redirect(url_for('login_page')) return render_template('register.html')
def register(): login = request.form.get('login') password = request.form.get('password') password2 = request.form.get('password2') if request.method == 'POST': if not (login or password or password2): flash('Пожалуйста заполните все поля') elif password != password2: flash('Пароль и проверка пароля не совпадают') else: hash_pwd = generate_password_hash(password) new_user = User(login=login, password=hash_pwd) db.session.add(new_user) db.session.commit() return redirect(url_for('login_page')) flash('Укажите логин и пароль') return render_template('register.html')
def registration(): if request.method == 'GET': return render_template('registration.html') else: try: login = request.form['login'].title() if User.query.filter_by(login=login).first() is not None: return json.dumps({ 'status':'fall', 'message':'The login is busy' }) # email = request.form['email'] # if User.query.filter_by(email=email).first() is not None: # return json.dumps({ # 'status':'fall', # 'message':'The email is busy' # }) if request.form['password'] != request.form['password_confirm']: return json.dumps({ 'status':'fall', 'message':'Pass1 must be == Pass2' }) # If success user = User(login=login,email='*****@*****.**'%login,password=request.form['password']) db.session.add(user) db.session.commit() return json.dumps({ 'status':'success', 'message':'Аккаунт успешно создан!' }) except Exception as e: print("Error is ", e) return json.dumps({ 'status':'fail', 'message':'Неизвестная ошибка сервера. Попробуйте снова' })
def register(): login = request.form.get('login') email = request.form.get('email') password = request.form.get('password') password2 = request.form.get('password2') pattern_login = re.compile('[a-zA-Z0-9_а-щыэ-яА-ЩЫЭ-Я]+$', re.UNICODE) # pattern_email = re.compile(r"^[\w\.\+\-]+\@[\w]+\.[az]{2,3}$") pattern_email = re.compile(r"([\w\.-]+)@([\w\.-]+)(\.[\w\.]+)") if login and email: flash('Please, enter either login or email') return render_template('register.html') if password: if len(password) < 8: flash('Password characters too few!') return redirect(url_for('register')) if login: if bool(pattern_login.match(login)) is False: flash('Login has special characters!') return redirect(url_for('register')) if request.method == 'POST': if not (login or password or password2): flash('Please, fill all fields!') elif password != password2: flash('Passwords are not equal!') else: hash_pwd = generate_password_hash(password) new_user = User(login=login, password=hash_pwd) if User.query.filter_by(login=login).first( ) is not None: # Пров-ем в БД создан-ли юзер под этим логом flash('A user with this login is already registered!') return redirect(url_for('register')) else: db.session.add(new_user) db.session.commit() return redirect(url_for('login_page')) elif email: if bool(pattern_email.match(email)) is False: flash('Email has not correct!') return redirect(url_for('register')) if request.method == 'POST': if not (email or password or password2): flash('Please, fill all fields!') elif password != password2: flash('Passwords are not equal!') else: hash_pwd = generate_password_hash(password) new_user = User(email=email, password=hash_pwd) if User.query.filter_by(email=email).first( ) is not None: # Пров-ем в БД создан-ли юзер под этим мылом flash('A user with this email is already registered!') return redirect(url_for('register')) else: db.session.add(new_user) db.session.commit() return redirect(url_for('login_page')) return render_template('register.html')