예제 #1
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        email = form.email.data
        name = form.username.data
        password = form.password.data
        user = User(email=email, username=name)
        user.generate_password(password)
        try:
            db.session.add(user)
            db.session.commit()
            # 发邮件
            send_email(user.email,
                       user=user,
                       token=user.generate_confirmation_token())
            flash("注册成功")
            return redirect(url_for('auth.login'))
        except Exception as e:
            print(e)
            flash("注册失败")
            db.session.rollback()
    else:
        if request.method == "POST":
            flash("注册失败")
    return render_template('auth/signup.html', form=form)
예제 #2
0
def signup():
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.role.data == "student":
            user = Student(name=form.name.data,
                           email=form.email.data,
                           student_ref=form.uni_id.data)
        else:
            user = Teacher(name=form.name.data,
                           title=form.title.data,
                           teacher_ref=form.uni_id.data,
                           email=form.email.data)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            response = make_response(redirect(url_for('main.index')))
            response.set_cookie("name", form.name.data)
            return response
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to register {}. Please check your details are correct and resubmit'
                .format(form.email.data), 'error')
    return render_template('signup.html', form=form)
예제 #3
0
def signup():
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        user = Users(first_name=form.first_name.data,
                     last_name=form.last_name.data,
                     email=(form.email.data).lower())
        user.set_password(form.password.data)

        try:
            db.session.add(user)

            diet_preference = UserDietPreferences(diet_type_id=1)
            user.diet_preferences.append(diet_preference)  # Add diet_preference to current user

            db.session.commit()

            login_user(user)  # User is logged in upon signing up
            flash('You are now a registered user!', 'success')

            response = make_response(redirect(url_for('main.index')))  # Set cookie and return to main, if successful
            response.set_cookie("name", form.first_name.data)
            return response

        except IntegrityError:
            # Validations in forms are already done (e.g. email is already registered), this error probably can't be
            # triggered from frontend.
            db.session.rollback()
            flash(f'ERROR! Unable to register {form.email.data}. Please check your details are correct and resubmit.',
                  'danger')

    return render_template('auth/signup.html', form=form)
예제 #4
0
파일: controllers.py 프로젝트: LukV/idnet
def signup():

    form = SignupForm(request.form)

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

        if not username:
            username = email.split('@')[0]

        user = User(username, email)
        user.password = password
        user.password_hash
        user.role = Role.USER
        user.status = Status.ACTIVE
        db.session.add(user)
        db.session.commit()

        flash(gettext('You can now login.'))
        return redirect(url_for('auth.login'))

    return render_template('auth/signup.html',
                           title=gettext('Sign up'),
                           form=form)
예제 #5
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = SignupForm()
    if form.validate_on_submit():
        user = auth_services.load_user(id=form.email.data)
        if user:
            return redirect(
                url_for(
                    "auth.signup",
                    homepage_message="Email address already exists. Try with different email.",
                )
            )
        auth_services.create_user(data=form.data)
        return redirect(
            url_for(
                "auth.login",
                homepage_message="Please login with newly created account.",
            )
        )
    return render_template(
        "auth/signup.html",
        title="Sign Up",
        form=form,
        homepage_message=request.args.get("homepage_message"),
    )
예제 #6
0
def signup():

    form = SignupForm(request.form)

    if form.validate_on_submit():

        # get data from form
        password = form.password.data

        # hash user password
        pwhash = bcrypt.hashpw(password, bcrypt.gensalt(12))

        email = form.email.data

        # insert into DB
        user = User(form.first_name.data, form.last_name.data,
                    form.username.data, email, pwhash)

        # generate one time auth token
        auth_token = secrets.token_urlsafe(64)

        # insert user into DB
        db.session.add(user)
        db.session.commit()

        # create the pair of user id and auth token
        user_authentication = UserAuthentication(user.id, auth_token)

        # put the auth token in the DB
        db.session.add(user_authentication)
        db.session.commit()

        # get welcome/authentication email
        welcome_body = render_template("mail/welcome.html",
                                       auth_token=auth_token)

        # build message
        msg = Message("Welcom to the Auction Site",
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[email],
                      html=welcome_body)

        # send it
        mail.send(msg)

        # set flash message in the session
        flashmsg = ("Thank you for creating your account, "
                    "to begin using it, you will have to authenticate it "
                    "using the email we have sent")

        flash(flashmsg)

        # redirect to home page
        return render_template("index.html")

    return render_template("auth/signup.html", page_title="Sign Up", form=form)
