コード例 #1
0
def reg():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        surname = form.surname.data
        password = form.password.data
        confirm = form.confirm.data
        password_hash = generate_password_hash(password)
        user_model = UsersModel(users_db.get_connection())

        all_data = user_model.get_all()
        for x in all_data:
            if username == x[1]:
                return render_template(
                    'reg.html',
                    title='Регистрация',
                    form=form,
                    alert='Такой пользователь уже зареестрирован')

        exists = user_model.exists(username, password_hash)
        if not exists[0] and password == confirm:
            user_model.insert(username, name, surname, password_hash)
            exists = user_model.exists(username, password_hash)
            session['username'] = username
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('reg.html',
                           title='Регистрация',
                           form=form,
                           alert='')
コード例 #2
0
def register():
    form = RegForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        repassword = form.repassword.data
        content = form.content.data
        filename = secure_filename(content.filename)
        user_model = UsersModel(db.get_connection())
        print(user_name)
        exists = user_model.login_used(user_name)
        if exists:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form)
        else:
            if password == repassword:
                if os.path.isfile(os.path.join('static', 'img', filename)):
                    while os.path.isfile(
                            os.path.join('static', 'img', filename)):
                        filename = filename.split('.')
                        filename = '.'.join([filename[0] + 'A', filename[-1]])
                content.save(os.path.join('static', 'img', filename))
                user_model.insert(user_name, password, filename)
                exists = user_model.exists(user_name, password)
                session['username'] = user_name
                session['user_id'] = exists[1][0]
                session['content'] = exists[1][-1]
            else:
                return render_template('register.html',
                                       title='Регистрация',
                                       form=form)
        return redirect("/index")
    return render_template('register.html', title='Регистрация', form=form)
コード例 #3
0
def registration():
    if current_user.is_authenticated:
        flash('Вы уже числитесь нашим пользователем!', category='danger')
        return redirect(url_for('index'))
    form = RegForm()
    if form.validate_on_submit():
        if User.query.filter_by(
                username=form.username.data).first() is not None:
            flash('Имя пользователя занято', category='danger')
            return redirect(url_for('registration'))
        elif User.query.filter_by(email=form.email.data).first() is not None:
            flash('Такая почта уже используется', category='danger')
            return redirect(url_for('registration'))
        email = form.email.data
        confirmation_token = serializer.dumps(email, salt='token_email')
        user = User(username=form.username.data,
                    email=form.email.data,
                    status='user',
                    confirmed=False)
        user.set_password(form.password.data)
        update_session(user)
        msg = Message('Подтвердите вашу регистрацию',
                      sender='*****@*****.**',
                      recipients=[email])
        link = url_for('confirmation',
                       token=confirmation_token,
                       _external=True)
        msg.body = 'Перейдите по этой ссылке: {}'.format(link)
        mail.send(msg)
        flash('Пожалуйста, подтвердите вашу почту', category='primary')
        return redirect(url_for('login'))
    for errors in form.errors.values():
        for error in errors:
            flash(error, category='danger')
    return render_template('registration.html', form=form, title='Регистрация')
コード例 #4
0
def registration():
    if current_user.is_authenticated:
        flash('Already logged in', category='danger')
        return redirect(url_for('index'))
    form = RegForm()
    if form.validate_on_submit():
        if User.query.filter_by(username=form.username.data).first() is not None:
            flash('Username is busy', category='danger')
            return redirect(url_for('registration'))
        elif User.query.filter_by(email=form.email.data).first() is not None:
            flash('Email is busy', category='danger')
            return redirect(url_for('registration'))
        email = form.email.data
        confirmation_token = serializer.dumps(email, salt='token_email')
        user = User(username=form.username.data, email=form.email.data, status='user', confirmed=False)
        user.set_password(form.password.data)
        update_session(user)
        msg = Message('Confirm your account on converter', sender='*****@*****.**',
                      recipients=[email])
        link = url_for('confirmation', token=confirmation_token, _external=True)
        msg.body = 'Click on this link: {}'.format(link)
        mail.send(msg)
        flash('Please, confirm your email.', category='primary')
        return redirect(url_for('login'))
    for errors in form.errors.values():
        for error in errors:
            flash(error, category='danger')
    return render_template('registration.html', form=form, title='Registration')
コード例 #5
0
ファイル: testPost.py プロジェクト: mespases/testPost
def register():
    global usuario
    form = RegForm(request.form)
    if form.validate():
        if not existenciaUsuario(form):
            hash_pass = generate_password_hash(form.password.data)
            usuario = User(form.email.data, hash_pass, form.role.data)
            login_user(usuario)
            return redirect('/table', code=302)
        else:
            print "El usuario ya existe"
    else:
        print form.validate()

    return render_template('register.html', form=form)
コード例 #6
0
class Registration(Resource):
    def __init__(self):
        super().__init__()
        self.form = RegForm()

    def get(self):
        return make_response(
            render_template('registration.html',
                            titile='registration',
                            form=self.form))

    def post(self):
        if self.form.validate_on_submit():
            res = Users.query.filter_by(
                username=self.form.username.data).first()
            if res is None:
                if self.form.password_validate.data != self.form.password.data:
                    flash('Password validating failed', category='danger')
                    return redirect('/registration')
                user = Users(username=self.form.username.data,
                             status='user',
                             active=True,
                             name=self.form.name.data,
                             surname=self.form.surname.data,
                             patronymic=self.form.patronymic.data)
                user.set_password(self.form.password.data)
                db.session.add(user)
                db.session.commit()
                flash('Successful!', category='success')
                return redirect('/login')
            flash('Account already exists', category='danger')
        return redirect('/registration')
コード例 #7
0
ファイル: server.py プロジェクト: aN1xx/Forum
def reg():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        surname = form.surname.data
        password = form.password.data
        confirm = form.confirm.data
        password_hash = generate_password_hash(password)
        user_model = UsersModel(users_db.get_connection())
        exists = user_model.exists(username, password_hash)
        if not exists[0] and password == confirm:
            user_model.insert(username, name, surname, password_hash)
            exists = user_model.exists(username, password_hash)
            session['username'] = username
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('reg.html', title='Sign up', form=form)
コード例 #8
0
ファイル: main.py プロジェクト: GovardFilipsovich/Site
def reg():
    form = RegForm()
    if form.validate_on_submit() and form.check_password() and form.check_user(
    ) == None:
        user = User()
        user.name = form.username.data
        user.password = sha256(form.password.data.encode('utf-8')).hexdigest()
        db_sess = db_session.create_session()
        db_sess.add(user)
        db_sess.commit()
        return redirect(f'/{form.username.data}/')
    elif form.check_user() != None:
        flash(u"Такой пользователь уже есть", "error")
    elif form.check_password() is False:
        flash(u"Не совпадают пароли", "error")
    return render_template('registration.html', title='Авторизация', form=form)
コード例 #9
0
 def __init__(self):
     super().__init__()
     self.form = RegForm()