예제 #1
0
def home():
    form = RegistrationForm()
    if form.validate_on_submit():
        salt_pw = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(64)) + \
               form.password.data
        salt_api_key = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(64)) + \
               form.password.data
        form.password.data += salt_pw
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode("utf-8")
        user_id = models.User.query.limit(1).all()
        user_id[0] += 1
        api_key = user_id[0] + salt_pw + salt_api_key

        try:
            user = models.User(
                email=form.email.data, password=hashed_pw, address=form.address.data,
                api_key=api_key, salt_pw=salt_pw
            )

            db.session.add(user)
            db.session.commit()

            return flask.redirect(flask.url_for("test"))
        except:
            flask.flash("Some error occured", category="danger")
            return flask.redirect(flask.url_for("/"))

    return flask.render_template("index.html", footer_bg="white", form=form)
예제 #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
예제 #3
0
파일: server.py 프로젝트: Meri-em/Newsfeed
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        password = form.password.data
        if not db.find_user(username):
            db.add_user(username, password)
            return render_template('register.html', success=True)
        else:
            flash("Потребителското име вече е заето. Изберете ново")
            return render_template('register.html', form=form)
    return render_template('register.html', form=form)
    def _register(self):
        if current_user.is_authenticated:
            return redirect(url_for('index'))

        form = RegistrationForm()
        if form.validate_on_submit():
            usr = User(unicode(form.username.data), form.email.data,
                       form.password.data)
            sql_alchemy_db.session.add(usr)
            sql_alchemy_db.session.commit()
            return redirect(url_for('login'))

        return render_template('register.html', form=form)
예제 #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('blog'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form)
예제 #6
0
def register():
    form = RegistrationForm()
    if form.is_submitted():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(first_name=form.first_name.data,
                    second_name=form.last_name.data,
                    email=form.email.data,
                    password=hashed_password,
                    document_number=form.document_number.data,
                    dateOfBirth=form.dateOfBirth.data)
        db.session.add(user)
        db.session.commit()
        flash('Your account have been created, now You can log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title="Register", form=form)
예제 #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in.',
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
예제 #8
0
 def test_missing_email(self):
     json = {
         'username': '******',
         'password': '******',
         'confirm': 'password',
     }
     form = RegistrationForm.from_json(json)
     assert form.validate() is False
예제 #9
0
 def test_missing_confirm(self):
     json = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**'
     }
     form = RegistrationForm.from_json(json)
     assert form.validate() is False
예제 #10
0
파일: routes.py 프로젝트: Eriwi/noName
def register():
    form = RegistrationForm()
    if request.method == 'GET':
        return render_template('register.html', form=form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User(username=form.username.data, email=form.email.data)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            return jsonify({'message': 'You are now registered!'})
        else:
            msg = ""
            for fieldName, errorMessages in form.errors.items():
                for err in errorMessages:
                    msg += (fieldName + ": " + err + " ")
            return jsonify({'message': msg})
예제 #11
0
 def test_invalid_password_combination(self):
     json = {
         'username': '******',
         'password': '******',
         'confirm': 'WRONG',
         'email': '*****@*****.**'
     }
     form = RegistrationForm.from_json(json)
     assert form.validate() is False
예제 #12
0
    def test_valid(self):
        json = {
            'username': '******',
            'password': '******',
            'confirm': 'password',
            'email': '*****@*****.**'
        }

        form = RegistrationForm.from_json(json)
        assert (form.validate())
예제 #13
0
def home():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode("utf-8")

        try:
            user = User(
                email=form.email.data, password=hashed_pw, address=form.address.data
            )

            db.session.add(user)
            db.session.commit()

            flash("Your account has been successfully registered", category="success")

        except:
            flash("Some error occured", category="danger")

        finally:
            return redirect(url_for("home"))

    return render_template("index.html", footer_bg="white", form=form)
예제 #14
0
파일: views.py 프로젝트: kushagra1729/spc
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            # newdoc = Document(docfile = request.FILES['docfile'])
            form.save()
            print(request.POST['username'])
            os.mkdir(settings.MEDIA_ROOT + '/' + request.POST['username'])

            # Redirect to the document list after POST
            return redirect('upload')
    else:
        form = RegistrationForm()  # A empty, unbound form

    # Load documents for the list page

    # Render list page with the documents and the form
    return render(request, 'register/register.html', {'form_reg': form})