コード例 #1
0
def register():
    """Register a new user, and send them a confirmation email."""
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegistrationForm()
    if form.validate_on_submit():

        # Implement Password Confirmations
        user = User(
            username=form.username.data,
            key=form.key.data,
            email=form.email.data,
            password=form.password.data,
            confirmed=True)
        # Confirmed is True as default

        db.session.add(user)
        db.session.commit()
        # Email Confirmation
        # token = user.generate_confirmation_token()
        # confirm_link = url_for('account.confirm', token=token, _external=True)
        # get_queue().enqueue(
        #     send_email,
        #     recipient=user.email,
        #     subject='Confirm Your Account',
        #     template='account/email/confirm',
        #     user=user,
        #     confirm_link=confirm_link)
        # flash('A confirmation link has been sent to {}.'.format(user.email),
        #       'warning')
        flash(Markup('Registration Completed<br> Please sign in by clicking <a href="' +
                     url_for('account.login')+'">here</a>'))
        return redirect(url_for('account.register'))
    return render_template('account/register.html', form=form)
コード例 #2
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        is_invited = User.query.filter_by(email=form.email.data).first()
        if is_invited is not None:
            if is_invited.password is None:
                user = User(first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            email=form.email.data,
                            password=form.password.data)
                db.session.add(user)
                db.session.commit()
                token = user.generate_confirmation_token()
                confirm_link = url_for('account.confirm',
                                       token=token,
                                       _external=True)
                status = send_email(recipient=user.email,
                                    subject='Confirm Your Account',
                                    template='account/email/confirm',
                                    user=user,
                                    invite_link=confirm_link)
                flash(
                    'A confirmation link has been sent to {}.'.format(
                        user.email), 'warning')
                return redirect(url_for('main.index'))

    if request.method == 'POST':
        flash(
            'Sorry, you are only allowed to register if you have been invited '
            'by the administrator.', 'form-error')

    return render_template('account/register.html', form=form)
コード例 #3
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data,
            vcpu_limit=form.vcpu_limit.data,
            memory_limit=form.memory_limit.data,
        )
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for("account.confirm", token=token, _external=True)
        user.__dict__.pop("storage_files")
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject="Confirm Your Account",
            template="account/email/confirm",
            user=user,
            confirm_link=confirm_link,
        )
        flash("A confirmation link has been sent to {}.".format(user.email),
              "warning")
        return redirect(url_for("main.index"))
    return render_template("account/register.html", form=form)
コード例 #4
0
ファイル: views.py プロジェクト: Alvin0113/LuoYunCloud
    def post(self):

        form = RegistrationForm(self.request.arguments)

        if form.validate():

            user = self.db2.query(User).filter_by( username=form.username.data ).all()

            if user:
                form.username.errors.append( _('This username is occupied') )
            else:
                salt = md5(str(random.random())).hexdigest()[:12]
                hsh = encrypt_password(salt, form.password.data)
                enc_password = "******" % (salt, hsh)

                newuser = User( username = form.username.data,
                                password = enc_password )
                self.db2.add(newuser)
                self.db2.commit()
                # Create profile
                profile = UserProfile(newuser, email = form.email.data)
                self.db2.add(profile)
                self.db2.commit()

                # send_mail()
                self.save_session(newuser.id)

                url = self.application.reverse_url('account:index')
                return self.redirect( url )

        # Have a error
        self.render( 'account/register.html', form = form )
コード例 #5
0
def register():
    """Register a new user, and send them a confirmation email."""
    # Prefill email from landing page
    if request.args.get('email'):
        form = RegistrationForm(request.args)
    else:
        form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            name=form.name.data,
            email=form.email.data,
            password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        flash('A confirmation link has been sent to {}.'.format(user.email), 'warning')
        send_email(
            recipient=form.email.data,
            subject='Confirm Your Account',
            template='account/email/confirm',
            user_name=form.name.data,
            confirm_link=confirm_link
        )
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
コード例 #6
0
def register(subscription=enum.Subscriptions.PERSONAL.value):
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = db_service.register_new_user(
            form.first_name.data, form.last_name.data, form.email.data,
            form.password.data, form.terms_agree.data, subscription)
        token = db_service.generate_confirmation_token(user)
        confirm_link = url_for('account.confirm', token=token, _external=True)

        send_email(recipient=user.email,
                   subject='Confirm Your Account',
                   template='account/email/confirm',
                   user=user,
                   confirm_link=confirm_link)

        send_email(recipient='*****@*****.**',
                   subject='Stock Score Server: new account registered',
                   template='account/email/new_account_registered',
                   user=user)

        flash(f'A confirmation link has been sent to {user.email}.', 'warning')
        url = account_login(form.email.data, form.password.data, True, request)
        if url:
            return redirect(request.args.get('next') or url_for(url))
    return render_template('account/register_new.html',
                           subscription=subscription,
                           form=form)