예제 #7
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        if not User.query.filter_by(email=form.email.data).scalar():
            User(email=form.email.data, password=form.password.data).save()
            return redirect(url_for('auth.login'))
        else:
            form.errors['email'] = 'User already exists.'
            return render_template('auth/signup.html', form=form)
    return render_template('auth/signup.html', form=form)
예제 #8
0
def signup():
    form = SignupForm()
    if(form.validate_on_submit()):
        flash("Check your inbox")
        user = User(username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()

        # qui dobbiamo autenticare l'utente ...

    return render_template('signup.html', form=form)
예제 #9
0
def signup():
    form = SignupForm()
    if(form.validate_on_submit()):
        flash("Check your inbox")
        user = User(username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user, True)
        send_mail(user.email, "Confirm your email", "mails/email_confirm", user=user, token=user.generate_confirmation_token())

    return render_template('signup.html', form=form)
예제 #10
0
def signup():
    # If sign in form is submitted
    form = SignupForm(request.form)
    # Verify the sign in form
    if form.validate_on_submit():
        user = User(name=form.name.data,
                    email=form.email.data,
                    password=generate_password_hash(form.password.data))
        s = db.session()
        s.add(user)
        s.commit()
        return redirect(url_for('auth.signin'))
    return render_template("auth/signup.html", form=form)
예제 #11
0
def signup():
  # If sign in form is submitted
  form = SignupForm(request.form)
  # Verify the sign in form
  if form.validate_on_submit():
    user = User(name=form.name.data,
                email=form.email.data,
                password=generate_password_hash(form.password.data))
    s = db.session()
    s.add(user)
    s.commit()
    return redirect(url_for('auth.signin'))
  return render_template("auth/signup.html", form=form)
예제 #12
0
파일: routes.py 프로젝트: dnilasor/quickgig
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = SignupForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    first_name=form.first_name.data,
                    last_name=form.last_name.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congrats, you are signed up!')
        return redirect(url_for('auth.login'))
    return render_template('auth/signup.html', title='Signup', form=form)
예제 #13
0
def signup():
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(name=form.name.data, email=form.email.data)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            response = make_response(redirect(url_for('auth.login')))
            return response
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to register {}. Please check your details are correct and resubmit'
                .format(form.email.data), 'error')
    return render_template('signup.html', form=form)
예제 #14
0
def signup():
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(name=form.name.data, email=form.email.data)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            flash('{} Signed up successfully'.format(user.name))
            return redirect(url_for('main.index'))
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to Sign up {}. Please check your details are correct and resubmit'
                .format(form.email.data), 'error')
    return render_template('signup.html', form=form)
예제 #15
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        encrypted_pwd = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user_id = db.add_user({
            'username': form.username.data,
            'password': str(encrypted_pwd),
            'email': form.email.data
        })
        user = User(form.username.data, str(encrypted_pwd), user_id,
                    form.email.data)
        login_user(user, remember=True)
        session['userInstance'] = user.toDict()
        return redirect(url_for('user_profile_blueprint.get_additional_info'))
    return render_template('auth/signup.html', title="Sign in", form=form)
예제 #16
0
def process_signup():
    current_app.logger.info(f"New Sign Up attempt: {request.form['first_name']} - {request.form['last_name']} - {request.form['email']}")
    if current_app.config['DEBUG']:
        form = SignupForm()
        if form.validate_on_submit():
            user = User()
            form.populate_obj(user)
            user.set_password(form.password.data)
            user.active = True
            db.session.add(user)
            db.session.commit()
            flash('Welcome to Web Serialist.com!', 'success')
            return redirect(url_for('main.index'))
        return redirect(url_for('auth.login'))
    flash('We are not accepting new users at the moment. Thank you for your interest!', 'danger')
    return redirect(url_for('main.index'))
예제 #17
0
파일: routes.py 프로젝트: psv-git/labs
def sign_up():
    signup_form = SignupForm()
    if signup_form.validate_on_submit():
        user_name = signup_form.user_name_field.data
        user_email = signup_form.user_email_field.data
        user_password = signup_form.user_password_field.data
        if user_name and user_email and user_password:
            User.create(db_manager, user_name, user_email, user_password)
        return redirect("/signin_page")

    page_template = "auth/signup_page.html"
    page_data = {"page_name": "signup_page", "page_title": "Sign Up page"}
    return render_template(
        page_template,
        page_data=page_data,
        signup_form=signup_form,
    )
