def post(self):
        form = SignupForm(request.form)

        if form.validate_on_submit():
            try:
                self._create_account(form.email.data, form.password.data)
                flash('Signed up! Now log in.')
                return redirect(url_for('auth.login'))
            except Exception as e:
                self.logger.exception(e)
                flash('Error!')
        return render_template("auth/signup.html", form=form)
def signup():
    form = SignupForm()

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

    if form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        password = form.repeat_password.data

        client = boto3.client('cognito-idp', region_name=Config.REGION)
        try:
            resp = client.sign_up(ClientId=Config.APP_CLIENT_ID,
                                  SecretHash=get_secret_hash(username),
                                  Username=username,
                                  Password=password,
                                  UserAttributes=[{
                                      'Name': "email",
                                      'Value': email
                                  }],
                                  ValidationData=[{
                                      'Name': "email",
                                      'Value': email
                                  }])
            print('Sign up Successfully')
            return redirect(url_for('authentication.confirm_signup'))

        except client.exceptions.UsernameExistsException as e:
            flash('This username already exists')
            return redirect(url_for('authentication.signup'))
        except client.exceptions.InvalidPasswordException as e:
            flash('Password not strong enough')
            return redirect(url_for('authentication.signup'))
        except client.exceptions.UserLambdaValidationException as e:
            flash('This email already exists')
            return redirect(url_for('authentication.signup'))
        except Exception as e:
            flash(e)
            return redirect(url_for('authentication.signup'))

    return render_template('authentication/signup.html',
                           form=form,
                           title='Sign Up')