コード例 #7
0
ファイル: routes.py プロジェクト: pete-sk/password-manager
def register():
    title = 'Create an account'

    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data.lower()
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        master_key = generate_pswrd(length=32, special=False)
        encrypted_master_key = encrypt(get_key(form.password.data), master_key)
        user = User(email=email, password=hashed_password, master_key=encrypted_master_key)

        try:
            send_activation_email(user)
            flash('Account created! Verification link has been sent to your email.', 'success')
        except SMTPRecipientsRefused:
            flash('Entered email address is invalid!', 'danger')
            return redirect(url_for('account.register'))
        except:
            user.activated = True
            flash('Account created! You can now log in.', 'success')

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

        return redirect(url_for('account.login'))

    return render_template('account/register.html', title=title, form=form)
コード例 #8
0
def register():
    """Register a new user, and send them a confirmation email."""

    # must pass the survey in order to be able to register
    can_register = request.cookies.get('can_register')
    if not can_register:
        return redirect(403)

    # passed survey
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject='Confirm Your Account',
            template='account/email/confirm',
            user=user,
            confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
コード例 #9
0
def register():
    """Register a new user."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
コード例 #10
0
ファイル: views.py プロジェクト: maikeulb/elasticblog
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('account.login'))
    return render_template('account/register.html',
                           title='Register',
                           form=form)
コード例 #11
0
ファイル: views.py プロジェクト: alayasix/LuoYunCloud
    def post(self):

        form = RegistrationForm(self.request.arguments)

        if form.validate():

            user = self.db2.query(User).filter_by( username=form.username.data ).all()

            if user:
                form.username.errors.append( _('This username is occupied') )
            else:
                salt = md5(str(random.random())).hexdigest()[:12]
                hsh = encrypt_password(salt, form.password.data)
                enc_password = "******" % (salt, hsh)

                newuser = User( username = form.username.data,
                                password = enc_password )
                self.db2.add(newuser)
                self.db2.commit()
                # Create profile
                profile = UserProfile(newuser, email = form.email.data)
                # Add to default group
                from settings import cf
                if cf.has_option('registration', 'user_default_group_id'):
                    try:
                        DGID = int(cf.get('registration', 'user_default_group_id'))
                        G = self.db2.query(Group).get(DGID)
                        newuser.groups = [G]
                        self.db2.commit()
                    except:
                        pass

                self.db2.add(profile)
                self.db2.commit()

                # send_message
                self.send_message( newuser )

                # send_mail()

                self.save_session(newuser.id)

                return self.redirect( self.reverse_url('account:index') )

        # Have a error
        self.render( 'account/register.html', form = form )
コード例 #12
0
    def post(self):

        form = RegistrationForm(self)

        if form.validate():

            user = self.db2.query(User).filter_by( username=form.username.data ).all()

            if user:
                form.username.errors.append( self.trans(_('This username is occupied')) )
            else:
                enc_password = enc_login_passwd(form.password.data)
                newuser = User( username = form.username.data,
                                password = enc_password )
                self.db2.add(newuser)
                self.db2.commit()
                # Create profile
                profile = UserProfile(newuser, email = form.email.data)
                root_passwd = enc_shadow_passwd(form.password.data)
                profile.set_secret('root_shadow_passwd', root_passwd)
                # Add to default group
                from settings import cf
                if cf.has_option('registration', 'user_default_group_id'):
                    try:
                        DGID = int(cf.get('registration', 'user_default_group_id'))
                        G = self.db2.query(Group).get(DGID)
                        newuser.groups = [G]
                        self.db2.commit()
                    except:
                        pass

                self.db2.add(profile)
                self.db2.commit()

                # send_message
                self.send_message( newuser )

                # send_mail()

                self.save_session(newuser.id)

                return self.redirect( self.reverse_url('account:index') )

        # Have a error
        self.render( 'account/register.html', form = form )
コード例 #13
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            # first_name=form.first_name.data,
            # last_name=form.last_name.data,
            username=form.username.data,
            full_name=form.full_name.data,
            email=form.email.data,
            password=form.password.data)
        # try:
        #     hyp_client.create_account(user.email, email=user.email,
        #                               display_name=user.email)
        # except HTTPError as ex:
        #     # FIXME: Make the service respond with an appropriate status code and
        #     # machine-readable error if the user account already exists
        #     email_err = 'user with email address {} already exists'.format(user.email)
        #     username_err = 'user with username {} already exists'.format(user.email)
        #     content = ex.response.content
        #     if email_err not in content and username_err not in content:
        #         raise ex
        # username = "******".format(user.first_name.lower(), user.last_name.lower())
        current_app.hypothesis_client.create_account(
            user.username, email=user.email, display_name=user.full_name)
        db.session.add(user)
        db.session.commit()
        # token = user.generate_confirmation_token()
        # confirm_link = url_for('account.confirm', token=token, _external=True)
        # get_queue().enqueue(
        #     send_email,
        #     recipient=user.email,
        #     subject='Confirm Your Account',
        #     template='account/email/confirm',
        #     user=user,
        #     confirm_link=confirm_link)
        # flash('A confirmation link has been sent to {}.'.format(user.email),
        #       'warning')

        # Bypass email confirmation
        user.force_confirm_account()
        return redirect(url_for('main.index'))
        # return redirect(url_for('account.manage'))
    return render_template('account/register.html', form=form)
コード例 #14
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        user.save()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        send_email.queue(recipient=user.email,
                         subject='Confirm Your Account',
                         template='account/email/confirm',
                         user=user,
                         confirm_link=confirm_link)
        flash(f'A confirmation link has been sent to {user.email}.', 'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
コード例 #15
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('account.login'))
    categories = Category.query.order_by(Category.name.desc())
    cart_items = g.cart.cart_items
    cart_quantity = sum([item.amount for item in cart_items])

    return render_template('account/register.html',
                           categories=categories,
                           cart_quantity=cart_quantity,
                           title='Register',
                           form=form)
コード例 #16
0
    def get(self):

        if self.enable_apply:
            if not self.key:
                return self.write( self.trans(_('No key found !')) )
            if not self.applyuser:
                return self.write( self.trans(_('No apply record found !')) )

        form = RegistrationForm(self)
        if self.applyuser:
            form.email.data = self.applyuser.email

        self.render( 'account/register.html', form = form )
コード例 #17
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        send_email_async(app=current_app._get_current_object(),
                         recipient=user.email,
                         subject='Confirm Your Account',
                         template='account/email/confirm',
                         user=user,
                         confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        return redirect(url_for('main.index'))
    return render_template_with_nav_info('account/register.html', form=form)
コード例 #18
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(user_name=form.user_name.data,
                    full_name=form.full_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(send_email,
                            recipient=user.email,
                            subject='Confirm Your Account',
                            template='account/email/confirm',
                            user=user,
                            confirm_link=confirm_link)
        flash(
            gettext('A confirmation link has been sent to {}.').format(
                user.email), 'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
コード例 #19
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db_session_add(user)
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(send_email,
                            recipient=user.email,
                            subject='Confirm Your Account',
                            template='account/email/confirm',
                            user=user,
                            confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        login_user(user)
        return jsonify(status='ok')
    return render_template('account/register.html',
                           form=form,
                           title="Register")
コード例 #20
0
ファイル: test_forms.py プロジェクト: maikeulb/filmogram
 def test_validate_email_already_registered(self, user):
     form = RegistrationForm(username='******',
                             email=user.email,
                             password='******',
                             confirm='example')
     assert form.validate() is False
コード例 #21
0
ファイル: test_forms.py プロジェクト: maikeulb/filmogram
 def test_validate_success(self, user):
     form = RegistrationForm(username='******',
                             email='*****@*****.**',
                             password='******',
                             confirm='example')
     assert form.validate() is True
コード例 #22
0
ファイル: test_forms.py プロジェクト: maikeulb/filmogram
 def test_validate_user_already_registered(self, user):
     form = RegistrationForm(username=user.username,
                             email='*****@*****.**',
                             password='******',
                             confirm='example')
     assert form.validate() is False
コード例 #23
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.is_submitted():
        print("submitted")

    if form.validate_on_submit():
        print("valid")

    print(form.errors)
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data,
            phone_number=form.phone_number.data,
            street=form.street.data,
            city=form.city.data,
            state=form.state.data,
            zip_code = form.zip_code.data,
            organization_corporation=form.organization_corporation.data,
            pa_residency =form.pa_residency.data,
            confirmed=False,
            role_id=1)
        db.session.add(user)
        if form.pa_residency.data == "Yes":
            volunteer = Volunteer(
                first_name=form.first_name.data,
                last_name=form.last_name.data,
                email=form.email.data,
                phone_number=form.phone_number.data,
                address_street=form.street.data,
                address_city=form.city.data,
                address_state=form.state.data,
                address_zip_code = form.zip_code.data,
                organization = form.organization_corporation.data,
                year_pa = form.pa_residency.data,
                status1=Status.NOT_SUBMITTED,
                status2=Status.NOT_SUBMITTED,
                status3=Status.NOT_NEEDED,
                status4=Status.NOT_SUBMITTED
            )
        if form.pa_residency.data == "No":
            volunteer = Volunteer(
                first_name=form.first_name.data,
                last_name=form.last_name.data,
                email=form.email.data,
                phone_number=form.phone_number.data,
                address_street=form.street.data,
                address_city=form.city.data,
                address_state=form.state.data,
                address_zip_code = form.zip_code.data,
                organization = form.organization_corporation.data,
                year_pa = form.pa_residency.data,
                status1=Status.NOT_SUBMITTED,
                status2=Status.NOT_SUBMITTED,
                status3=Status.NOT_SUBMITTED,
                status4=Status.NOT_SUBMITTED
            )
        db.session.add(volunteer)
        # db.session.query(user)
        db.session.commit()

        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject='Confirm Your Account',
            template='account/email/confirm',
            user=user,
            confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)