Exemple #1
0
def register():
    form = RegisterForm(request.form)

    if request.method == 'POST' and form.validate():

        user = User.query.filter_by(email=form.email.data).first()

        if user is None:
            user = User(username=form.username.data,
                        email=form.email.data,
                        password=sha256_crypt.encrypt(str(form.password.data)),
                        registeredAt=datetime.now(),
                        confirmed=False)
            db.session.add(user)
            db.session.commit()

            user_settings = Setting(ageGap=2,
                                    searchDistance=30,
                                    settingsEdited=False)
            db.session.add(user_settings)
            db.session.commit()

            user_profile = Profile(fullname=form.name.data,
                                   firstName=form.name.data.split()[0],
                                   surname=' '.join(
                                       form.name.data.split()[1:]),
                                   username=form.username.data,
                                   profileEdited=False)
            db.session.add(user_profile)
            db.session.commit()

            token = s.dumps(form.email.data)

            msg = Message('Confirm your Email! :)',
                          recipients=[form.email.data])
            link = url_for('confirmed', token=token, _external=True)
            msg.body = f"Your confirmation link is: {link}"
            mail.send(msg)

            return redirect(url_for('confirm_email'))

        else:
            flash("Email or Username already being used!")

    return render_template('register.html', form=form)
Exemple #2
0
def register_handle():
    form=RegisterForm(request.form)
    if request.method=="POST" and form.validate():
        stat = check_user(request.form['username'])
        if stat==True:
            flash("This username already taken")
            return redirect(url_for("register_handle"))
        else:

            username=request.form['username']
            email =request.form['email']
            password= request.form['pswd']
            first_name =request.form['firstname']
            last_name = request.form['lastname']
            print("dfghjkl")
            print("fffff",username, password, email, first_name, last_name)
            add_user(password,username,email,first_name,last_name)

            flash("welcome"+username)
            session['logged_in'] = True
            session['username'] = username
            return redirect(url_for("dashboard"))

    return render_template("register.html", form=form)