Beispiel #1
0
def register():
    form = RegistrationForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            try:
                hash_password = bcrypt.generate_password_hash(
                    form.password.data).decode('utf-8')
                new_user = User(form.username.data, form.firstname.data,
                                form.surname.data, form.sex.data,
                                form.email.data, form.address.data,
                                form.phone.data, form.phone2.data,
                                hash_password)
                new_user.authenticated = True
                db.session.add(new_user)
                db.session.commit()
                login_user(new_user)
                send_confirmation_email(new_user.email)
                flash(
                    'Thanks for registering!  Please check your email to confirm your email address.',
                    'success')
                return redirect(url_for('users.unconfirmed'))
            except IntegrityError:
                db.session.rollback()
                flash(
                    'ERROR! Email ({}), Username({}) already exists.'.format(
                        form.email.data, form.username.data), 'error')
    return render_template('register.html', title='Register', form=form)
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(name=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return redirect(url_for('home.home'))
    return render_template('register.html', form=form)
Beispiel #3
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        user = User (email= form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        
        db.session.add(user)
        db.session.commit()
        flash("Thanks for registration", "success")
        return redirect(url_for('users.login'))
    return render_template('register.html', form=form)
Beispiel #4
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(mobile=form.mobile.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        account_sid = os.environ['TWILIO_ACCOUNT_SID']
        auth_token = os.environ['TWILIO_AUTH_TOKEN']
        client = Client(account_sid, auth_token)
        message = client.messages.create(
            body='Hi there! Thanks for registering!!',
            from_='whatsapp:+14155238886',
            to='whatsapp:' + form.mobile.data)
        return redirect(url_for("users.login"))
    return render_template("register.html", form=form)
Beispiel #5
0
def register():
    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)

        db.session.add(user)
        db.session.commit()
        flash('Thanks for registration!')
        return redirect(url_for('users.login'))

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

    #if the login is not valid send them back to registration page
    return render_template(url_for('register.html', form=form))
Beispiel #6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("main.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(u'Your account has been created! You are now able to log in!',
              "success")
        return redirect(url_for('users.login'))
    return render_template("register.html", title="Register Page", form=form)
Beispiel #7
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        if not User.query.filter_by(email=form.email.data).first() and\
            not User.query.filter_by(email=form.username.data).first():
            user = User(email=form.email.data,
                        username=form.username.data,
                        password=form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('注册成功!')
            return redirect(url_for('users.register'))
            
        else:
            flash('用户已经存在!')
            return redirect(url_for('users.register'))
    return render_template('register.html',form=form)
Beispiel #8
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(f'Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template(
        'register.html', title='Register',
        form=form)  # Passamos a instância da form para o nosso template
Beispiel #9
0
def register():

    # Defining a variable equal to a form
    form = RegistrationForm()

    # Checking if form is valid
    if form.validate_on_submit():

        try:
            print('user')

            # Running auth function
            createUser = createUserFunc(form.email.data, form.password.data,
                                        form.firstname.data,
                                        form.lastname.data)
            print(createUser)
            print('aaaa')
            user = createUser[1]
            uid = user['localId']
            emailDict = {"email": form.email.data, "uid": uid}
            token = safeTimedUrlSerializer.dumps(emailDict,
                                                 salt='email-confirm')

            # Sending email
            link = url_for('users.confirmEmail', token=token, _external=True)
            send = sendEmailVerified(form.email.data, link)

            # Getting returned data
            returnedData = createUser
            print('aaaa')
            email = returnedData[0]['email']
            firstname = returnedData[0]['firstname']
            lastname = returnedData[0]['lastname']

            # Alerting user account was created
            flash(
                f'Email Confirmation Sent to {form.email.data} ! If not seen in your inbox check junk mail.',
                'success')
            return redirect(url_for('users.login'))
        except Exception as e:
            print(e)
            flash(f'Failed to Create Account')

    return render_template('users/register.html', title='Register', form=form)
Beispiel #10
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.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,
                    firstName=form.firstName.data,
                    middleName=form.middleName.data,
                    lastName=form.lastName.data,
                    address=form.address.data,
                    phone=form.phone.data,
                    doctor=form.doctor.data,
                    drLicenseNum=form.drLicenseNum.data,
                    dateOfBirth=form.dateOfBirth.data,
                    gender=form.gender.data,
                    ssn=form.ssn.data,
                    race=form.race.data,
                    emergencyName=form.emergencyName.data,
                    emergencyRelation=form.emergencyRelation.data,
                    emergencyAddress=form.emergencyAddress.data,
                    emergencyPhone=form.emergencyPhone.data,
                    majorSurgery=form.majorSurgery.data,
                    smoking=form.smoking.data,
                    confirmed=False)
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('users.confirm_email',
                              token=token,
                              _external=True)
        html = render_template('user/activate.html',
                               confirm_url=confirm_url,
                               user=user)
        subject = "Confirm Email"
        send_email('*****@*****.**', subject, html)
        flash(
            'Your account has been created! Please wait till we verify your account',
            'success')
        return redirect(url_for('users.unconfirmed'))
    return render_template('register.html', title='Register', form=form)
Beispiel #11
0
def register():

    # Defining a variable equal to a form
    form = RegistrationForm()

    # Checking if form is valid
    if form.validate_on_submit():

        # Defining variables equal to post request paramaters
        url = "http://localhost:8000/create-user"
        data = {
            'firstname': form.firstname.data,
            'lastname': form.lastname.data,
            'email': form.email.data,
            'password': form.password.data
        }

        try:
            # Sending data to API
            getData = requests.post(url=url, json=data)

            # Getting returned data
            returnedData = getData.json()
            email = returnedData[0]['email']
            firstname = returnedData[0]['firstname']
            lastname = returnedData[0]['lastname']

            # Storing returned data
            session['user'] = returnedData[1]
            session['name'] = str(firstname) + " " + str(lastname)
            session['email'] = email

            # Alerting user account was created
            flash(f'Account Created for {form.email.data} !', 'success')
            return redirect(url_for('dashboard.home'))
        except Exception as e:
            print(e)
            flash(f'Failed to Create Account')

    return render_template('users/register.html', title='Register', form=form)
Beispiel #12
0
def signup():
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        # Register form is valid, check if username already in db
        # if form.username.data in [row[0] for row in db.session.query(RegisteredUser.username).all()]:
        #     error = 'This username exists!'
        #     return render_template('signup.html', form=form, error=error)

        # Add a new user, the user id is the current max(user.id) + 1
        try:
            cur_max_id = db.session.query(RegisteredUser.id).order_by(
                desc(RegisteredUser.id)).all()[0][0]
        except IndexError:  # If it's an empty table
            cur_max_id = 0

        db.session.add(
            RegisteredUser(cur_max_id + 1, form.username.data,
                           form.password.data, form.email.data))
        db.session.commit()
        flash('Thanks for signing up')
        return redirect(url_for('home.home'))

    return render_template('signup.html', form=form, error=form.errors)