예제 #18
0
def signup():
    form = SignupForm()

    if request.method == 'POST':
        if not form.validate_on_submit():
            return render_template('/auth/signup.html', form=form), 406
        user = User(username=form.username.data,
                    name=form.name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()

        return "sign in the user and redirect to Home"  # TODO

    elif request.method == 'GET':
        return render_template('/auth/signup.html', form=form)
예제 #19
0
def signup():
    form = SignupForm()

    if request.method == 'POST':
        if not form.validate_on_submit():
            return render_template('/auth/signup.html', form=form), 406
        user = User(username=form.username.data,
                    name=form.name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()

        return "sign in the user and redirect to Home"  # TODO

    elif request.method == 'GET':
        return render_template('/auth/signup.html', form=form)
예제 #20
0
def signup():
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        user = User(username=form.username.data, email=form.email.data, name=form.name.data, age=form.age.data, school=form.school.data, studies=form.studies.data)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            db.session.commit()
            flash('You are now a registered user!')
            return redirect (url_for ('main.home'))
            # response = make_response (redirect (url_for ('main.index')))
            # response.set_cookie ("name", form.name.data)
            # return response
        except IntegrityError:
            db.session.rollback()
            flash('ERROR! Unable to register {}. Please check your details are correct and resubmit'.format(
                form.username.data), 'error')
    return render_template('signup.html', form=form)
예제 #21
0
def signup():
    if current_user.is_authenticated:
        return redirect(
            url_for('main.home'))  #TODO this should redirect to /home

    form = SignupForm()

    #returns true if request method is POST, GET if false
    if form.validate_on_submit():

        user = User(username=form.username.data)
        user.set_password(form.password.data)
        db.session.add(user)  # ignore these errors
        db.session.commit()
        flash('Successfully registered!')
        return redirect(url_for('auth.login'))

    return render_template('auth/signup.html', title='Sign up', form=form)
예제 #22
0
def register():
    if current_user.is_authenticated:
        flash('You are logged in')
        return redirect(url_for('main.index', account='musicians'))
    form = SignupForm(request.form)
    if request.method == 'POST' and form.validate():
        user = Profile(username=form.username.data,
                       email=form.email.data,
                       profile_name=None,
                       profile_description=None,
                       profile_image=None,
                       location=None,
                       rating=None,
                       block=0)
        user.set_password(form.password.data)
        try:
            db.session.add(user)
            response = make_response(
                redirect(url_for('main.index', account='musicians')))
            response.set_cookie("username", form.username.data)
            user = Profile.query.filter_by(email=form.email.data).first()
            login_user(user)
            if form.option.data == 'm':
                user = Musician(gender=None,
                                profile_id=current_user.profile_id,
                                birthdate=None,
                                availability=None,
                                sc_id=None)
                db.session.add(user)
            else:
                user = Venue(venue_capacity=None,
                             profile_id=current_user.profile_id,
                             venue_type=None)
                db.session.add(user)
            db.session.commit()
            return response
        except IntegrityError:
            db.session.rollback()
            flash(
                'Unable to register {}. Please try again.'.format(
                    form.username.data), 'error')
            return redirect(url_for('main.index'))
    return render_template('register.html', form=form)
예제 #23
0
def signup(tab='Sign Up'):
    if tab == 'Sign Up':
        flash('Sign ups are currently closed.', 'danger')
    signup_form = SignupForm()
    login_form = LoginForm()
    return render_template('auth/login.html',
            title = tab,
            signup_form = signup_form,
            login_form = login_form,
            tab = tab,
        )
def signup():
    """
    signup view
    """
    form = SignupForm(request.form)

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('auth/signup.html', form=form)
        else:   
            newuser = User(form.firstname.data,
                           form.lastname.data,
                           form.username.data,
                           form.email.data,
                           form.password.data)
            db.session.add(newuser)
            db.session.commit()

            session['email'] = newuser.email
            return redirect(url_for('main.profile'))

    elif request.method == 'GET':
        return render_template('auth/signup.html', form=form)