Exemple #1
0
def signup():
    form = user_forms.SignUp()
    if form.validate_on_submit():
        # Create a user who hasn't validated his email address
        user = models.User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            phone=form.phone.data,
            email=form.email.data,
            confirmation=False,
            password=form.password.data,
        )
        # Insert the user in the database
        db.session.add(user)
        db.session.commit()
        # Subject of the confirmation email
        subject = 'Please confirm your email address.'
        # Generate a random token
        token = ts.dumps(user.email, salt='email-confirm-key')
        # Build a confirm link with token
        confirmUrl = url_for('userbp.confirm', token=token, _external=True)
        # Render an HTML template to send by email
        html = render_template('email/confirm.html', confirm_url=confirmUrl)
        # Send the email to user
        email.send(user.email, subject, html)
        # Send back to the home page
        flash('Check your emails to confirm your email address.', 'positive')
        return redirect(url_for('index'))
    return render_template('user/signup.html', form=form, title='Sign up')
Exemple #2
0
def signup():
    form = user_forms.SignUp()
    if form.validate_on_submit():
        # Create a user who hasn't validated his email address
        user = models.User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            phone=form.phone.data,
            email=form.email.data,
            confirmation=False,
            password=form.password.data,
        )
        # Insert the user in the database
        db.session.add(user)
        db.session.commit()
        # Subject of the confirmation email
        subject = 'Please confirm your email address.'
        # Generate a random token
        token = ts.dumps(user.email, salt='email-confirm-key')
        # Build a confirm link with token
        confirmUrl = url_for('userbp.confirm', token=token, _external=True)
        # Render an HTML template to send by email
        html = render_template('email/confirm.html', confirm_url=confirmUrl)
        message = Mail(from_email='*****@*****.**',
                       to_emails=user.email,
                       subject=subject,
                       html_content=render_template('email/confirm.html',
                                                    confirm_url=confirmUrl))
        try:
            sg = SendGridAPIClient(
                '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'
            )
            response = sg.send(message)
            print(response.status_code)
            print(response.body)
            print(response.headers)
        except Exception as e:
            print(e.message)
        #Send the email to user
        # try:
        #     #email.send(user.email, subject, html)
        #     print("email sent")
        # except SMTPException as e:
        #     print("can not send email")

        # Send back to the home page
        flash('Please confirm your email address.', 'positive')
        return redirect(url_for('userbp.signin'))
    return render_template('user/signup2.html', form=form, title='Sign up')
Exemple #3
0
def signup():
    ''' Render signup for to register user
    and insert entry in database '''
    form = user_forms.SignUp()
    mapping = {
        q.user_name: int(q.id)
        for q in models.InstaInfluencer.query.with_entities(
            models.InstaInfluencer.user_name,
            models.InstaInfluencer.id).distinct()
    }
    form.insta_influencers.choices = [(k, k) for k, v in mapping.items()]
    if form.validate_on_submit():
        # Create a user who hasn't validated his email address
        user = models.User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            phone=form.phone.data,
            email=form.email.data,
            confirmation=False,
            _password=form.password.data,
        )

        # Insert the user in the database
        db.session.add(user)
        db.session.commit()
        for ids in form.insta_influencers.data:
            if_id = mapping[ids]
            insta_map = models.UserInfluencerMap(user_email=form.email.data,
                                                 influencer_id=int(if_id))
            db.session.add(insta_map)
        db.session.commit()
        # Subject of the confirmation email
        # subject = 'Please confirm your email address.'
        # Generate a random token
        # token = ts.dumps(user.email, salt='email-confirm-key')
        # Build a confirm link with token
        # confirmUrl = url_for('userbp.confirm', token=token, _external=True)
        # Render an HTML template to send by email
        # html = render_template('email/confirm.html',
        #                       confirm_url=confirmUrl)
        # Send the email to user
        # email.send(user.email, subject, html)
        # Send back to the home page
        # flash('Check your emails to confirm your email address.', 'positive')
        return redirect(url_for('product'))
    return render_template('user/signup2.html', form=form, title='Sign up')
Exemple #4
0
def signup():
    form = user_forms.SignUp()
    if form.validate_on_submit():
        # Create a user who hasn't validated his email address
        user = models.User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            #            phone=form.phone.data,
            email=form.email.data,
            confirmation=False,
            password=form.password.data)

        # Create a ldap_user
        ldap_user = {
            'objectClass': ['inetOrgPerson', 'posixAccount', 'top'],
            'givenName': user.first_name,
            'sn': user.last_name,
            'gidNumber': 500,
            'uidNumber': random.randint(1000, 1000000),
            'uid': user.email.split('@', 1)[0],
            'homeDirectory': '/home/users/' + user.email.split('@', 1)[0],
            'userPassword': form.password.data
        }

        user_ldap_dn = 'cn=' + ldap_user['uid'] + ',ou=Users,dc=ldap,dc=com'
        # Insert the user in the database
        db.session.add(user)
        # Add user in LDAP
        try:
            c = Connection(s,
                           user=app.config['LDAP_SERVICE_USERNAME'],
                           password=app.config['LDAP_SERVICE_PASSWORD'])
            c.open()
            c.start_tls()
            c.bind()
            c.add(user_ldap_dn, attributes=ldap_user)
        except Exception as e:
            # remove the user from the db session
            print(e)
            db.session.rollback()
            db.session.commit()
            logger.error('User account creation failed', user=user.get_id())
            flash(
                'There was an error in creating your account, if the issue persists, '
                'please contact and administrator.', 'negative')
            return redirect(url_for('index'))
        logger.info('User account created successfully', user=user.get_id())
        # If there was no error in adding user via LDAP we will commit the session to the database
        c.unbind()
        db.session.commit()
        # Subject of the confirmation email
        subject = 'Please confirm your email address.'
        # Generate a random token
        token = ts.dumps(user.email, salt='email-confirm-key')
        # Build a confirm link with token
        confirmUrl = url_for('userbp.confirm', token=token, _external=True)
        # Render an HTML template to send by email
        html = render_template('email/confirm.html', confirm_url=confirmUrl)
        # Send the email to user
        email.send(user.email, subject, html)
        # Send back to the home page
        flash('Check your emails to confirm your email address.', 'positive')
        return redirect(url_for('index'))
    return render_template('user/signup.html', form=form, title='Sign up')
Exemple #5
0
def signup():
    print('sign up page opened')
    form = user_forms.SignUp()
    return render_template('user/signup.html', form=form, title='Sign up')